%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Author: Ivan Chang
%%   Date: March 2001
%%   v1.1
%%
%% Matlab function that displays all information about neural organization.
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function dpyAllNNInfo(neurons, filename, confusion_train, correct_train, declare_train, ...
   confusion_test, correct_test, declare_test);
fprintf('Creating log filename ...\n\n');
FID = fopen(filename,'w');
unary_kernels = { 'ident', 'log_2', 'exp_2' };
binary_kernels = { 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7' };

for i=1:length(neurons),
   fprintf(FID, 'Neuron ID %d\n\n', i);
   func = neurons{i}.func;
   if ~strcmp(func,'')
      for j=1:length(unary_kernels),
         func = ...
            strrep(func,strcat(strcat('unary_kernels{',num2str(j)),'}'),unary_kernels{j});
      end
      for j=1:length(binary_kernels),
         func = ...
            strrep(func,strcat(strcat('binary_kernels{',num2str(j)),'}'),binary_kernels{j});
      end
      fprintf(FID, '\tevolved function: %s\n\n', func);
   else
      fprintf(FID, '\tevolved function: none\n\n');
   end
   if length(neurons{i}.features)
      fprintf(FID, '\tfeatures @%d: %d\n', [ 1:length(neurons{i}.features); cat(2,neurons{i}.features{:}) ]);
   else
      fprintf(FID, '\tfeatures: none\n');
   end
   fprintf(FID,'\n');
   if ~strcmp(func,'')
      fprintf(FID, '\tthreshold: %f\n\n', neurons{i}.threshold);
   else
      fprintf(FID, '\tthreshold: na\n\n');
   end
   fprintf(FID, '\tdelta_in: %f\n', neurons{i}.delta_in);
   fprintf(FID, '\tdelta_o: %f\n', neurons{i}.delta_o);
   fprintf(FID, '\tdelta_ot: %f\n', neurons{i}.delta_ot);
   fprintf(FID, '\tdelta_oti: %f\n', neurons{i}.delta_oti);
   fprintf(FID, '\n');
   fprintf(FID, '\tsot: %d\n', neurons{i}.sot);
   fprintf(FID, '\tsoti: %d\n', neurons{i}.soti);
   fprintf(FID, '\n');
   fmtStr = '';
   if length(neurons{i}.nsc)
      for j=1:size(neurons{i}.nsc,2),
         fmtStr = cat(2, fmtStr, '%d ');
      end
      fprintf(FID, cat(2, cat(2, '\tnsc(%d,:): ',fmtStr),'\n'), [ 1:2 ; neurons{i}.nsc' ]);
   end
   fprintf(FID,'\n');
   fmtStr = '';
   if length(neurons{i}.presynaptic_neurons)
      for j=1:length(neurons{i}.presynaptic_neurons),
         fmtStr = cat(2, fmtStr, '%d ');
      end
      fprintf(FID, cat(2,cat(2,'\tpresynaptic neuron IDs: ',fmtStr),'\n'), cat(2,neurons{i}.presynaptic_neurons{:}));
   end
   fprintf(FID,'\n');
   fmtStr = '';
   if length(neurons{i}.scf_neurons)
      for j=1:length(neurons{i}.scf_neurons),
         fmtStr = cat(2, fmtStr, '%d ');
      end
      fprintf(FID, cat(2, cat(2, '\tSCFN IDs: ',fmtStr),'\n'), cat(2,neurons{i}.scf_neurons{:}));
   end
   fprintf(FID,'\n\n');
end

		disp('training confusion matrix');
      disp(confusion_train);
      for j=1:size(confusion_train,2)+1,
         fmtStr = cat(2, fmtStr, '%d ');
      end
      disp('test confusion matrix');
      disp(confusion_test);
      fprintf(FID, cat(2, cat(2,'\ttraining confusion matrix: ', fmtStr),'\n'), confusion_train);
      fprintf(FID, cat(2, cat(2,'\ttest confusion matrix: ', fmtStr),'\n'), confusion_test);
      fprintf(FID,'\n');
      
      disp('probability of correct classification training');
      disp(correct_train);
      fprintf(FID, '\tcorrect classification training: %f\n', correct_train);
      disp('probability of declaration training');
      disp(declare_train);
      fprintf(FID, '\tdeclaration rate training: %f\n', declare_train);
      fprintf(FID,'\n');
      
      disp('probability of correct classification testing');
      disp(correct_test);
      fprintf(FID, '\tcorrect classification testing: %f\n', correct_test);
      disp('probability of declaration testing');
      disp(declare_test);
      fprintf(FID, '\tdeclaration rate testing: %f\n', declare_test);
      fprintf(FID,'\n');
      
fclose(FID);