annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_stats_report.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function som_stats_report(csS,fname,fmt,texonly)
Daniel@0 2
Daniel@0 3 % SOM_STATS_REPORT Make report of the statistics.
Daniel@0 4 %
Daniel@0 5 % som_stats_report(csS, fname, fmt, [standalone])
Daniel@0 6 %
Daniel@0 7 % som_stats_report(csS, 'data_stats', 'ps')
Daniel@0 8 %
Daniel@0 9 % Input and output arguments ([]'s are optional):
Daniel@0 10 % csS (cell array) of statistics structs
Daniel@0 11 % (struct) a statistics struct
Daniel@0 12 % fname (string) output file name (without extension)
Daniel@0 13 % (cellstr) {direc, fname}
Daniel@0 14 % fmt (string) report format: 'ps', 'pdf', 'html' or 'txt'
Daniel@0 15 % [texonly] (any) for 'ps' and 'pdf' formats: if 4th argument
Daniel@0 16 % is given, only the tex file is written
Daniel@0 17 % (w/o document start/end), and it is not compiled
Daniel@0 18 %
Daniel@0 19 % See also SOM_STATS, SOM_STATS_PLOT, SOM_STATS_TABLE, SOM_TABLE_PRINT, REP_UTILS.
Daniel@0 20
Daniel@0 21 % Contributed to SOM Toolbox 2.0, December 31st, 2001 by Juha Vesanto
Daniel@0 22 % Copyright (c) by Juha Vesanto
Daniel@0 23 % http://www.cis.hut.fi/projects/somtoolbox/
Daniel@0 24
Daniel@0 25 % Version 2.0beta juuso 311201
Daniel@0 26
Daniel@0 27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniel@0 28 %% input arguments
Daniel@0 29
Daniel@0 30 if isstruct(csS), csS = {csS}; end
Daniel@0 31 dim = length(csS);
Daniel@0 32 if iscell(fname), direc = fname{1}; fname = fname{2}; else direc = '.'; end
Daniel@0 33 if nargin<4, texonly = 0; else texonly = 1; end
Daniel@0 34
Daniel@0 35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniel@0 36 %% action
Daniel@0 37
Daniel@0 38 % additional analysis
Daniel@0 39 continuity = zeros(dim,1);
Daniel@0 40 for i=1:dim, continuity(i) = csS{i}.nunique / csS{i}.nvalid; end
Daniel@0 41
Daniel@0 42 entropy_rel = zeros(dim,1);
Daniel@0 43 for i=1:dim,
Daniel@0 44 c = csS{i}.hist.counts;
Daniel@0 45 if length(c) < 2 | all(c==0), entropy(i) = 0;
Daniel@0 46 else
Daniel@0 47 maxent = log(length(c));
Daniel@0 48 c = c(c>0)/sum(c);
Daniel@0 49 entropy_rel(i) = -sum(c.*log(c)) / maxent;
Daniel@0 50 end
Daniel@0 51 end
Daniel@0 52
Daniel@0 53 % meta-statistics
Daniel@0 54 values = {'Number of variables',dim; ...
Daniel@0 55 'Number of samples',csS{1}.ntotal; ...
Daniel@0 56 'Valid values',c_and_p_str(count_total(csS,'nvalid'),dim*csS{1}.ntotal); ...
Daniel@0 57 'Mean(#unique / #valid)',mean(continuity); ...
Daniel@0 58 'Mean relative entropy',mean(entropy_rel)};
Daniel@0 59 %'Dataset name',sD.name; 'Report generated',datestr(now);
Daniel@0 60 sTdset = som_table_struct(values);
Daniel@0 61
Daniel@0 62 % statistics tables
Daniel@0 63 [sTstats,csThist] = som_stats_table(csS);
Daniel@0 64 sTstats = som_table_modify(sTstats,'addcol',entropy_rel,{'entropy'});
Daniel@0 65
Daniel@0 66 % write report
Daniel@0 67 if isempty(fname), fid = 1;
Daniel@0 68 else
Daniel@0 69 switch fmt,
Daniel@0 70 case {'ps','pdf'}, ending = '.tex';
Daniel@0 71 case 'html', ending = '.html';
Daniel@0 72 case 'txt', ending = '.txt';
Daniel@0 73 end
Daniel@0 74 fid = fopen([direc '/' fname ending],'w');
Daniel@0 75 end
Daniel@0 76 if ~texonly, rep_utils('header',fmt,fid); end
Daniel@0 77
Daniel@0 78 rep_utils({'inserttable',sTdset,1,0},fmt,fid);
Daniel@0 79 rep_utils({'insertbreak'},fmt,fid);
Daniel@0 80 rep_utils({'inserttable',sTstats,1,0},fmt,fid);
Daniel@0 81 rep_utils({'insertbreak'},fmt,fid);
Daniel@0 82 som_stats_plot(csS,'stats');
Daniel@0 83 rep_utils({'printfigure',[direc '/histograms']},fmt);
Daniel@0 84 rep_utils({'insertfigure','histograms'},fmt,fid);
Daniel@0 85 for i=1:dim,
Daniel@0 86 rep_utils({'insertbreak'},fmt,fid);
Daniel@0 87 rep_utils({'inserttable',csThist{i},1,0},fmt,fid);
Daniel@0 88 end
Daniel@0 89
Daniel@0 90 if ~texonly, rep_utils('footer',fmt,fid); end
Daniel@0 91 if fid~=1, fclose(fid); end
Daniel@0 92
Daniel@0 93 if ~texonly & any(strcmp(fmt,{'ps','pdf'})), rep_utils('compile',fmt); end
Daniel@0 94 return;
Daniel@0 95
Daniel@0 96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniel@0 97 %% subfunctions
Daniel@0 98
Daniel@0 99 function a = count_total(csS,field)
Daniel@0 100 % count total of the field values
Daniel@0 101 a = 0; for i=1:length(csS), a = a + getfield(csS{i},field); end
Daniel@0 102 return;
Daniel@0 103
Daniel@0 104 function str = c_and_p_str(n,m)
Daniel@0 105 % return a string of form # (%), e.g. '23 (12%)'
Daniel@0 106 if n==m, p = '100';
Daniel@0 107 elseif n==0, p = '0';
Daniel@0 108 else p = sprintf('%.2g',100*n/m);
Daniel@0 109 end
Daniel@0 110 str = sprintf('%d (%s%%)',round(n),p);
Daniel@0 111 return;
Daniel@0 112
Daniel@0 113