annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_plotmatrix.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function som_plotmatrix(sM,D,Col,comps)
wolffd@0 2
wolffd@0 3 %SOM_PLOTMATRIX Visualize pairwise scatter plots and histograms.
wolffd@0 4 %
wolffd@0 5 % som_plotmatrix(sM,[sD],[Col],[comps])
wolffd@0 6 %
wolffd@0 7 % Input and output arguments ([]'s are optional):
wolffd@0 8 % sM (struct) map struct
wolffd@0 9 % [sD] (struct) data struct, corresponding to the map
wolffd@0 10 % (matrix) data matrix (size dlen x dim)
wolffd@0 11 % [Col] (matrix) size munits x 3, color for each map unit
wolffd@0 12 % [comps] (vector) which components to plot (1:dim by default)
wolffd@0 13 %
wolffd@0 14 % See also: SOM_SHOW, SOM_ORDER_CPLANES.
wolffd@0 15
wolffd@0 16 % Copyright (c) 2000 by the SOM toolbox programming team.
wolffd@0 17 % Contributed to SOM Toolbox on June 16th, 2000 by Juha Vesanto
wolffd@0 18 % http://www.cis.hut.fi/projects/somtoolbox/
wolffd@0 19
wolffd@0 20 % Version 2.0beta juuso 140600
wolffd@0 21
wolffd@0 22 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55
wolffd@0 23
wolffd@0 24 % sM
wolffd@0 25 [munits dim] = size(sM.codebook);
wolffd@0 26 M = sM.codebook;
wolffd@0 27
wolffd@0 28 % sD
wolffd@0 29 if nargin>1 & ~isempty(D),
wolffd@0 30 if isstruct(D), D = D.data; end
wolffd@0 31 bmus = som_bmus(sM,D);
wolffd@0 32 else D = []; bmus = [];
wolffd@0 33 end
wolffd@0 34
wolffd@0 35 % Col
wolffd@0 36 if nargin<3 | isempty(Col), Col = som_colorcode(sM); end
wolffd@0 37 if ischar(Col), Col = som_colorcode(sM,Col); end
wolffd@0 38
wolffd@0 39 % comps
wolffd@0 40 if nargin<4 | isempty(comps), comps = 1:dim; end
wolffd@0 41 n = length(comps)+1;
wolffd@0 42
wolffd@0 43 % histogram bins
wolffd@0 44 if ~isempty(D), C=D; else C=M; end
wolffd@0 45 cHbins = cell(dim,1);
wolffd@0 46 cAxis = cell(dim,1);
wolffd@0 47 for i=1:dim,
wolffd@0 48 if ~isempty(D), mima = [min(D(:,i)),max(D(:,i))];
wolffd@0 49 else mima = [min(M(:,i)),max(M(:,i))];
wolffd@0 50 end
wolffd@0 51 cAxis{i} = mima;
wolffd@0 52 [dummy,cHbins{i}] = hist(mima,20);
wolffd@0 53 end
wolffd@0 54
wolffd@0 55 nt = 4; % number of ticks in scatter plots
wolffd@0 56
wolffd@0 57 % visualization
wolffd@0 58 clf
wolffd@0 59 for i=1:n,
wolffd@0 60 for j=1:n,
wolffd@0 61 subplot(n,n,(i-1)*n+j);
wolffd@0 62 if j==1 & i==1,
wolffd@0 63 h=som_cplane(sM,Col); set(h,'edgecolor','none')
wolffd@0 64 elseif i==1,
wolffd@0 65 ind = comps(j-1);
wolffd@0 66 b = cHbins{ind};
wolffd@0 67 hs = hist(M(:,ind),b);
wolffd@0 68 h = bar(b,hs,0.8); set(h,'EdgeColor','none','FaceColor','k');
wolffd@0 69 axis on, axis tight
wolffd@0 70 set(gca,'XTick',[],'Box','on');
wolffd@0 71 title(sM.comp_names{ind});
wolffd@0 72 elseif j==1,
wolffd@0 73 ind = comps(i-1);
wolffd@0 74 if ~isempty(D),
wolffd@0 75 b = cHbins{ind};
wolffd@0 76 hs = hist(D(:,ind),b);
wolffd@0 77 h = bar(b,hs,0.8); set(h,'EdgeColor','none','FaceColor','k');
wolffd@0 78 axis on, axis tight
wolffd@0 79 set(gca,'XTick',[],'Box','on');
wolffd@0 80 ylabel(sM.comp_names{ind})
wolffd@0 81 else
wolffd@0 82 text(0.5,0.5,sM.comp_names{ind});
wolffd@0 83 axis off
wolffd@0 84 end
wolffd@0 85 elseif i==j,
wolffd@0 86 ind = comps(i-1);
wolffd@0 87 h=som_cplane(sM,M(:,ind));
wolffd@0 88 set(h,'edgecolor','none')
wolffd@0 89 a = cAxis{ind};
wolffd@0 90 caxis(a); v = unique([a, min(M(:,ind)), max(M(:,ind))]);
wolffd@0 91 vn=som_denormalize(v,sM.comp_norm{ind})';
wolffd@0 92 h=colorbar('vert');
wolffd@0 93 set(h,'YTick',v,'YTickLabel',cellstr(num2str(vn,2)));
wolffd@0 94 elseif i<j | ~isempty(D),
wolffd@0 95 if i>j, i1 = i-1; i2 = j-1; else i1 = j-1; i2 = i-1; end
wolffd@0 96 ind1 = comps(i1); ind2 = comps(i2);
wolffd@0 97 if i<j,
wolffd@0 98 som_grid(sM,'coord',M(:,[ind1 ind2]),'markersize',2,'MarkerColor',Col);
wolffd@0 99 else
wolffd@0 100 som_grid('rect',[size(D,1) 1],'coord',D(:,[ind1 ind2]),...
wolffd@0 101 'Line','none','MarkerColor',Col(bmus,:),'Markersize',2);
wolffd@0 102 %cla; hold on
wolffd@0 103 %for k=1:max(bmus),
wolffd@0 104 % inds = find(bmus==k);
wolffd@0 105 % if any(inds),
wolffd@0 106 % som_grid('rect',[length(inds) 1],'coord',D(inds,[ind1 ind2]),...
wolffd@0 107 % 'Line','none','MarkerColor',Col(k,:),'Markersize',2);
wolffd@0 108 % end
wolffd@0 109 %end
wolffd@0 110 end
wolffd@0 111 a = [cAxis{ind1} cAxis{ind2}]; axis(a);
wolffd@0 112 x = linspace(a(1),a(2),nt); xn = som_denormalize(x,sM.comp_norm{ind1})';
wolffd@0 113 set(gca,'XTick',x,'XTickLabel',cellstr(num2str(xn,2)));
wolffd@0 114 y = linspace(a(3),a(4),nt); yn = som_denormalize(y,sM.comp_norm{ind2})';
wolffd@0 115 set(gca,'YTick',y,'YTickLabel',cellstr(num2str(yn,2)));
wolffd@0 116 xlabel(sM.comp_names{ind1}), ylabel(sM.comp_names{ind2})
wolffd@0 117 end
wolffd@0 118 end
wolffd@0 119 end
wolffd@0 120
wolffd@0 121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55
wolffd@0 122