annotate DL/two-step DL/dico_color_separate.m @ 218:c38d965b5a1d luisf_dev

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