Mercurial > hg > smallbox
comparison DL/two-step DL/dico_decorr_symetric.m @ 220:0d30f9074dd9
Merge
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Wed, 11 Apr 2012 15:56:39 +0100 |
parents | 69ce11724b1f |
children | fd0b5d36f6ad |
comparison
equal
deleted
inserted
replaced
165:775caafd5651 | 220:0d30f9074dd9 |
---|---|
1 function dico = dico_decorr_symetric(dico, mu) | |
2 %DICO_DECORR decorrelate a dictionary | |
3 % Parameters: | |
4 % dico: the dictionary, either a matrix or a cell array of matrices. | |
5 % mu: the coherence threshold | |
6 % | |
7 % Result: | |
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. | |
13 | |
14 eps = 1e-3; % define tolerance for normalisation term alpha | |
15 | |
16 % convert mu to the to the mean direction | |
17 theta = acos(mu)/2; | |
18 ctheta = cos(theta); | |
19 stheta = sin(theta); | |
20 | |
21 % compute atom weights | |
22 % if nargin > 2 | |
23 % rank = sum(amp.*amp, 2); | |
24 % else | |
25 % rank = randperm(length(dico)); | |
26 % end | |
27 | |
28 % if only one dictionary is provided, then decorrelate it | |
29 if ~iscell(dico) | |
30 % several decorrelation iterations might be needed to reach global | |
31 % coherence mu. niter can be adjusted to needs. | |
32 niter = 1; | |
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 | |
77 | |
78 while maxCorr > mu + eps | |
79 % find pairs of high correlation atoms | |
80 [colors nbColors] = dico_color_separate(dico, mu); | |
81 | |
82 % iterate on all pairs | |
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 | |
102 %build the basis vectors | |
103 v1 = dico{i}(:,m)+dico{j}(:,n); | |
104 v1 = v1/norm(v1); | |
105 v2 = dico{i}(:,m)-dico{j}(:,n); | |
106 v2 = v2/norm(v2); | |
107 | |
108 dico{i}(:,m) = ctheta*v1+stheta*v2; | |
109 dico{j}(:,n) = ctheta*v1-stheta*v2; | |
110 else | |
111 v1 = dico{i}(:,m)-dico{j}(:,n); | |
112 v1 = v1/norm(v1); | |
113 v2 = dico{i}(:,m)+dico{j}(:,n); | |
114 v2 = v2/norm(v2); | |
115 | |
116 dico{i}(:,m) = 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})))); | |
135 end | |
136 end | |
137 end | |
138 end | |
139 end |