comparison toolboxes/MIRtoolbox1.3.2/somtoolbox/som_stats_report.m @ 0:e9a9cd732c1e tip

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