comparison examples/SMALL_test_coherence2.m @ 170:68fb71aa5339 danieleb

Added dictionary decorrelation functions and test script for Letters paper.
author Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk>
date Thu, 06 Oct 2011 14:33:41 +0100
parents 290cca7d3469
children dc2f0fa21310
comparison
equal deleted inserted replaced
169:290cca7d3469 170:68fb71aa5339
1 clc, clear, close all 1 clc, clear, close all
2 2
3 %% Parameteres 3 %% Parameteres
4 nTrials = 10; %number of trials of the experiment
5
4 % Dictionary learning parameters 6 % Dictionary learning parameters
5 toolbox = 'TwoStepDL'; %dictionary learning toolbox 7 toolbox = 'TwoStepDL'; %dictionary learning toolbox
6 dicUpdate = {'ksvd'}; %dictionary learning updates 8 dicUpdate = 'ksvd'; %dictionary learning updates
7 dicDecorr = {'none','mailhe','tropp','barchiesi'}; %dictionary decorrelation methods 9 dicDecorr = {'iterproj','ink-svd','shrinkgram'}; %dictionary decorrelation methods
8 minCoherence = linspace(0.1,1,1); %coherence levels 10 minCoherence = linspace(0.1,1,10); %coherence levels
9 minCoherence = 0.4;
10 %dicDecorr = {'barchiesi'};
11 11
12 iterNum = 20; %number of iterations 12 iterNum = 20; %number of iterations
13 epsilon = 1e-6; %tolerance level 13 epsilon = 1e-6; %tolerance level
14 dictSize = 512; %number of atoms in the dictionary 14 dictSize = 512; %number of atoms in the dictionary
15 percActiveAtoms = 5; %percentage of active atoms 15 percActiveAtoms = 5; %percentage of active atoms
17 % Test signal parameters 17 % Test signal parameters
18 signal = audio('music03_16kHz.wav'); %audio signal 18 signal = audio('music03_16kHz.wav'); %audio signal
19 blockSize = 256; %size of audio frames 19 blockSize = 256; %size of audio frames
20 overlap = 0.5; %overlap between consecutive frames 20 overlap = 0.5; %overlap between consecutive frames
21 21
22
23 % Dependent parameters 22 % Dependent parameters
24 nActiveAtoms = fix(blockSize/100*percActiveAtoms); %number of active atoms 23 nActiveAtoms = fix(blockSize/100*percActiveAtoms); %number of active atoms
25 24
26 % Initial dictionaries 25 % Initial dictionaries
27 dctDict = dictionary('dct',blockSize,dictSize);
28 dctDict = dctDict.phi;
29 gaborParam = struct('N',blockSize,'redundancyFactor',2,'wd',@rectwin); 26 gaborParam = struct('N',blockSize,'redundancyFactor',2,'wd',@rectwin);
30 gaborDict = Gabor_Dictionary(gaborParam); 27 gaborDict = Gabor_Dictionary(gaborParam);
31 initDicts = {[],dctDict,gaborDict}; 28 initDicts = {[],gaborDict};
32 initDicts = {[]};
33 29
34 %% Generate audio approximation problem 30 %% Generate audio approximation problem
35 signal = buffer(signal,blockSize,blockSize*overlap,@rectwin); 31 signal = buffer(signal,blockSize,blockSize*overlap,@rectwin); %buffer frames of audio into columns of the matrix S
36 SMALL.Problem.b = signal.S; 32 SMALL.Problem.b = signal.S;
37 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)
38 34
39 % omp2 sparse representation solver 35 % omp2 sparse representation solver
40 ompParam = struct('X',SMALL.Problem.b,'epsilon',epsilon,'maxatoms',nActiveAtoms); %parameters 36 ompParam = struct('X',SMALL.Problem.b,'epsilon',epsilon,'maxatoms',nActiveAtoms); %parameters
41 solver = SMALL_init_solver('ompbox','omp2',ompParam,false); %solver structure 37 solver = SMALL_init_solver('ompbox','omp2',ompParam,false); %solver structure
42 38
43 39
44 %% Test 40 %% Test
45 nDicUpdates = length(dicUpdate); %number of dictionary updates
46 nDecorrAlgs = length(dicDecorr); %number of decorrelation algorithms 41 nDecorrAlgs = length(dicDecorr); %number of decorrelation algorithms
47 nCorrLevels = length(minCoherence); %number of coherence levels 42 nCorrLevels = length(minCoherence); %number of coherence levels
48 nInitDicts = length(initDicts); %number of initial dictionaries 43 nInitDicts = length(initDicts); %number of initial dictionaries
49 44
50 SMALL.DL(nInitDicts,nCorrLevels,nDecorrAlgs,nDicUpdates) = SMALL_init_DL(toolbox); %create dictionary learning structures 45 SMALL.DL(nTrials,nInitDicts,nCorrLevels,nDecorrAlgs) = SMALL_init_DL(toolbox); %create dictionary learning structures
51 for iInitDicts=1:nInitDicts 46 for iTrial=1:nTrials
52 for iCorrLevels=1:nCorrLevels 47 for iInitDicts=1:nInitDicts
53 for iDecorrAlgs=1:nDecorrAlgs 48 for iCorrLevels=1:nCorrLevels
54 for iDicUpdates=1:nDicUpdates 49 for iDecorrAlgs=1:nDecorrAlgs
55 SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).toolbox = toolbox; 50 SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).toolbox = toolbox;
56 SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).name = dicUpdate{iDicUpdates}; 51 SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).name = dicUpdate;
57 SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).profile = true; 52 SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).profile = true;
58 SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).param = ... 53 SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).param = ...
59 struct( 'data',SMALL.Problem.b,... 54 struct( 'data',SMALL.Problem.b,...
60 'Tdata',nActiveAtoms,... 55 'Tdata',nActiveAtoms,...
61 'dictsize',dictSize,... 56 'dictsize',dictSize,...
62 'iternum',iterNum,... 57 'iternum',iterNum,...
63 'memusage','high',... 58 'memusage','high',...
64 'solver',solver,... 59 'solver',solver,...
65 'decFcn',dicDecorr{iDecorrAlgs},... 60 'decFcn',dicDecorr{iDecorrAlgs},...
66 'coherence',minCoherence(iCorrLevels),... 61 'coherence',minCoherence(iCorrLevels),...
67 'initdict',initDicts(iInitDicts)); 62 'initdict',initDicts(iInitDicts));
68 63
69 SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates) = ... 64 SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs) = ...
70 SMALL_learn(SMALL.Problem,SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates)); 65 SMALL_learn(SMALL.Problem,SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs));
66 save('SMALL_DL','SMALL');
71 end 67 end
72 end 68 end
73 end 69 end
74 end 70 end
75 71
76 %% Evaluate coherence and snr of representation for the various methods 72 %% Evaluate coherence and snr of representation for the various methods
77 sr = zeros(size(SMALL.DL)); %signal to noise ratio 73 sr = zeros(size(SMALL.DL)); %signal to noise ratio
78 mu = zeros(size(SMALL.DL)); %coherence 74 mu = zeros(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs,blockSize); %cumulative coherence
79 dic(size(SMALL.DL)) = dictionary; %initialise dictionary objects 75 dic(size(SMALL.DL)) = dictionary; %initialise dictionary objects
80 for iInitDict=1:nInitDicts 76 for iTrial=1:nTrials
81 for iCorrLevels=1:nCorrLevels 77 for iInitDicts=1:nInitDicts
82 for iDecorrAlgs=1:nDecorrAlgs 78 for iCorrLevels=1:nCorrLevels
83 for iDicUpdates=1:nDicUpdates 79 for iDecorrAlgs=1:nDecorrAlgs
84 %Sparse representation 80 %Sparse representation
85 SMALL.Problem.A = SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).D; 81 SMALL.Problem.A = SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).D;
86 tempSolver = SMALL_solve(SMALL.Problem,solver); 82 tempSolver = SMALL_solve(SMALL.Problem,solver);
87 %calculate snr 83 %calculate snr
88 sr(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates) = ... 84 sr(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs) = ...
89 snr(SMALL.Problem.b,SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).D*tempSolver.solution); 85 snr(SMALL.Problem.b,SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).D*tempSolver.solution);
90 %calculate mu 86 %calculate mu
91 dic(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates) = ... 87 dic(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs) = ...
92 dictionary(SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).D); 88 dictionary(SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).D);
93 mu(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates) = ... 89 mu(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs,:) = ...
94 dic(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).coherence; 90 dic(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).cumcoherence;
95 end 91 end
96 end 92 end
97 end 93 end
98 end 94 end
99 95
100 %% Plot results 96 %% Plot results
101 minMu = sqrt((dictSize-blockSize)/(blockSize*(dictSize-1))); %lowe bound on coherence 97 minMu = sqrt((dictSize-blockSize)/(blockSize*(dictSize-1))); %lowe bound on coherence
102 initDictsNames = {'Data','DCT','Gabor'}; 98 initDictsNames = {'Data','Gabor'};
103 dicDecorrNames = {'K-SVD','INK-SVD','Grassmannian','New'}; 99 dicDecorrNames = {'Iter. Proj. + Rotation','INK-SVD','Iter. Proj.'};
104 lineStyles = {'ks-','kd-','ko-','k*-'}; 100 lineStyles = {'ks-','kd-','ko-'};
105 for iInitDict=1:nInitDicts 101 for iInitDict=1:nInitDicts
106 figure, hold on, grid on 102 figure, hold on, grid on
107 title([initDictsNames{iInitDict} ' Initialisation']); 103 title([initDictsNames{iInitDict} ' Initialisation']);
108 plot([1 1],[0 25],'k-'); 104 plot([1 1],[0 25],'k-');
109 for iDecorrAlgs=1:nDecorrAlgs 105 for iDecorrAlgs=1:nDecorrAlgs
110 plot(mu(iInitDicts,:,iDecorrAlgs,1),sr(iInitDicts,:,iDecorrAlgs,1),... 106 plot(mu(1,iInitDict,:,iDecorrAlgs,1),sr(1,iInitDict,:,iDecorrAlgs),...
111 lineStyles{iDecorrAlgs}); 107 lineStyles{iDecorrAlgs});
112 end 108 end
113 plot([minMu minMu],[0 25],'k--') 109 plot([minMu minMu],[0 25],'k--')
114 110
115 set(gca,'YLim',[0 25],'XLim',[0 1.4]); 111 set(gca,'YLim',[0 25],'XLim',[0 1.4]);