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