wolffd@0: function [V,I]=som_divide(sMap, D, inds, mode) wolffd@0: wolffd@0: %SOM_DIVIDE Divides a dataset according to a given map. wolffd@0: % wolffd@0: % [V,I]=som_divide(sMap, sData, [inds], [mode]) wolffd@0: % wolffd@0: % ARGUMENTS ([]'s are optional) wolffd@0: % wolffd@0: % sMap (struct or matrix) map struct or codebook (size munits x dim) wolffd@0: % sData (struct or matrix) data struct or matrix (size N x dim ) wolffd@0: % [inds] From which map units should the local data sets wolffd@0: % be constructed. Interpretation depends on mode wolffd@0: % argument. By default [1:munits]. wolffd@0: % 'class': (vector) munits x 1 matrix of class numbers wolffd@0: % 'index': (vector) K x 1 vector of map node indexes wolffd@0: % 'index': (matrix) K x k matrix of map node subscripts wolffd@0: % [mode] (string) 'index' or 'class', if inds is a vector of length wolffd@0: % munits, default is 'class', otherwise 'index'. wolffd@0: % RETURNS wolffd@0: % wolffd@0: % If mode == 'index' wolffd@0: % V (matrix) data vectors hitting the specified nodes (size K x dim) wolffd@0: % I (vector) corresponding data row indexes (size K x 1) wolffd@0: % wolffd@0: % If mode == 'class' (this can be used after using som_select) wolffd@0: % V (cell array) V{K} includes vectors whose BMU has class number wolffd@0: % K in the input matrix 'coord'. Note that wolffd@0: % values of K below 1 are ignored. wolffd@0: % I (cell array) corresponding data indexes in the cell array wolffd@0: % wolffd@0: % NOTE: if the same node is specified multiple times, only one wolffd@0: % set of hits is returned. wolffd@0: % wolffd@0: % See also SOM_BMU, SOM_HITS, SOM_SELECT. wolffd@0: wolffd@0: % Version 1.0beta 260997 Johan wolffd@0: % Version 2.0beta 230300 juuso wolffd@0: wolffd@0: % Contributed to SOM Toolbox vs2, Mar 23rd, 2000 by Juha Vesanto wolffd@0: % http://www.cis.hut.fi/projects/somtoolbox/ wolffd@0: wolffd@0: %%%% Init & Check %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% wolffd@0: wolffd@0: error(nargchk(0, 4, nargin)) % check if no. of input args is correct wolffd@0: wolffd@0: % map wolffd@0: if isstruct(sMap), wolffd@0: msize = sMap.topol.msize; wolffd@0: dim = size(sMap.codebook,2); wolffd@0: else wolffd@0: msize = [size(sMap,1) 1]; wolffd@0: dim = size(sMap,2); wolffd@0: end wolffd@0: munits = prod(msize); wolffd@0: wolffd@0: % data wolffd@0: if isstruct(D), D=D.data; end wolffd@0: wolffd@0: % inds wolffd@0: if nargin<3, inds = 1:munits; end wolffd@0: isvec = prod(size(inds))==length(inds); wolffd@0: wolffd@0: % mode wolffd@0: if nargin<4, wolffd@0: if isvec & length(inds)==munits, wolffd@0: mode = 'class'; wolffd@0: else wolffd@0: mode = 'index'; wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: %%% Action & Build output according to the mode string output wolffd@0: wolffd@0: if ~isvec, inds = som_sub2ind(msize,inds); end wolffd@0: wolffd@0: bmus=som_bmus(sMap,D); wolffd@0: wolffd@0: switch mode wolffd@0: case 'index' wolffd@0: I=find(ismember(bmus,inds)); wolffd@0: V=D(I,:); wolffd@0: case 'class' wolffd@0: K=max(inds); % classes wolffd@0: V = cell(K,1); wolffd@0: I = cell(K,1); wolffd@0: for i=1:K, wolffd@0: N_ind=find(inds == i); % indexes of the units of class i wolffd@0: I{i}=find(ismember(bmus,N_ind)); % data indexes wolffd@0: V{i}=D(I{i},:); wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: wolffd@0: wolffd@0: wolffd@0: