Daniel@0: function a = som_clget(sC, mode, ind) Daniel@0: Daniel@0: %SOM_CLGET Get properties of specified clusters. Daniel@0: % Daniel@0: % a = som_clget(sC, mode, ind) Daniel@0: % Daniel@0: % inds = som_clget(sC,'dinds',20); Daniel@0: % col = som_clget(sC,'depth',[1 2 3 20 54]); Daniel@0: % Daniel@0: % Input and output arguments: Daniel@0: % sC (struct) clustering struct Daniel@0: % mode (string) what kind of property is requested Daniel@0: % 'binds' (a union over) indeces of base clusters Daniel@0: % belonging to the specified cluster(s) Daniel@0: % 'dinds' (a union over) indeces of the data vectors Daniel@0: % belonging to the specified cluster(s) Daniel@0: % 'dlen' number of data vectors belonging Daniel@0: % to each of the specified cluster(s) Daniel@0: % 'depth' depths of the specified clusters Daniel@0: % (depth of the root cluster is 0, Daniel@0: % depth of its children are 1, etc.) Daniel@0: % 'child' (a union over) children clusters Daniel@0: % of specified cluster(s), including Daniel@0: % the clusters themselves Daniel@0: % 'base' base partitioning based on given Daniel@0: % clusters Daniel@0: % ind (vector) indeces of the clusters Daniel@0: % Daniel@0: % a (vector) the answer Daniel@0: % Daniel@0: % See also SOM_CLSTRUCT, SOM_CLPLOT. Daniel@0: Daniel@0: % Copyright (c) 2000 by the SOM toolbox programming team. Daniel@0: % Contributed to SOM Toolbox on XXX by Juha Vesanto Daniel@0: % http://www.cis.hut.fi/projects/somtoolbox/ Daniel@0: Daniel@0: % Version 2.0beta juuso 180800 Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: clen = size(sC.tree,1)+1; Daniel@0: Daniel@0: switch mode, Daniel@0: case 'binds', Daniel@0: a = []; Daniel@0: for i=1:length(ind), a = [a, getbaseinds(sC.tree,ind(i))]; end Daniel@0: a = unique(a); Daniel@0: case 'dinds', Daniel@0: b = []; Daniel@0: for i=1:length(ind), b = [b, getbaseinds(sC.tree,ind(i))]; end Daniel@0: b = unique(b); Daniel@0: a = zeros(length(sC.base),1); Daniel@0: for i=1:length(b), a(find(sC.base==b(i)))=1; end Daniel@0: a = find(a); Daniel@0: case 'dlen', Daniel@0: a = zeros(length(ind),1); Daniel@0: for i=1:length(ind), Daniel@0: b = getbaseinds(sC.tree,ind(i)); Daniel@0: for j=1:length(b), a(i) = a(i) + sum(sC.base==b(j)); end Daniel@0: end Daniel@0: case 'depth', Daniel@0: a = getdepth(sC.tree); Daniel@0: a = a(ind); Daniel@0: case 'child', Daniel@0: a = getchildren(sC.tree,ind); Daniel@0: case 'base', Daniel@0: a = sC.base*0; Daniel@0: ind = -sort(-ind); Daniel@0: for i=1:length(ind), a(som_clget(sC,'dinds',ind(i))) = ind(i); end Daniel@0: end Daniel@0: Daniel@0: return; Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: Daniel@0: function ch = getchildren(Z,ind) Daniel@0: Daniel@0: clen = size(Z,1)+1; Daniel@0: ch = ind; cho = ind; Daniel@0: while any(cho), Daniel@0: i = cho(1); cho = cho(2:end); Daniel@0: j = Z(i-clen,1); k = Z(i-clen,2); Daniel@0: if j>clen, cho(end+1) = j; end Daniel@0: if k>clen, cho(end+1) = k; end Daniel@0: ch(end+1) = j; ch(end+1) = k; Daniel@0: end Daniel@0: return; Daniel@0: Daniel@0: function binds = getbaseinds(Z,ind) Daniel@0: Daniel@0: clen = size(Z,1)+1; Daniel@0: binds = ind; Daniel@0: while binds(1)>clen, Daniel@0: i = binds(1); Daniel@0: binds = binds(2:end); Daniel@0: j = Z(i-clen,1); k = Z(i-clen,2); Daniel@0: if j>clen, binds = [j binds]; else binds(end+1) = j; end Daniel@0: if k>clen, binds = [k binds]; else binds(end+1) = k; end Daniel@0: end Daniel@0: return; Daniel@0: Daniel@0: function depth = getdepth(Z) Daniel@0: Daniel@0: clen = size(Z,1)+1; Daniel@0: depth = zeros(2*clen-1,1); Daniel@0: ch = 2*clen-1; % active nodes Daniel@0: while any(ch), Daniel@0: c = ch(1); ch = ch(2:end); Daniel@0: if c>clen & isfinite(Z(c-clen,3)), Daniel@0: chc = Z(c-clen,1:2); % children of c Daniel@0: depth(chc) = depth(c) + 1; % or +(ind==chc(1)) Daniel@0: ch = [ch, chc]; Daniel@0: end Daniel@0: end Daniel@0: return;