wolffd@0
|
1 function som_stats_plot(csS,plottype,varargin)
|
wolffd@0
|
2
|
wolffd@0
|
3 %SOM_STATS_PLOT Plots of data set statistics.
|
wolffd@0
|
4 %
|
wolffd@0
|
5 % som_stats_plot(csS, plottype, [argID, value, ...])
|
wolffd@0
|
6 %
|
wolffd@0
|
7 % som_stats_plot(csS,'stats')
|
wolffd@0
|
8 % som_stats_plot(csS,'stats','p','vert','color','r')
|
wolffd@0
|
9 %
|
wolffd@0
|
10 % Input and output arguments ([]'s are optional):
|
wolffd@0
|
11 % csS (cell array) of statistics structs
|
wolffd@0
|
12 % (struct) a statistics struct
|
wolffd@0
|
13 % plottype (string) some of the following
|
wolffd@0
|
14 % 'hist' histogram
|
wolffd@0
|
15 % 'box' min, max, mean, and std shown as a boxplot
|
wolffd@0
|
16 % 'stats' both histogram (with black) and the boxplot
|
wolffd@0
|
17 % [argID, (string) See below. The values which are unambiguous can
|
wolffd@0
|
18 % value] (varies) be given without the preceeding argID.
|
wolffd@0
|
19 %
|
wolffd@0
|
20 % Here are the valid argument IDs and corresponding values. The values which
|
wolffd@0
|
21 % are unambiguous (marked with '*') can be given without the preceeding argID.
|
wolffd@0
|
22 % 'counts' *(string) 'c' (for counts, the default) or 'p' (for percentages)
|
wolffd@0
|
23 % 'color' (vector) size 1 x 3, color to be used
|
wolffd@0
|
24 % (string) a color string
|
wolffd@0
|
25 % 'title' (string) 'on' (default) or 'off'
|
wolffd@0
|
26 % 'orientation' *(string) 'horiz' or 'vert' (default): orientation for the
|
wolffd@0
|
27 % bin values (horizontally or vertically)
|
wolffd@0
|
28 %
|
wolffd@0
|
29 % See also SOM_STATS, SOM_STATS_TABLE, SOM_TABLE_PRINT, SOM_STATS_REPORT.
|
wolffd@0
|
30
|
wolffd@0
|
31 % Contributed to SOM Toolbox 2.0, December 31st, 2001 by Juha Vesanto
|
wolffd@0
|
32 % Copyright (c) by Juha Vesanto
|
wolffd@0
|
33 % http://www.cis.hut.fi/projects/somtoolbox/
|
wolffd@0
|
34
|
wolffd@0
|
35 % Version 2.0beta juuso 311201
|
wolffd@0
|
36
|
wolffd@0
|
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
wolffd@0
|
38 %% arguments
|
wolffd@0
|
39
|
wolffd@0
|
40 % statistics
|
wolffd@0
|
41 if isstruct(csS), csS = {csS}; end
|
wolffd@0
|
42
|
wolffd@0
|
43 % default values
|
wolffd@0
|
44 useprob = 0;
|
wolffd@0
|
45 color = [0 0 1];
|
wolffd@0
|
46 showtitle = 1;
|
wolffd@0
|
47 horiz = 0;
|
wolffd@0
|
48
|
wolffd@0
|
49 % varargin
|
wolffd@0
|
50 i=1;
|
wolffd@0
|
51 while i<=length(varargin),
|
wolffd@0
|
52 argok = 1;
|
wolffd@0
|
53 if ischar(varargin{i}),
|
wolffd@0
|
54 switch varargin{i},
|
wolffd@0
|
55 % argument IDs
|
wolffd@0
|
56 case 'counts', i=i+1; useprob = strcmp(varargin{i}(1),'p');
|
wolffd@0
|
57 case 'color', i=i+1; color = varargin{i};
|
wolffd@0
|
58 case 'title', i=i+1; showtitle = strcmp(varargin{i},'on');
|
wolffd@0
|
59 case 'orientation', i=i+1; horiz = strcmp(varargin{i},'horiz');
|
wolffd@0
|
60 % unambiguous values
|
wolffd@0
|
61 case {'horiz','vert'}, horiz = strcmp(varargin{i},'horiz');
|
wolffd@0
|
62 case {'c','p'}, useprob = strcmp(varargin{i}(1),'p');
|
wolffd@0
|
63 otherwise argok=0;
|
wolffd@0
|
64 end
|
wolffd@0
|
65 elseif isstruct(varargin{i}) & isfield(varargin{i},'type'),
|
wolffd@0
|
66 argok = 0;
|
wolffd@0
|
67 else
|
wolffd@0
|
68 argok = 0;
|
wolffd@0
|
69 end
|
wolffd@0
|
70 if ~argok,
|
wolffd@0
|
71 disp(['(som_stats_plot) Ignoring invalid argument #' num2str(i+2)]);
|
wolffd@0
|
72 end
|
wolffd@0
|
73 i = i+1;
|
wolffd@0
|
74 end
|
wolffd@0
|
75
|
wolffd@0
|
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
|
wolffd@0
|
77 %% action
|
wolffd@0
|
78
|
wolffd@0
|
79 ss = ceil(sqrt(length(csS))); ss = [ss, ceil(length(csS)/ss)];
|
wolffd@0
|
80
|
wolffd@0
|
81 for j = 1:length(csS),
|
wolffd@0
|
82 sS = csS{j};
|
wolffd@0
|
83 subplot(ss(1),ss(2),j);
|
wolffd@0
|
84 switch plottype,
|
wolffd@0
|
85 case 'stats',
|
wolffd@0
|
86 cla, hold on
|
wolffd@0
|
87 Counts = sS.hist.counts;
|
wolffd@0
|
88 if useprob, for i=1:size(Counts,2), Counts(:,i) = Counts(:,i)/sum(Counts(:,i)); end, end
|
wolffd@0
|
89 hist_plot(sS.hist.bins,sS.hist.binlabels,Counts,color);
|
wolffd@0
|
90 box_plot(sS.min,sS.max,sS.mean,sS.std,[0 0 0]);
|
wolffd@0
|
91 case 'hist',
|
wolffd@0
|
92 cla, hold on
|
wolffd@0
|
93 Counts = sS.hist.counts;
|
wolffd@0
|
94 if useprob, for i=1:size(Counts,2), Counts(:,i) = Counts(:,i)/sum(Counts(:,i)); end, end
|
wolffd@0
|
95 hist_plot(sS.hist.bins,sS.hist.binlabels,Counts,color);
|
wolffd@0
|
96 case 'box',
|
wolffd@0
|
97 cla
|
wolffd@0
|
98 box_plot(sS.min,sS.max,sS.mean,sS.std,color);
|
wolffd@0
|
99 end
|
wolffd@0
|
100 if showtitle, title(sprintf('%s (valid: %d/%d)',sS.name,sS.nvalid,sS.ntotal)); end
|
wolffd@0
|
101 if ~horiz, view(90,-90); end
|
wolffd@0
|
102 a = axis; a(1) = sS.min; a(2) = sS.max; axis(a);
|
wolffd@0
|
103 end
|
wolffd@0
|
104
|
wolffd@0
|
105 return;
|
wolffd@0
|
106
|
wolffd@0
|
107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
|
wolffd@0
|
108 %% subfunctions
|
wolffd@0
|
109
|
wolffd@0
|
110 function hist_plot(bins,binlabels,Counts,color)
|
wolffd@0
|
111
|
wolffd@0
|
112 if nargin<4, color = jet(size(Counts,2)); end
|
wolffd@0
|
113 h = bar(bins,Counts);
|
wolffd@0
|
114 for j=1:length(h), set(h(j),'facecolor',color(j,:),'edgecolor','none'); end
|
wolffd@0
|
115 a = axis; a(3:4) = [0 max(Counts(:))]; axis(a);
|
wolffd@0
|
116 set(gca,'XTick',bins,'XTickLabel',binlabels);
|
wolffd@0
|
117 return;
|
wolffd@0
|
118
|
wolffd@0
|
119 function vstr = numtostring(v,d)
|
wolffd@0
|
120
|
wolffd@0
|
121 nearzero = (abs(v)/(max(v)-min(v)) < 10.^-d);
|
wolffd@0
|
122 i1 = find(v > 0 & nearzero);
|
wolffd@0
|
123 i2 = find(v < 0 & nearzero);
|
wolffd@0
|
124 vstr = strrep(cellstr(num2str(v,d)),' ','');
|
wolffd@0
|
125 vstr(i1) = {'0.0'};
|
wolffd@0
|
126 vstr(i2) = {'-0.0'};
|
wolffd@0
|
127 return;
|
wolffd@0
|
128
|
wolffd@0
|
129 function box_plot(mi,ma,me,st,Color)
|
wolffd@0
|
130
|
wolffd@0
|
131 if nargin < 5, Color = jet(length(mi)); end
|
wolffd@0
|
132 a = axis;
|
wolffd@0
|
133 y = linspace(a(3),a(4),length(mi)+2); y = y(2:end);
|
wolffd@0
|
134 d = (y(2)-y(1))/20;
|
wolffd@0
|
135 for i=1:length(mi),
|
wolffd@0
|
136 h1 = line([mi(i) ma(i)],[y(i) y(i)]);
|
wolffd@0
|
137 h2 = line([mi(i) mi(i) NaN ma(i) ma(i)],[y(i)-d y(i)+d NaN y(i)-d y(i)+d]);
|
wolffd@0
|
138 h3 = line([me(i)-st(i) me(i)+st(i)],[y(i) y(i)]);
|
wolffd@0
|
139 h4 = line([me(i) me(i)],[y(i)-2*d y(i)+2*d]);
|
wolffd@0
|
140 set([h1 h2 h3 h4],'color',Color(i,:));
|
wolffd@0
|
141 set([h1 h2],'linewidth',1);
|
wolffd@0
|
142 set([h3 h4],'linewidth',3);
|
wolffd@0
|
143 end
|
wolffd@0
|
144 return;
|