annotate examples/SMALL_test_coherence2.m @ 175:9eb5f0d4c1a4 danieleb

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