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