Mercurial > hg > camir-aes2014
comparison toolboxes/MIRtoolbox1.3.2/somtoolbox/som_divide.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function [V,I]=som_divide(sMap, D, inds, mode) | |
2 | |
3 %SOM_DIVIDE Divides a dataset according to a given map. | |
4 % | |
5 % [V,I]=som_divide(sMap, sData, [inds], [mode]) | |
6 % | |
7 % ARGUMENTS ([]'s are optional) | |
8 % | |
9 % sMap (struct or matrix) map struct or codebook (size munits x dim) | |
10 % sData (struct or matrix) data struct or matrix (size N x dim ) | |
11 % [inds] From which map units should the local data sets | |
12 % be constructed. Interpretation depends on mode | |
13 % argument. By default [1:munits]. | |
14 % 'class': (vector) munits x 1 matrix of class numbers | |
15 % 'index': (vector) K x 1 vector of map node indexes | |
16 % 'index': (matrix) K x k matrix of map node subscripts | |
17 % [mode] (string) 'index' or 'class', if inds is a vector of length | |
18 % munits, default is 'class', otherwise 'index'. | |
19 % RETURNS | |
20 % | |
21 % If mode == 'index' | |
22 % V (matrix) data vectors hitting the specified nodes (size K x dim) | |
23 % I (vector) corresponding data row indexes (size K x 1) | |
24 % | |
25 % If mode == 'class' (this can be used after using som_select) | |
26 % V (cell array) V{K} includes vectors whose BMU has class number | |
27 % K in the input matrix 'coord'. Note that | |
28 % values of K below 1 are ignored. | |
29 % I (cell array) corresponding data indexes in the cell array | |
30 % | |
31 % NOTE: if the same node is specified multiple times, only one | |
32 % set of hits is returned. | |
33 % | |
34 % See also SOM_BMU, SOM_HITS, SOM_SELECT. | |
35 | |
36 % Version 1.0beta 260997 Johan | |
37 % Version 2.0beta 230300 juuso | |
38 | |
39 % Contributed to SOM Toolbox vs2, Mar 23rd, 2000 by Juha Vesanto | |
40 % http://www.cis.hut.fi/projects/somtoolbox/ | |
41 | |
42 %%%% Init & Check %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
43 | |
44 error(nargchk(0, 4, nargin)) % check if no. of input args is correct | |
45 | |
46 % map | |
47 if isstruct(sMap), | |
48 msize = sMap.topol.msize; | |
49 dim = size(sMap.codebook,2); | |
50 else | |
51 msize = [size(sMap,1) 1]; | |
52 dim = size(sMap,2); | |
53 end | |
54 munits = prod(msize); | |
55 | |
56 % data | |
57 if isstruct(D), D=D.data; end | |
58 | |
59 % inds | |
60 if nargin<3, inds = 1:munits; end | |
61 isvec = prod(size(inds))==length(inds); | |
62 | |
63 % mode | |
64 if nargin<4, | |
65 if isvec & length(inds)==munits, | |
66 mode = 'class'; | |
67 else | |
68 mode = 'index'; | |
69 end | |
70 end | |
71 | |
72 %%% Action & Build output according to the mode string output | |
73 | |
74 if ~isvec, inds = som_sub2ind(msize,inds); end | |
75 | |
76 bmus=som_bmus(sMap,D); | |
77 | |
78 switch mode | |
79 case 'index' | |
80 I=find(ismember(bmus,inds)); | |
81 V=D(I,:); | |
82 case 'class' | |
83 K=max(inds); % classes | |
84 V = cell(K,1); | |
85 I = cell(K,1); | |
86 for i=1:K, | |
87 N_ind=find(inds == i); % indexes of the units of class i | |
88 I{i}=find(ismember(bmus,N_ind)); % data indexes | |
89 V{i}=D(I{i},:); | |
90 end | |
91 end | |
92 | |
93 | |
94 | |
95 | |
96 |