Mercurial > hg > smallbox
comparison examples/SMALL_test_mocod.m @ 177:714fa7b8c1ad danieleb
added ramirez dl (to be completed) and MOCOD dictionary update
author | Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk> |
---|---|
date | Thu, 17 Nov 2011 11:18:25 +0000 |
parents | |
children | 0dc98f1c60bb |
comparison
equal
deleted
inserted
replaced
176:d0645d5fca7d | 177:714fa7b8c1ad |
---|---|
1 clc, clear, close all | |
2 | |
3 %% Parameteres | |
4 nTrials = 10; %number of trials of the experiment | |
5 | |
6 % Dictionary learning parameters | |
7 toolbox = 'TwoStepDL'; %dictionary learning toolbox | |
8 dicUpdate = 'mocod'; %dictionary learning updates | |
9 zeta = logspace(-2,2,10); | |
10 eta = logspace(-2,2,10); | |
11 | |
12 iterNum = 20; %number of iterations | |
13 epsilon = 1e-6; %tolerance level | |
14 dictSize = 512; %number of atoms in the dictionary | |
15 percActiveAtoms = 5; %percentage of active atoms | |
16 | |
17 % Test signal parameters | |
18 signal = audio('music03_16kHz.wav'); %audio signal | |
19 blockSize = 256; %size of audio frames | |
20 overlap = 0.5; %overlap between consecutive frames | |
21 | |
22 % Dependent parameters | |
23 nActiveAtoms = fix(blockSize/100*percActiveAtoms); %number of active atoms | |
24 | |
25 % Initial dictionaries | |
26 gaborParam = struct('N',blockSize,'redundancyFactor',2,'wd',@rectwin); | |
27 gaborDict = Gabor_Dictionary(gaborParam); | |
28 initDicts = {[],gaborDict}; | |
29 | |
30 %% Generate audio approximation problem | |
31 signal = buffer(signal,blockSize,blockSize*overlap,@rectwin); %buffer frames of audio into columns of the matrix S | |
32 SMALL.Problem.b = signal.S; | |
33 SMALL.Problem.b1 = SMALL.Problem.b; % copy signals from training set b to test set b1 (needed for later functions) | |
34 | |
35 % omp2 sparse representation solver | |
36 ompParam = struct('X',SMALL.Problem.b,'epsilon',epsilon,'maxatoms',nActiveAtoms); %parameters | |
37 solver = SMALL_init_solver('ompbox','omp2',ompParam,false); %solver structure | |
38 | |
39 %% Test | |
40 nInitDicts = length(initDicts); %number of initial dictionaries | |
41 nZetas = length(zeta); | |
42 nEtas = length(eta); | |
43 | |
44 SMALL.DL(nTrials,nInitDicts,nZetas,nEtas) = SMALL_init_DL(toolbox); %create dictionary learning structures | |
45 for iTrial=1:nTrials | |
46 for iInitDicts=1:nInitDicts | |
47 for iZetas=1:nZetas | |
48 for iEtas=1:nEtas | |
49 SMALL.DL(iTrial,iInitDicts,iZetas,iEtas).toolbox = toolbox; | |
50 SMALL.DL(iTrial,iInitDicts,iZetas,iEtas).name = dicUpdate; | |
51 SMALL.DL(iTrial,iInitDicts,iZetas,iEtas).profile = true; | |
52 SMALL.DL(iTrial,iInitDicts,iZetas,iEtas).param = ... | |
53 struct('data',SMALL.Problem.b,... | |
54 'Tdata',nActiveAtoms,... | |
55 'dictsize',dictSize,... | |
56 'iternum',iterNum,... | |
57 'memusage','high',... | |
58 'solver',solver,... | |
59 'initdict',initDicts(iInitDicts),... | |
60 'zeta',zeta(iZetas),... | |
61 'eta',eta(iEtas)); | |
62 SMALL.DL(iTrial,iInitDicts,iZetas,iEtas) = ... | |
63 SMALL_learn(SMALL.Problem,SMALL.DL(iTrial,iInitDicts,iZetas,iEtas)); | |
64 end | |
65 end | |
66 end | |
67 end | |
68 | |
69 %% Evaluate coherence and snr of representation for the various methods | |
70 sr = zeros(size(SMALL.DL)); %signal to noise ratio | |
71 mu = zeros(iTrial,iInitDicts,iZetas,iEtas); %coherence | |
72 dic(size(SMALL.DL)) = dictionary; %initialise dictionary objects | |
73 for iTrial=1:nTrials | |
74 for iInitDicts=1:nInitDicts | |
75 for iZetas=1:nZetas | |
76 for iEtas=1:nEtas | |
77 %Sparse representation | |
78 SMALL.Problem.A = SMALL.DL(iTrial,iInitDicts,iZetas,iEtas).D; | |
79 tempSolver = SMALL_solve(SMALL.Problem,solver); | |
80 %calculate snr | |
81 sr(iTrial,iInitDicts,iZetas,iEtas) = ... | |
82 snr(SMALL.Problem.b,SMALL.DL(iTrial,iInitDicts,iZetas,iEtas).D*tempSolver.solution); | |
83 %calculate mu | |
84 dic(iTrial,iInitDicts,iZetas,iEtas) = ... | |
85 dictionary(SMALL.DL(iTrial,iInitDicts,iZetas,iEtas).D); | |
86 mu(iTrial,iInitDicts,iZetas,iEtas) = ... | |
87 dic(iTrial,iInitDicts,iZetas,iEtas).coherence; | |
88 end | |
89 end | |
90 end | |
91 end | |
92 | |
93 save('MOCOD.mat') | |
94 | |
95 %% Plot results | |
96 minMu = sqrt((dictSize-blockSize)/(blockSize*(dictSize-1))); %lowe bound on coherence | |
97 initDictsNames = {'Data','Gabor'}; | |
98 lineStyles = {'k.-','r*-','b+-'}; | |
99 for iInitDict=1:nInitDicts | |
100 figure, hold on, grid on | |
101 title([initDictsNames{iInitDict} ' Initialisation']); | |
102 coherenceLevels = squeeze(mean(mu(:,iInitDict,:,:),1)); | |
103 meanSNRs = squeeze(mean(sr(:,iInitDict,:,:),1)); | |
104 %stdSNRs = squeeze(std(sr(:,iInitDict,iZetas,iEtas),0,1)); | |
105 subplot(2,2,1) | |
106 surf(eta,zeta,coherenceLevels); | |
107 set(gca,'Xscale','log','Yscale','log','ZLim',[0 1.4]); | |
108 view(gca,130,20) | |
109 xlabel('\eta'); | |
110 ylabel('\zeta'); | |
111 zlabel('\mu'); | |
112 title('Coherence') | |
113 | |
114 subplot(2,2,2) | |
115 surf(eta,zeta,meanSNRs); | |
116 set(gca,'Xscale','log','Yscale','log','ZLim',[0 25]); | |
117 view(gca,130,20) | |
118 xlabel('\eta'); | |
119 ylabel('\zeta'); | |
120 zlabel('SNR (dB)'); | |
121 title('Reconstruction Error') | |
122 | |
123 subplot(2,2,[3 4]) | |
124 mus = mu(:,iInitDict,:,:); | |
125 mus = mus(:); | |
126 SNRs = sr(:,iInitDict,:,:); | |
127 SNRs = SNRs(:); | |
128 [un idx] = sort(mus); | |
129 plot([1 1],[0 25],'k') | |
130 hold on, grid on | |
131 scatter(mus(idx),SNRs(idx),'k+'); | |
132 plot([minMu minMu],[0 25],'k--') | |
133 set(gca,'YLim',[0 25],'XLim',[0 1.4]); | |
134 xlabel('\mu'); | |
135 ylabel('SNR (dB)'); | |
136 legend([{'\mu_{max}'},'MOCOD',{'\mu_{min}'}]); | |
137 title('Coherence-Reconstruction Error Tradeoff') | |
138 | |
139 % plot([minMu minMu],[0 25],'k--') | |
140 % | |
141 % set(gca,'YLim',[0 25],'XLim',[0 1.4]); | |
142 % legend([{'\mu_{max}'},dicDecorrNames,{'\mu_{min}'}]); | |
143 % xlabel('\mu'); | |
144 % ylabel('SNR (dB)'); | |
145 end |