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