
% TRY TO FIGURE OUT THE OPTIMAL NUMBER OF SOM NODES TO USE


% Different options when computing SOMs
%fln='output_som4_wt_y_d_1_18-Apr-2018_16:17:50.mat';
%fln='output_som4_wt_y_d_2_18-Apr-2018_15:58:50.mat';
%fln='output_som6_wt_y_d_1_18-Apr-2018_15:29:20.mat';
%fln='output_som6_wt_y_d_2_18-Apr-2018_15:56:38.mat';
%fln='output_som8_wt_y_d_1_18-Apr-2018_17:03:04.mat';
%fln='output_som8_wt_y_d_2_18-Apr-2018_17:11:25.mat';
%fln='output_som9_wt_y_d_1_18-Apr-2018_16:54:38.mat';
%fln='output_som9_wt_y_d_2_18-Apr-2018_16:51:02.mat';
%fln='output_som12_wt_y_d_1_18-Apr-2018_17:22:36.mat';
%fln='output_som12_wt_y_d_2_18-Apr-2018_17:18:55.mat';
%fln='output_som12_wt_y_d_1_nodetrend_19-Apr-2018_14:25:02.mat';



fln={'output_som4_wt_y_d_1_18-Apr-2018_16:17:50.mat',...
'output_som6_wt_y_d_1_18-Apr-2018_15:29:20.mat',...
'output_som8_wt_y_d_1_18-Apr-2018_17:03:04.mat',...
'output_som9_wt_y_d_1_18-Apr-2018_16:54:38.mat',...
'output_som12_wt_y_d_1_18-Apr-2018_17:22:36.mat'};

for i=1:length(fln)

   load(fln{i},'ptrns','somCols','somRows')

   % Compute correlation matrix skipping NaNs at top and bottom
   cM=corrcoef(ptrns','rows','complete');
   % Take upper triangle (unique values)
   cU = triu(cM,1);
   % Remove zeros and negative values 
   cuv=cU(:);cuv(cuv<=0)=[];
   pc=length(cuv(cuv>0.8));

   disp(['max corr = ' num2str(max(cuv))])

   %figure
   %histogram(cuv,10)   
   %title(['SOMs =' num2str(somCols*somRows)])

   figure
   plot(sort(cuv),'o')
   hold on
   title(['SOMs =' num2str(somCols*somRows) ', n = ' num2str(pc) ' >0.8'])

end




