annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_projections.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 [cPCAarg, Pdata, Pproto] = som_projections(D,sM,bmus)
wolffd@0 2
wolffd@0 3 % SOM_PROJECTIONS Makes different kinds of projections for the data and the prototypes.
wolffd@0 4 %
wolffd@0 5 % [cPCAarg, Pdata, Pproto] = som_projections(D,sM,[bmus])
wolffd@0 6 %
wolffd@0 7 % sD (struct) data struct
wolffd@0 8 % (matrix) size dlen x dim
wolffd@0 9 % sM (struct) map struct
wolffd@0 10 % (matrix) size munits x dim: prototype vectors
wolffd@0 11 % [bmus] (vector) BMU for each data vector (calculated if not specified)
wolffd@0 12 %
wolffd@0 13 % cPCAarg (cell array) PCA arguments: {V, me, l} from pcaproj function
wolffd@0 14 % Pdata (matrix) size dlen x 7, consisting of 3 projection coordinates from PCA,
wolffd@0 15 % 1 residual from the rest of the PCA-projection coordinates,
wolffd@0 16 % and 3 color components
wolffd@0 17 % Pproto (matrix) size dlen x 7, consisting of 3 projection coordinates from PCA,
wolffd@0 18 % 1 residual from the rest of the PCA-projection coordinates,
wolffd@0 19 % 3 color components, and 3 projection coordinates from CCA
wolffd@0 20 %
wolffd@0 21 % See also PCAPROJ, CCA, SAMMON, SOM_PROJECTIONS_PLOT, SOM_COLORING, SOM_COLORCODE,
wolffd@0 22 % SOM_CLUSTERCOLOR, SOM_KMEANCOLOR.
wolffd@0 23
wolffd@0 24 if isstruct(D),
wolffd@0 25 cn = D.comp_names;
wolffd@0 26 D = D.data;
wolffd@0 27 end
wolffd@0 28 [dlen dim] = size(D);
wolffd@0 29 if nargin<3, bmus = som_bmus(sM,D); end
wolffd@0 30
wolffd@0 31 % projection of data
wolffd@0 32
wolffd@0 33 [P0,V,me,l] = pcaproj(D,dim);
wolffd@0 34 D1 = som_fillnans(D,sM);
wolffd@0 35 P1 = pcaproj(D1,V,me);
wolffd@0 36 Res4 = zeros(dlen,1);
wolffd@0 37 if dim<=3,
wolffd@0 38 Res4 = zeros(dlen,1);
wolffd@0 39 else
wolffd@0 40 Res4 = sqrt(sum(P1(:,4:end).*P1(:,4:end),2));
wolffd@0 41 end
wolffd@0 42 P1 = P1(:,1:min(3,dim));
wolffd@0 43 if dim<3, P1 = [P1, zeros(dlen,3-dim)]; end
wolffd@0 44
wolffd@0 45 % projection of codebook vectors
wolffd@0 46
wolffd@0 47 P1_m = pcaproj(sM,V,me);
wolffd@0 48 Res4_m = zeros(dlen,1);
wolffd@0 49 if dim<=3,
wolffd@0 50 Res4_m = zeros(dlen,1);
wolffd@0 51 else
wolffd@0 52 Res4_m = sum(P1_m(:,4:end).*P1_m(:,4:end),2);
wolffd@0 53 end
wolffd@0 54 P1_m = P1_m(:,1:min(3,dim));
wolffd@0 55 if dim<3, P1_m = [P1_m, zeros(size(P1_m,1),3-dim)]; end
wolffd@0 56
wolffd@0 57 P2_m = cca(sM,P1_m,20);
wolffd@0 58
wolffd@0 59 PCol_m = som_coloring(sM);
wolffd@0 60
wolffd@0 61 PCol = PCol_m(bmus,:);
wolffd@0 62
wolffd@0 63 % output
wolffd@0 64
wolffd@0 65 cPCAarg = {V,me,l};
wolffd@0 66 Pdata = [P1, Res4, PCol];
wolffd@0 67 Pproto = [P1_m, Res4_m, PCol_m, P2_m];
wolffd@0 68
wolffd@0 69 return;
wolffd@0 70