comparison DL/two-step DL/dico_color_separate.m @ 200:69ce11724b1f luisf_dev

Added dictionary decorrelation for multiple dictionaries
author bmailhe
date Tue, 20 Mar 2012 12:25:50 +0000
parents
children
comparison
equal deleted inserted replaced
195:d50f5bdbe14c 200:69ce11724b1f
1 function [colors nbColors] = dico_color_separate(dico, mu)
2 % DICO_COLOR cluster several dictionaries in pairs of high correlation
3 % atoms. Called by dico_decorr.
4 %
5 % Parameters:
6 % -dico: the dictionaries
7 % -mu: the correlation threshold
8 %
9 % Result:
10 % -colors: a cell array of indices. Two atoms with the same color have
11 % a correlation greater than mu
12
13
14 numDico = length(dico);
15 colors = cell(numDico,1);
16 for i = 1:numDico
17 colors{i} = zeros(length(dico{i}),1);
18 end
19
20 G = cell(numDico);
21
22 % compute the correlations
23 for i = 1:numDico
24 for j = i+1:numDico
25 G{i,j} = abs(dico{i}'*dico{j});
26 end
27 end
28
29 % iterate on the correlations higher than mu
30 c = 1;
31 [maxCorr, i, j, m, n] = findMaxCorr(G);
32 while maxCorr > mu
33 % find the highest correlated pair
34
35 % color them
36 colors{i}(m) = c;
37 colors{j}(n) = c;
38 c = c+1;
39
40 % make sure these atoms never get selected again
41 % Set to zero relevant lines in the Gram Matrix
42 for j2 = i+1:numDico
43 G{i,j2}(m,:) = 0;
44 end
45
46 for i2 = 1:i-1
47 G{i2,i}(:,m) = 0;
48 end
49
50 for j2 = j+1:numDico
51 G{j,j2}(n,:) = 0;
52 end
53
54 for i2 = 1:j-1
55 G{i2,j}(:,n) = 0;
56 end
57
58 % find the next correlation
59 [maxCorr, i, j, m, n] = findMaxCorr(G);
60 end
61
62 % complete the coloring with singletons
63 % index = find(colors==0);
64 % colors(index) = c:c+length(index)-1;
65 nbColors = c-1;
66 end
67
68 function [val, i, j, m, n] = findMaxCorr(G)
69 %FINDMAXCORR find the maximal correlation in the cellular Gram matrix
70 %
71 % Input:
72 % -G: the Gram matrix
73 %
74 % Output:
75 % -val: value of the correlation
76 % -i,j,m,n: indices of the argmax. The maximal correlation is reached
77 % for the m^th atom of the i^th dictionary and the n^h atom of the
78 % j^h dictionary
79
80 val = -1;
81 for tmpI = 1:length(G)
82 for tmpJ = tmpI+1:length(G)
83 [tmpVal tmpM] = max(G{tmpI,tmpJ},[],1);
84 [tmpVal tmpN] = max(tmpVal);
85 if tmpVal > val
86 val = tmpVal;
87 i = tmpI;
88 j = tmpJ;
89 n = tmpN;
90 m = tmpM(n);
91 end
92 end
93 end
94 end
95