comparison examples/SMALL_test_coherence.m @ 169:290cca7d3469 danieleb

Added dictionary decorrelation functions and test script for ICASSP paper.
author Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk>
date Thu, 29 Sep 2011 09:46:52 +0100
parents 8324c7ea6602
children
comparison
equal deleted inserted replaced
168:ff866a412be5 169:290cca7d3469
16 percActiveAtoms = 5; %percentage of active atoms 16 percActiveAtoms = 5; %percentage of active atoms
17 17
18 % Dependent parameters 18 % Dependent parameters
19 nActiveAtoms = fix(blockSize/100*percActiveAtoms); %number of active atoms 19 nActiveAtoms = fix(blockSize/100*percActiveAtoms); %number of active atoms
20 epsilon = 1/sigma; %error constraint for sparse representation step (corresponds to noise applied to signals) 20 epsilon = 1/sigma; %error constraint for sparse representation step (corresponds to noise applied to signals)
21 %minCoherence = sqrt((dictSize-blockSize)/(blockSize*(dictSize-1))); %target coherence (based on coherence lower bound) 21 minMu = sqrt((dictSize-blockSize)/(blockSize*(dictSize-1))); %target coherence (based on coherence lower bound)
22 minCoherence = 0.4; %target coherence 22 minCoherence = [0.1:0.1:1];
23 23
24 % Initial dictionaries 24 % Initial dictionaries
25 dctDict = dictionary('dct',blockSize,dictSize); 25 dctDict = dictionary('dct',blockSize,dictSize);
26 dctDict = dctDict.phi; 26 dctDict = dctDict.phi;
27 gaborParam = struct('N',blockSize,'redundancyFactor',2,'wd',@rectwin); 27 gaborParam = struct('N',blockSize,'redundancyFactor',2,'wd',@rectwin);
28 gaborDict = Gabor_Dictionary(gaborParam); 28 gaborDict = Gabor_Dictionary(gaborParam);
29 29
30 %% Generate audio denoising problem with low noise (audio representation) 30 %% Generate audio denoising problem with low noise (audio representation)
31 SMALL.Problem = generateAudioDenoiseProblem(signal.s,[],blockSize,... 31 SMALL.Problem = generateAudioDenoiseProblem(signal.s,[],blockSize,...
32 dictSize,overlap,sigma); % generate representation problem 32 dictSize,overlap,sigma); % generate representation problem
33 SMALL.Problem.b1 = SMALL.Problem.b; % copy signals from training set b to test set b1 (needed for later functions) 33 SMALL.Problem.b1 = SMALL.Problem.b; % copy signals from training set b to test set b1 (needed for later functions)
34 34
35 % omp2 sparse representation solver 35 % omp2 sparse representation solver
36 ompParam = struct('X',SMALL.Problem.b,'epsilon',epsilon,'maxatoms',nActiveAtoms); %parameters 36 ompParam = struct('X',SMALL.Problem.b,'epsilon',epsilon,'maxatoms',nActiveAtoms); %parameters
37 solver = SMALL_init_solver('ompbox','omp2',ompParam,false); %solver structure 37 solver = SMALL_init_solver('ompbox','omp2',ompParam,false); %solver structure
38 38
39 39
40 %% Test ksvd dictionary update 40 %% Test
41 name = dicUpdate{1}; %use ksvd update 41 name = dicUpdate{1}; %use ksvd update
42 SMALL.DL(1:9) = SMALL_init_DL(toolbox,name); %create dictionary learning structures 42 SMALL.DL(1:36) = SMALL_init_DL(toolbox,name); %create dictionary learning structures
43 43
44 % learn with random initialisation and no decorrelation 44 % learn with random initialisation and no decorrelation
45 SMALL.DL(1).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,... 45 SMALL.DL(1).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
46 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,... 46 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
47 'decFcn','none'); %parameters for the dictionary learning 47 'decFcn','none'); %parameters for the dictionary learning
48 SMALL.DL(1) = SMALL_learn(SMALL.Problem,SMALL.DL(1)); %learn dictionary 48 SMALL.DL(1) = SMALL_learn(SMALL.Problem,SMALL.DL(1)); %learn dictionary
49 %save('SMALL','SMALL');
49 50
50 % learn with random initialisation and mailhe decorrelation 51 % learn with random initialisation and mailhe decorrelation
51 SMALL.DL(2).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,... 52 for iMu=1:10
52 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,... 53 SMALL.DL(1+iMu).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
53 'decFcn','mailhe','coherence',minCoherence); %parameters for the dictionary learning 54 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
54 SMALL.DL(2) = SMALL_learn(SMALL.Problem,SMALL.DL(2)); %learn dictionary 55 'decFcn','mailhe','coherence',minCoherence(iMu)); %parameters for the dictionary learning
55 56 SMALL.DL(1+iMu) = SMALL_learn(SMALL.Problem,SMALL.DL(1+iMu)); %learn dictionary
56 % learn with random initialisation and tropp decorrelation 57 %save('SMALL','SMALL');
57 SMALL.DL(3).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,... 58 end
58 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
59 'decFcn','tropp','coherence',minCoherence); %parameters for the dictionary learning
60 SMALL.DL(3) = SMALL_learn(SMALL.Problem,SMALL.DL(3)); %learn dictionary
61
62 % Learn with dct initialisation and no decorrelation
63 SMALL.DL(4).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
64 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
65 'decFcn','none','initdict',dctDict); %parameters for the dictionary learning
66 SMALL.DL(4) = SMALL_learn(SMALL.Problem,SMALL.DL(4)); %learn dictionary
67
68 % learn with dct initialisation and mailhe decorrelation
69 SMALL.DL(5).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
70 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
71 'decFcn','mailhe','coherence',minCoherence,'initdict',dctDict); %parameters for the dictionary learning
72 SMALL.DL(5) = SMALL_learn(SMALL.Problem,SMALL.DL(5)); %learn dictionary
73
74 % learn with dct initialisation and tropp decorrelation
75 SMALL.DL(6).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
76 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
77 'decFcn','tropp','coherence',minCoherence,'initdict',dctDict); %parameters for the dictionary learning
78 SMALL.DL(6) = SMALL_learn(SMALL.Problem,SMALL.DL(6)); %learn dictionary
79
80 % Learn with gabor initialisation and no decorrelation
81 SMALL.DL(7).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
82 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
83 'decFcn','none','initdict',gaborDict); %parameters for the dictionary learning
84 SMALL.DL(7) = SMALL_learn(SMALL.Problem,SMALL.DL(7)); %learn dictionary
85
86 % learn with gabor initialisation and mailhe decorrelation
87 SMALL.DL(8).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
88 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
89 'decFcn','mailhe','coherence',minCoherence,'initdict',gaborDict); %parameters for the dictionary learning
90 SMALL.DL(8) = SMALL_learn(SMALL.Problem,SMALL.DL(8)); %learn dictionary
91
92 % learn with gabor initialisation and tropp decorrelation
93 SMALL.DL(9).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
94 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
95 'decFcn','tropp','coherence',minCoherence,'initdict',gaborDict); %parameters for the dictionary learning
96 SMALL.DL(9) = SMALL_learn(SMALL.Problem,SMALL.DL(9)); %learn dictionary
97
98 %% Test mailhe dictionary update
99 name = dicUpdate{2}; %use mailhe update
100 SMALL.DL(10:18) = SMALL_init_DL(toolbox,name); %create dictionary learning structure
101
102 % learn with random initialisation and no decorrelation
103 SMALL.DL(10).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
104 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
105 'decFcn','none'); %parameters for the dictionary learning
106 SMALL.DL(10) = SMALL_learn(SMALL.Problem,SMALL.DL(10)); %learn dictionary
107
108 % learn with random initialisation and mailhe decorrelation
109 SMALL.DL(11).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
110 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
111 'decFcn','mailhe','coherence',minCoherence); %parameters for the dictionary learning
112 SMALL.DL(11) = SMALL_learn(SMALL.Problem,SMALL.DL(11)); %learn dictionary
113 59
114 % learn with random initialisation and tropp decorrelation 60 % learn with random initialisation and tropp decorrelation
115 SMALL.DL(12).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,... 61 SMALL.DL(12).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
116 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,... 62 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
117 'decFcn','tropp','coherence',minCoherence); %parameters for the dictionary learning 63 'decFcn','tropp','coherence',minCoherence); %parameters for the dictionary learning
118 SMALL.DL(12) = SMALL_learn(SMALL.Problem,SMALL.DL(12)); %learn dictionary 64 SMALL.DL(12) = SMALL_learn(SMALL.Problem,SMALL.DL(12)); %learn dictionary
119 65
120 % Learn with dct initialisation and no decorrelation 66 % Learn with dct initialisation and no decorrelation
121 SMALL.DL(13).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,... 67 SMALL.DL(13).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
122 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,... 68 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
123 'decFcn','none','initdict',dctDict); %parameters for the dictionary learning 69 'decFcn','none','initdict',dctDict); %parameters for the dictionary learning
124 SMALL.DL(13) = SMALL_learn(SMALL.Problem,SMALL.DL(13)); %learn dictionary 70 SMALL.DL(13) = SMALL_learn(SMALL.Problem,SMALL.DL(13)); %learn dictionary
125 71
126 % learn with dct initialisation and mailhe decorrelation 72 % learn with dct initialisation and mailhe decorrelation
127 SMALL.DL(14).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,... 73 for iMu=1:10
128 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,... 74 SMALL.DL(13+iMu).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
129 'decFcn','mailhe','coherence',minCoherence,'initdict',dctDict); %parameters for the dictionary learning 75 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
130 SMALL.DL(14) = SMALL_learn(SMALL.Problem,SMALL.DL(14)); %learn dictionary 76 'decFcn','mailhe','coherence',minCoherence(iMu),'initdict',dctDict); %parameters for the dictionary learning
77 SMALL.DL(13+iMu) = SMALL_learn(SMALL.Problem,SMALL.DL(13+iMu)); %learn dictionary
78 %save('SMALL','SMALL');
79 end
131 80
132 % learn with dct initialisation and tropp decorrelation 81 % learn with dct initialisation and tropp decorrelation
133 SMALL.DL(15).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,... 82 SMALL.DL(24).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
134 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,... 83 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
135 'decFcn','tropp','coherence',minCoherence,'initdict',dctDict); %parameters for the dictionary learning 84 'decFcn','tropp','coherence',minCoherence,'initdict',dctDict); %parameters for the dictionary learning
136 SMALL.DL(15) = SMALL_learn(SMALL.Problem,SMALL.DL(15)); %learn dictionary 85 SMALL.DL(24) = SMALL_learn(SMALL.Problem,SMALL.DL(24)); %learn dictionary
86
137 87
138 % Learn with gabor initialisation and no decorrelation 88 % Learn with gabor initialisation and no decorrelation
139 SMALL.DL(16).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,... 89 SMALL.DL(25).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
140 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,... 90 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
141 'decFcn','none','initdict',gaborDict); %parameters for the dictionary learning 91 'decFcn','none','initdict',gaborDict); %parameters for the dictionary learning
142 SMALL.DL(16) = SMALL_learn(SMALL.Problem,SMALL.DL(16)); %learn dictionary 92 SMALL.DL(25) = SMALL_learn(SMALL.Problem,SMALL.DL(25)); %learn dictionary
143 93
144 % learn with gabor initialisation and mailhe decorrelation 94 % learn with gabor initialisation and mailhe decorrelation
145 SMALL.DL(17).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,... 95 for iMu=1:10
146 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,... 96 SMALL.DL(25+iMu).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
147 'decFcn','mailhe','coherence',minCoherence,'initdict',gaborDict); %parameters for the dictionary learning 97 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
148 SMALL.DL(17) = SMALL_learn(SMALL.Problem,SMALL.DL(17)); %learn dictionary 98 'decFcn','mailhe','coherence',minCoherence(iMu),'initdict',gaborDict); %parameters for the dictionary learning
99 SMALL.DL(25+iMu) = SMALL_learn(SMALL.Problem,SMALL.DL(25+iMu)); %learn dictionary
100 %save('SMALL','SMALL');
101 end
149 102
150 % learn with gabor initialisation and tropp decorrelation 103 % learn with gabor initialisation and tropp decorrelation
151 SMALL.DL(18).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,... 104 SMALL.DL(36).param = struct('data',SMALL.Problem.b,'Tdata',nActiveAtoms,...
152 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,... 105 'dictsize',dictSize,'iternum',iterNum,'memusage','high','solver',solver,...
153 'decFcn','tropp','coherence',minCoherence,'initdict',gaborDict); %parameters for the dictionary learning 106 'decFcn','tropp','coherence',minCoherence,'initdict',gaborDict); %parameters for the dictionary learning
154 SMALL.DL(18) = SMALL_learn(SMALL.Problem,SMALL.DL(18)); %learn dictionary 107 SMALL.DL(36) = SMALL_learn(SMALL.Problem,SMALL.DL(36)); %learn dictionary
155 108
156 %% Evaluate coherence and snr of representation for the various methods 109 %% Evaluate coherence and snr of representation for the various methods
157 sigNoiseRatio = zeros(18,1); 110 sigNoiseRatio = zeros(36,1);
158 mu = zeros(18,1); 111 mu = zeros(36,1);
159 for i=1:18 112 for i=1:36
160 SMALL.Problem.A = SMALL.DL(i).D; 113 SMALL.Problem.A = SMALL.DL(i).D;
161 tempSolver = SMALL_solve(SMALL.Problem,solver); 114 tempSolver = SMALL_solve(SMALL.Problem,solver);
162 sigNoiseRatio(i) = snr(SMALL.Problem.b,SMALL.DL(i).D*tempSolver.solution); 115 sigNoiseRatio(i) = snr(SMALL.Problem.b,SMALL.DL(i).D*tempSolver.solution);
163 dic(i) = dictionary(SMALL.DL(i).D); 116 dic(i) = dictionary(SMALL.DL(i).D);
164 mu(i) = dic(i).coherence; 117 mu(i) = dic(i).coherence;
165 end 118 end
166 119
167 %% Plot results 120 %% Plot results
168 minMu = sqrt((dictSize-blockSize)/(blockSize*(dictSize-1))); 121 minMu = sqrt((dictSize-blockSize)/(blockSize*(dictSize-1)));
169 maxSNR = max(sigNoiseRatio); 122
170 123 figure,
171 figure, subplot(1,2,1) 124 %subplot(3,1,1)
172 snrMat = buffer(sigNoiseRatio(1:9),3); 125 hold on, grid on
173 bar(snrMat'); 126 title('Data Initialisation')
174 title('Signal to noise ratio') 127 plot([1 1],[0 25],'k-');
175 xlabel('Initial dictionary') 128 plot(mu(1),sigNoiseRatio(1),'ks');
176 ylabel('SNR (dB)') 129 plot(mu(12),sigNoiseRatio(12),'kd');
177 set(gca,'XTickLabel',{'data','dct','gabor'}); 130 plot(mu(2:11),sigNoiseRatio(2:11),'k*-');
178 legend('none','Mailhe','Tropp') 131 plot([minMu minMu],[0 25],'k--')
179 grid on 132 set(gca,'YLim',[0 25],'XLim',[0 1.4]);
180 133 legend({'\mu_{max}','K-SVD','Grassmannian','INK-SVD','\mu_{min}'});
134 xlabel('\mu');
135 ylabel('SNR (dB)');
136
137 figure
138 %subplot(3,1,2)
139 hold on, grid on
140 title('DCT Initialisation')
141 plot([1 1],[0 25],'k-');
142 plot(mu(13),sigNoiseRatio(13),'ks');
143 plot(mu(24),sigNoiseRatio(24),'kd');
144 plot(mu(14:23),sigNoiseRatio(14:23),'k*-');
145 plot([minMu minMu],[0 25],'k--')
146 set(gca,'YLim',[0 25],'XLim',[0 1.4]);
147 legend({'\mu_{max}','K-SVD','Grassmannian','INK-SVD','\mu_{min}'});
148 xlabel('\mu');
149 ylabel('SNR (dB)');
150
151 figure
152 %subplot(3,1,3)
153 hold on, grid on
154 title('Gabor Initialisation')
155 plot([1 1],[0 25],'k-');
156 plot(mu(25),sigNoiseRatio(25),'ks');
157 plot(mu(36),sigNoiseRatio(36),'kd');
158 plot(mu(26:35),sigNoiseRatio(26:35),'k*-');
159 plot([minMu minMu],[0 25],'k--')
160 set(gca,'YLim',[0 25],'XLim',[0 1.4]);
161 legend({'\mu_{max}','K-SVD','Grassmannian','INK-SVD','\mu_{min}'});
162 xlabel('\mu');
163 ylabel('SNR (dB)');
164
165 % minMu = sqrt((dictSize-blockSize)/(blockSize*(dictSize-1)));
166 % maxSNR = max(sigNoiseRatio);
167 %
168 % figure, subplot(2,2,1)
169 % snrMat = buffer(sigNoiseRatio(1:9),3);
170 % bar(snrMat');
171 % title('Signal to noise ratio')
172 % xlabel('Initial dictionary')
173 % ylabel('SNR (dB)')
174 % set(gca,'XTickLabel',{'data','dct','gabor'});
175 % legend('none','Mailhe','Tropp')
176 % grid on
177 %
181 % subplot(2,2,2), grid on 178 % subplot(2,2,2), grid on
182 % snrMat = buffer(sigNoiseRatio(10:18),3); 179 % snrMat = buffer(sigNoiseRatio(10:18),3);
183 % bar(snrMat'); 180 % bar(snrMat');
184 % title('SNR - Mailhe Update') 181 % title('SNR - Mailhe Update')
185 % xlabel('Initial dictionary') 182 % xlabel('Initial dictionary')
186 % ylabel('SNR (dB)') 183 % ylabel('SNR (dB)')
187 % set(gca,'XTickLabel',{'data','dct','gabor'},'YLim',[0 maxSNR+1]); 184 % set(gca,'XTickLabel',{'data','dct','gabor'},'YLim',[0 maxSNR+1]);
188 % legend('none','Mailhe','Tropp') 185 % legend('none','Mailhe','Tropp')
189 % grid on 186 % grid on
190 187 %
191 subplot(1,2,2), hold on, grid on 188 % subplot(2,2,3), hold on, grid on
192 title('Coherence') 189 % title('Coherence')
193 muMat = buffer(mu(1:9),3); 190 % muMat = buffer(mu(1:9),3);
194 line([0.5 3.5],[1 1],'Color','r'); 191 % line([0.5 3.5],[1 1],'Color','r');
195 bar(muMat'); 192 % bar(muMat');
196 line([0.5 3.5],[minMu minMu],'Color','k'); 193 % line([0.5 3.5],[minMu minMu],'Color','k');
197 set(gca,'XTick',1:3,'XTickLabel',{'data','dct','gabor'},'YLim',[0 1.05]) 194 % set(gca,'XTick',1:3,'XTickLabel',{'data','dct','gabor'},'YLim',[0 1.05])
198 legend('\mu_{max}','none','Mailhe','Tropp','\mu_{min}') 195 % legend('\mu_{max}','none','Mailhe','Tropp','\mu_{min}')
199 ylabel('\mu') 196 % ylabel('\mu')
200 xlabel('Initial dictionary') 197 % xlabel('Initial dictionary')
201 198 %
202 % subplot(2,2,4), hold on, grid on 199 % subplot(2,2,4), hold on, grid on
203 % title('Coherence - Mailhe Update') 200 % title('Coherence - Mailhe Update')
204 % muMat = buffer(mu(10:18),3); 201 % muMat = buffer(mu(10:18),3);
205 % line([0.5 3.5],[1 1],'Color','r'); 202 % line([0.5 3.5],[1 1],'Color','r');
206 % bar(muMat'); 203 % bar(muMat');