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