wolffd@0: function som_stats_report(csS,fname,fmt,texonly) wolffd@0: wolffd@0: % SOM_STATS_REPORT Make report of the statistics. wolffd@0: % wolffd@0: % som_stats_report(csS, fname, fmt, [standalone]) wolffd@0: % wolffd@0: % som_stats_report(csS, 'data_stats', 'ps') wolffd@0: % wolffd@0: % Input and output arguments ([]'s are optional): wolffd@0: % csS (cell array) of statistics structs wolffd@0: % (struct) a statistics struct wolffd@0: % fname (string) output file name (without extension) wolffd@0: % (cellstr) {direc, fname} wolffd@0: % fmt (string) report format: 'ps', 'pdf', 'html' or 'txt' wolffd@0: % [texonly] (any) for 'ps' and 'pdf' formats: if 4th argument wolffd@0: % is given, only the tex file is written wolffd@0: % (w/o document start/end), and it is not compiled wolffd@0: % wolffd@0: % See also SOM_STATS, SOM_STATS_PLOT, SOM_STATS_TABLE, SOM_TABLE_PRINT, REP_UTILS. wolffd@0: wolffd@0: % Contributed to SOM Toolbox 2.0, December 31st, 2001 by Juha Vesanto wolffd@0: % Copyright (c) by Juha Vesanto wolffd@0: % http://www.cis.hut.fi/projects/somtoolbox/ wolffd@0: wolffd@0: % Version 2.0beta juuso 311201 wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: %% input arguments wolffd@0: wolffd@0: if isstruct(csS), csS = {csS}; end wolffd@0: dim = length(csS); wolffd@0: if iscell(fname), direc = fname{1}; fname = fname{2}; else direc = '.'; end wolffd@0: if nargin<4, texonly = 0; else texonly = 1; end wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: %% action wolffd@0: wolffd@0: % additional analysis wolffd@0: continuity = zeros(dim,1); wolffd@0: for i=1:dim, continuity(i) = csS{i}.nunique / csS{i}.nvalid; end wolffd@0: wolffd@0: entropy_rel = zeros(dim,1); wolffd@0: for i=1:dim, wolffd@0: c = csS{i}.hist.counts; wolffd@0: if length(c) < 2 | all(c==0), entropy(i) = 0; wolffd@0: else wolffd@0: maxent = log(length(c)); wolffd@0: c = c(c>0)/sum(c); wolffd@0: entropy_rel(i) = -sum(c.*log(c)) / maxent; wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: % meta-statistics wolffd@0: values = {'Number of variables',dim; ... wolffd@0: 'Number of samples',csS{1}.ntotal; ... wolffd@0: 'Valid values',c_and_p_str(count_total(csS,'nvalid'),dim*csS{1}.ntotal); ... wolffd@0: 'Mean(#unique / #valid)',mean(continuity); ... wolffd@0: 'Mean relative entropy',mean(entropy_rel)}; wolffd@0: %'Dataset name',sD.name; 'Report generated',datestr(now); wolffd@0: sTdset = som_table_struct(values); wolffd@0: wolffd@0: % statistics tables wolffd@0: [sTstats,csThist] = som_stats_table(csS); wolffd@0: sTstats = som_table_modify(sTstats,'addcol',entropy_rel,{'entropy'}); wolffd@0: wolffd@0: % write report wolffd@0: if isempty(fname), fid = 1; wolffd@0: else wolffd@0: switch fmt, wolffd@0: case {'ps','pdf'}, ending = '.tex'; wolffd@0: case 'html', ending = '.html'; wolffd@0: case 'txt', ending = '.txt'; wolffd@0: end wolffd@0: fid = fopen([direc '/' fname ending],'w'); wolffd@0: end wolffd@0: if ~texonly, rep_utils('header',fmt,fid); end wolffd@0: wolffd@0: rep_utils({'inserttable',sTdset,1,0},fmt,fid); wolffd@0: rep_utils({'insertbreak'},fmt,fid); wolffd@0: rep_utils({'inserttable',sTstats,1,0},fmt,fid); wolffd@0: rep_utils({'insertbreak'},fmt,fid); wolffd@0: som_stats_plot(csS,'stats'); wolffd@0: rep_utils({'printfigure',[direc '/histograms']},fmt); wolffd@0: rep_utils({'insertfigure','histograms'},fmt,fid); wolffd@0: for i=1:dim, wolffd@0: rep_utils({'insertbreak'},fmt,fid); wolffd@0: rep_utils({'inserttable',csThist{i},1,0},fmt,fid); wolffd@0: end wolffd@0: wolffd@0: if ~texonly, rep_utils('footer',fmt,fid); end wolffd@0: if fid~=1, fclose(fid); end wolffd@0: wolffd@0: if ~texonly & any(strcmp(fmt,{'ps','pdf'})), rep_utils('compile',fmt); end wolffd@0: return; wolffd@0: wolffd@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: %% subfunctions wolffd@0: wolffd@0: function a = count_total(csS,field) wolffd@0: % count total of the field values wolffd@0: a = 0; for i=1:length(csS), a = a + getfield(csS{i},field); end wolffd@0: return; wolffd@0: wolffd@0: function str = c_and_p_str(n,m) wolffd@0: % return a string of form # (%), e.g. '23 (12%)' wolffd@0: if n==m, p = '100'; wolffd@0: elseif n==0, p = '0'; wolffd@0: else p = sprintf('%.2g',100*n/m); wolffd@0: end wolffd@0: str = sprintf('%d (%s%%)',round(n),p); wolffd@0: return; wolffd@0: wolffd@0: