annotate DL/two-step DL/dico_color.m @ 160:e3035d45d014 danieleb

Added support classes
author Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk>
date Wed, 31 Aug 2011 10:53:10 +0100
parents 485747bf39e0
children
rev   line source
ivan@152 1 function colors = dico_color(dico, mu)
ivan@152 2 % DICO_COLOR cluster a dictionary in pairs of high correlation atoms.
ivan@152 3 % Called by dico_decorr.
ivan@152 4 %
ivan@152 5 % Parameters:
ivan@152 6 % -dico: the dictionary
ivan@152 7 % -mu: the correlation threshold
ivan@152 8 %
ivan@152 9 % Result:
ivan@152 10 % -colors: a vector of indices. Two atoms with the same color have a
ivan@152 11 % correlation greater than mu
ivan@152 12
ivan@152 13 numAtoms = length(dico);
ivan@152 14 colors = zeros(numAtoms, 1);
ivan@152 15
ivan@152 16 % compute the correlations
ivan@152 17 G = abs(dico'*dico);
ivan@152 18 G = G-eye(size(G));
ivan@152 19
ivan@152 20 % iterate on the correlations higher than mu
ivan@152 21 c = 1;
ivan@152 22 maxCorr = max(max(G));
ivan@152 23 while maxCorr > mu
ivan@152 24 % find the highest correlated pair
ivan@152 25 x = find(max(G)==maxCorr, 1);
ivan@152 26 y = find(G(x,:)==maxCorr, 1);
ivan@152 27
ivan@152 28 % color them
ivan@152 29 colors(x) = c;
ivan@152 30 colors(y) = c;
ivan@152 31 c = c+1;
ivan@152 32
ivan@152 33 % make sure these atoms never get selected again
ivan@152 34 G(x,:) = 0;
ivan@152 35 G(:,x) = 0;
ivan@152 36 G(y,:) = 0;
ivan@152 37 G(:,y) = 0;
ivan@152 38
ivan@152 39 % find the next correlation
ivan@152 40 maxCorr = max(max(G));
ivan@152 41 end
ivan@152 42
ivan@152 43 % complete the coloring with singletons
ivan@152 44 index = find(colors==0);
ivan@152 45 colors(index) = c:c+length(index)-1;
ivan@152 46 end