Mercurial > hg > smallbox
comparison DL/two-step DL/dico_decorr_symetric.m @ 224:fd0b5d36f6ad danieleb
Updated the contents of this branch with the contents of the default branch.
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Thu, 12 Apr 2012 13:52:28 +0100 |
parents | 290cca7d3469 69ce11724b1f |
children |
comparison
equal
deleted
inserted
replaced
196:82b0d3f982cb | 224:fd0b5d36f6ad |
---|---|
1 function dico = dico_decorr_symetric(dico, mu, amp) | 1 function dico = dico_decorr_symetric(dico, mu) |
2 %DICO_DECORR decorrelate a dictionary | 2 %DICO_DECORR decorrelate a dictionary |
3 % Parameters: | 3 % Parameters: |
4 % dico: the dictionary | 4 % dico: the dictionary, either a matrix or a cell array of matrices. |
5 % mu: the coherence threshold | 5 % mu: the coherence threshold |
6 % amp: the amplitude coefficients, only used to decide which atom to | |
7 % project | |
8 % | 6 % |
9 % Result: | 7 % Result: |
10 % dico: a dictionary close to the input one with coherence mu. | 8 % dico: if the input dico was a matrix, then a matrix close to the |
9 % input one with coherence mu. | |
10 % If the input was a cell array, a cell array of the same size | |
11 % containing matrices such that the coherence between different cells | |
12 % is lower than mu. | |
11 | 13 |
12 eps = 1e-6; % define tolerance for normalisation term alpha | 14 eps = 1e-3; % define tolerance for normalisation term alpha |
13 | 15 |
14 % convert mu to the to the mean direction | 16 % convert mu to the to the mean direction |
15 theta = acos(mu)/2; | 17 theta = acos(mu)/2; |
16 ctheta = cos(theta); | 18 ctheta = cos(theta); |
17 stheta = sin(theta); | 19 stheta = sin(theta); |
21 % rank = sum(amp.*amp, 2); | 23 % rank = sum(amp.*amp, 2); |
22 % else | 24 % else |
23 % rank = randperm(length(dico)); | 25 % rank = randperm(length(dico)); |
24 % end | 26 % end |
25 | 27 |
26 % several decorrelation iterations might be needed to reach global | 28 % if only one dictionary is provided, then decorrelate it |
27 % coherence mu. niter can be adjusted to needs. | 29 if ~iscell(dico) |
28 niter = 1; | 30 % several decorrelation iterations might be needed to reach global |
29 while max(max(abs(dico'*dico -eye(length(dico))))) > mu + 0.01 | 31 % coherence mu. niter can be adjusted to needs. |
30 % find pairs of high correlation atoms | 32 niter = 1; |
31 colors = dico_color(dico, mu); | 33 while max(max(abs(dico'*dico -eye(length(dico))))) > mu + eps |
34 % find pairs of high correlation atoms | |
35 colors = dico_color(dico, mu); | |
36 | |
37 % iterate on all pairs | |
38 nbColors = max(colors); | |
39 for c = 1:nbColors | |
40 index = find(colors==c); | |
41 if numel(index) == 2 | |
42 if dico(:,index(1))'*dico(:,index(2)) > 0 | |
43 %build the basis vectors | |
44 v1 = dico(:,index(1))+dico(:,index(2)); | |
45 v1 = v1/norm(v1); | |
46 v2 = dico(:,index(1))-dico(:,index(2)); | |
47 v2 = v2/norm(v2); | |
48 | |
49 dico(:,index(1)) = ctheta*v1+stheta*v2; | |
50 dico(:,index(2)) = ctheta*v1-stheta*v2; | |
51 else | |
52 v1 = dico(:,index(1))-dico(:,index(2)); | |
53 v1 = v1/norm(v1); | |
54 v2 = dico(:,index(1))+dico(:,index(2)); | |
55 v2 = v2/norm(v2); | |
56 | |
57 dico(:,index(1)) = ctheta*v1+stheta*v2; | |
58 dico(:,index(2)) = -ctheta*v1+stheta*v2; | |
59 end | |
60 end | |
61 end | |
62 niter = niter+1; | |
63 end | |
64 %if a cell array of dictionaries is provided, decorrelate among | |
65 %different dictionaries only | |
66 else | |
67 niter = 1; | |
68 numDicos = length(dico); | |
69 G = cell(numDicos); | |
70 maxCorr = 0; | |
71 for i = 1:numDicos | |
72 for j = i+1:numDicos | |
73 G{i,j} = dico{i}'*dico{j}; | |
74 maxCorr = max(maxCorr,max(max(abs(G{i,j})))); | |
75 end | |
76 end | |
32 | 77 |
33 % iterate on all pairs | 78 while maxCorr > mu + eps |
34 nbColors = max(colors); | 79 % find pairs of high correlation atoms |
35 for c = 1:nbColors | 80 [colors nbColors] = dico_color_separate(dico, mu); |
36 index = find(colors==c); | 81 |
37 if numel(index) == 2 | 82 % iterate on all pairs |
38 if dico(:,index(1))'*dico(:,index(2)) > 0 | 83 for c = 1:nbColors |
84 for tmpI = 1:numDicos | |
85 index = find(colors{tmpI}==c); | |
86 if ~isempty(index) | |
87 i = tmpI; | |
88 m = index; | |
89 break; | |
90 end | |
91 end | |
92 for tmpJ = i+1:numDicos | |
93 index = find(colors{tmpJ}==c); | |
94 if ~isempty(index) | |
95 j = tmpJ; | |
96 n = index; | |
97 break; | |
98 end | |
99 end | |
100 | |
101 if dico{i}(:,m)'*dico{j}(:,n) > 0 | |
39 %build the basis vectors | 102 %build the basis vectors |
40 v1 = dico(:,index(1))+dico(:,index(2)); | 103 v1 = dico{i}(:,m)+dico{j}(:,n); |
41 v1 = v1/norm(v1); | 104 v1 = v1/norm(v1); |
42 v2 = dico(:,index(1))-dico(:,index(2)); | 105 v2 = dico{i}(:,m)-dico{j}(:,n); |
43 v2 = v2/norm(v2); | 106 v2 = v2/norm(v2); |
44 | 107 |
45 dico(:,index(1)) = ctheta*v1+stheta*v2; | 108 dico{i}(:,m) = ctheta*v1+stheta*v2; |
46 dico(:,index(2)) = ctheta*v1-stheta*v2; | 109 dico{j}(:,n) = ctheta*v1-stheta*v2; |
47 else | 110 else |
48 v1 = dico(:,index(1))-dico(:,index(2)); | 111 v1 = dico{i}(:,m)-dico{j}(:,n); |
49 v1 = v1/norm(v1); | 112 v1 = v1/norm(v1); |
50 v2 = dico(:,index(1))+dico(:,index(2)); | 113 v2 = dico{i}(:,m)+dico{j}(:,n); |
51 v2 = v2/norm(v2); | 114 v2 = v2/norm(v2); |
52 | 115 |
53 dico(:,index(1)) = ctheta*v1+stheta*v2; | 116 dico{i}(:,m) = ctheta*v1+stheta*v2; |
54 dico(:,index(2)) = -ctheta*v1+stheta*v2; | 117 dico{j}(:,n) = -ctheta*v1+stheta*v2; |
118 end | |
119 end | |
120 niter = niter+1; | |
121 | |
122 % Remove noegative components and renormalize | |
123 for i = 1:length(dico) | |
124 dico{i} = max(dico{i},0); | |
125 for m = 1:size(dico{i},2) | |
126 dico{i}(:,m) = dico{i}(:,m)/norm(dico{i}(:,m)); | |
127 end | |
128 end | |
129 | |
130 maxCorr = 0; | |
131 for i = 1:numDicos | |
132 for j = i+1:numDicos | |
133 G{i,j} = dico{i}'*dico{j}; | |
134 maxCorr = max(maxCorr,max(max(abs(G{i,j})))); | |
55 end | 135 end |
56 end | 136 end |
57 end | 137 end |
58 niter = niter+1; | |
59 end | 138 end |
60 end | 139 end |
61 |