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