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