function  sumstats = PLM_summary(stats)

%PLM_SUMMARY -- Aggregate across runs the PLM_STATS statistics.
%
% sumstats = PLM_summary(stats)
%
% STATS is produced by PLM_STATS. This function simply takes averages.
%
% Typical usage:
%  stats = PLM_stats(descr,o(:,1,:),o(:,2,:),o(:,3,:)) ;
%  sumstats = PLM_summary(stats) ; 
%  figure(1) ; plot_PLM_dynamics(sumstats) ;
%  figure(2) ; plot_PLM_fit({sumstats.zP_congr',sumstats.zP_incon'}) ;
%
% See also PLOT_PLM_DYNAMICS, PLM_STATS, MERGE_PLM_STATS, PLMODEL1.

% Original coding by Alexander Petrov, UC Irvine.
% $Revision: 1.0 $  $Date: 2003/03/05 11:10 $

fields = {...
 'zP_congr'  3 ; 'zP_incon'  3 ; 'dprime' 3 ; ...   % z-probabilities
 'accZP'     1 ; 'seqP'      1 ; ...
 'mnA_congr' 3 ; 'mnA_incon' 3 ; 'Aprime' 3 ; ...   % mean output_act
 'accA'      1 ; 'seqA'      1 ; ...
 'mnI_congr' 3 ; 'mnI_incon' 3 ; 'Iprime' 3 ; ...   % mean net_input
 'accI'      1 ; 'seqI'      1 ; ...
 'contextc'  1 ; 'contexti'  1 ; ...                % transitions
 'otherc'    1 ; 'otheri'    1
} ; % end FIELDS

sumstats.N_runs = length(stats.group) ;
for k = 1:size(fields,1)
   f = fields{k,1} ; dim = fields{k,2} ;
   if (isfield(stats,f))
      mn = mean(getfield(stats,f),dim) ;
      sumstats = setfield(sumstats,f,mn) ;
   end
end

%-- Return SUMSTATS
%%%%% End of PLM_SUMMARY.M
