Mercurial > hg > smallbox
comparison DL/two-step DL/dico_color.m @ 152:485747bf39e0 ivand_dev
Two step dictonary learning - Integration of the code for dictionary update and dictionary decorrelation from Boris Mailhe
author | Ivan Damnjanovic lnx <ivan.damnjanovic@eecs.qmul.ac.uk> |
---|---|
date | Thu, 28 Jul 2011 15:49:32 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
149:fec205ec6ef6 | 152:485747bf39e0 |
---|---|
1 function colors = dico_color(dico, mu) | |
2 % DICO_COLOR cluster a dictionary in pairs of high correlation atoms. | |
3 % Called by dico_decorr. | |
4 % | |
5 % Parameters: | |
6 % -dico: the dictionary | |
7 % -mu: the correlation threshold | |
8 % | |
9 % Result: | |
10 % -colors: a vector of indices. Two atoms with the same color have a | |
11 % correlation greater than mu | |
12 | |
13 numAtoms = length(dico); | |
14 colors = zeros(numAtoms, 1); | |
15 | |
16 % compute the correlations | |
17 G = abs(dico'*dico); | |
18 G = G-eye(size(G)); | |
19 | |
20 % iterate on the correlations higher than mu | |
21 c = 1; | |
22 maxCorr = max(max(G)); | |
23 while maxCorr > mu | |
24 % find the highest correlated pair | |
25 x = find(max(G)==maxCorr, 1); | |
26 y = find(G(x,:)==maxCorr, 1); | |
27 | |
28 % color them | |
29 colors(x) = c; | |
30 colors(y) = c; | |
31 c = c+1; | |
32 | |
33 % make sure these atoms never get selected again | |
34 G(x,:) = 0; | |
35 G(:,x) = 0; | |
36 G(y,:) = 0; | |
37 G(:,y) = 0; | |
38 | |
39 % find the next correlation | |
40 maxCorr = max(max(G)); | |
41 end | |
42 | |
43 % complete the coloring with singletons | |
44 index = find(colors==0); | |
45 colors(index) = c:c+length(index)-1; | |
46 end |