Commit 4b0906ed authored by Carlos Mejia's avatar Carlos Mejia
Browse files

Adding a PARFOR for Parallel Computong of Lambda loop in 2S-SOM training. The...

Adding a PARFOR for Parallel Computong of Lambda loop in 2S-SOM training. The "if (bool_2ssom)" was re-indented with Matlab Editor
parent f5d3f6ea
...@@ -75,6 +75,7 @@ function [StsMap sMap_denorm Resultout sMapPTout] = learn_2s_som(A,nb_neurone,va ...@@ -75,6 +75,7 @@ function [StsMap sMap_denorm Resultout sMapPTout] = learn_2s_som(A,nb_neurone,va
bool_DimData = false; DimData = [size(A,2)]; bool_DimData = false; DimData = [size(A,2)];
bool_lambda = false; lambda = 1; bool_lambda = false; lambda = 1;
bool_eta = false; eta = 1000; bool_eta = false; eta = 1000;
bool_parcomp = false; parcomp_workers = 8; % 8 workers for parallel computing by default, if activated (if bool_parcomp is true)
Result = struct([]); Result = struct([]);
...@@ -156,6 +157,9 @@ function [StsMap sMap_denorm Resultout sMapPTout] = learn_2s_som(A,nb_neurone,va ...@@ -156,6 +157,9 @@ function [StsMap sMap_denorm Resultout sMapPTout] = learn_2s_som(A,nb_neurone,va
else else
bool_eta = true; bool_eta = true;
end end
case 'parcomp'
bool_parcomp = true;
parcomp_workers = varargin{i+1}; i=i+1;
case 'ini-with-make' case 'ini-with-make'
bool_init_with_make = true; bool_init_with_make = true;
case 'no-ini-with-make' case 'no-ini-with-make'
...@@ -404,12 +408,10 @@ function [StsMap sMap_denorm Resultout sMapPTout] = learn_2s_som(A,nb_neurone,va ...@@ -404,12 +408,10 @@ function [StsMap sMap_denorm Resultout sMapPTout] = learn_2s_som(A,nb_neurone,va
%if (bool_lambda && bool_eta && bool_DimData) %if (bool_lambda && bool_eta && bool_DimData)
if (bool_lambda && bool_eta) if (bool_lambda && bool_eta)
best_i = 0; n_lambda = length(lambda);
best_j = 0; n_eta = length(eta);
bestperf = inf;
i_train = 1; i_train = 1;
n_train = length(lambda)*length(eta); n_train = n_lambda*n_eta;
if ~bool_rad_2s_som if ~bool_rad_2s_som
rad_2s_som = [rad(round(length(rad)/2)) ... rad_2s_som = [rad(round(length(rad)/2)) ...
...@@ -421,14 +423,20 @@ function [StsMap sMap_denorm Resultout sMapPTout] = learn_2s_som(A,nb_neurone,va ...@@ -421,14 +423,20 @@ function [StsMap sMap_denorm Resultout sMapPTout] = learn_2s_som(A,nb_neurone,va
fprintf(1,[ '\n-- batchtrainRTOM loop for %d lambda and %d eta values:\n', ... fprintf(1,[ '\n-- batchtrainRTOM loop for %d lambda and %d eta values:\n', ...
'-- ------------------------------------------------------------------\n' ], ... '-- ------------------------------------------------------------------\n' ], ...
length(lambda), length(eta)); n_lambda, n_eta);
if tracking > 1, if tracking > 1,
fprintf(1,' ... trainlen_2s_som ... %s\n', num2str(trlen_2s_som)) fprintf(1,' ... trainlen_2s_som ... %s\n', num2str(trlen_2s_som))
fprintf(1,' ... radius_2s_som ..... [%s]\n', join(string(rad_2s_som),', ')) fprintf(1,' ... radius_2s_som ..... [%s]\n', join(string(rad_2s_som),', '))
end end
for i=1:length(lambda) if bool_parcomp, ticBytes(gcp); end % POUR CALCUL PARALLELE
for j=1:length(eta) if bool_parcomp
fprintf(1,'-- batchtrainRTOM (%d/%d) with lambda=%s and eta=%s ... ',i_train, ... parcomp_M = parcomp_workers;
else
parcomp_M = 1;
end
parfor (i=1:n_lambda,parcomp_M)
for j=1:n_eta
fprintf(1,'-- batchtrainRTOM (%d/%d) with lambda=%s and eta=%s ... ',(i - 1) * n_eta + j, ...
n_train, num2str(lambda(i)),num2str(eta(j))); n_train, num2str(lambda(i)),num2str(eta(j)));
if tracking, fprintf(1,'\n'); end if tracking, fprintf(1,'\n'); end
...@@ -449,28 +457,37 @@ function [StsMap sMap_denorm Resultout sMapPTout] = learn_2s_som(A,nb_neurone,va ...@@ -449,28 +457,37 @@ function [StsMap sMap_denorm Resultout sMapPTout] = learn_2s_som(A,nb_neurone,va
current_perf = som_distortion(Result(i,j).sMap,sD_norm); current_perf = som_distortion(Result(i,j).sMap,sD_norm);
fprintf(1,' --> som_distortion=%s\n', num2str(current_perf)); fprintf(1,' --> som_distortion=%s\n', num2str(current_perf));
% end
%end
% best_i=0;
% best_j=0;
% bestperf=inf;
% for i=1:length(lambda)
% for j=1:length(eta)
%
Result(i,j).Perf = current_perf;
if Result(i,j).Perf < bestperf
best_i = i;
best_j = j;
end
i_train = i_train + 1; Result(i,j).Perf = current_perf;
end end
end end
if bool_parcomp, tocBytes(gcp), end % POUR CALCUL PARALLELE
sMap = Result(best_i,best_j).sMap;
% best_i = 0;
% best_j = 0;
% bestperf = inf;
% for i=1:n_lambda
% for j=1:n_eta
% % end
% %end
% % best_i=0;
% % best_j=0;
% % bestperf=inf;
% % for i=1:n_lambda
% % for j=1:n_eta
% %
% if Result(i,j).Perf < bestperf
% best_i = i;
% best_j = j;
% bestperf = Result(i,j).Perf;
% end
% end
% end
%
% sMap = Result(best_i,best_j).sMap;
else else
error('manque de parametre') error('manque de parametre: specifier les valeurs pour LAMBDA, pour ETA ou pour les deux!')
end end
elseif (bool_lambda || bool_eta) elseif (bool_lambda || bool_eta)
error([ '*** %s: PAS DE 2SSOM SPECIFIE MAIS FLAGS (LAMBDA ou ETA) ACTIVE ***\n', ... error([ '*** %s: PAS DE 2SSOM SPECIFIE MAIS FLAGS (LAMBDA ou ETA) ACTIVE ***\n', ...
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment