Mercurial > hg > smallbox
diff 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 |
line wrap: on
line diff
--- a/examples/SMALL_test_coherence2.m Thu Sep 29 09:46:52 2011 +0100 +++ b/examples/SMALL_test_coherence2.m Thu Oct 06 14:33:41 2011 +0100 @@ -1,13 +1,13 @@ clc, clear, close all %% Parameteres +nTrials = 10; %number of trials of the experiment + % Dictionary learning parameters toolbox = 'TwoStepDL'; %dictionary learning toolbox -dicUpdate = {'ksvd'}; %dictionary learning updates -dicDecorr = {'none','mailhe','tropp','barchiesi'}; %dictionary decorrelation methods -minCoherence = linspace(0.1,1,1); %coherence levels -minCoherence = 0.4; -%dicDecorr = {'barchiesi'}; +dicUpdate = 'ksvd'; %dictionary learning updates +dicDecorr = {'iterproj','ink-svd','shrinkgram'}; %dictionary decorrelation methods +minCoherence = linspace(0.1,1,10); %coherence levels iterNum = 20; %number of iterations epsilon = 1e-6; %tolerance level @@ -19,20 +19,16 @@ blockSize = 256; %size of audio frames overlap = 0.5; %overlap between consecutive frames - % Dependent parameters nActiveAtoms = fix(blockSize/100*percActiveAtoms); %number of active atoms % Initial dictionaries -dctDict = dictionary('dct',blockSize,dictSize); -dctDict = dctDict.phi; gaborParam = struct('N',blockSize,'redundancyFactor',2,'wd',@rectwin); gaborDict = Gabor_Dictionary(gaborParam); -initDicts = {[],dctDict,gaborDict}; -initDicts = {[]}; +initDicts = {[],gaborDict}; %% Generate audio approximation problem -signal = buffer(signal,blockSize,blockSize*overlap,@rectwin); +signal = buffer(signal,blockSize,blockSize*overlap,@rectwin); %buffer frames of audio into columns of the matrix S SMALL.Problem.b = signal.S; SMALL.Problem.b1 = SMALL.Problem.b; % copy signals from training set b to test set b1 (needed for later functions) @@ -42,20 +38,19 @@ %% Test -nDicUpdates = length(dicUpdate); %number of dictionary updates nDecorrAlgs = length(dicDecorr); %number of decorrelation algorithms nCorrLevels = length(minCoherence); %number of coherence levels nInitDicts = length(initDicts); %number of initial dictionaries -SMALL.DL(nInitDicts,nCorrLevels,nDecorrAlgs,nDicUpdates) = SMALL_init_DL(toolbox); %create dictionary learning structures -for iInitDicts=1:nInitDicts - for iCorrLevels=1:nCorrLevels - for iDecorrAlgs=1:nDecorrAlgs - for iDicUpdates=1:nDicUpdates - SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).toolbox = toolbox; - SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).name = dicUpdate{iDicUpdates}; - SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).profile = true; - SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).param = ... +SMALL.DL(nTrials,nInitDicts,nCorrLevels,nDecorrAlgs) = SMALL_init_DL(toolbox); %create dictionary learning structures +for iTrial=1:nTrials + for iInitDicts=1:nInitDicts + for iCorrLevels=1:nCorrLevels + for iDecorrAlgs=1:nDecorrAlgs + SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).toolbox = toolbox; + SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).name = dicUpdate; + SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).profile = true; + SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).param = ... struct( 'data',SMALL.Problem.b,... 'Tdata',nActiveAtoms,... 'dictsize',dictSize,... @@ -66,8 +61,9 @@ 'coherence',minCoherence(iCorrLevels),... 'initdict',initDicts(iInitDicts)); - SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates) = ... - SMALL_learn(SMALL.Problem,SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates)); + SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs) = ... + SMALL_learn(SMALL.Problem,SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs)); + save('SMALL_DL','SMALL'); end end end @@ -75,23 +71,23 @@ %% Evaluate coherence and snr of representation for the various methods sr = zeros(size(SMALL.DL)); %signal to noise ratio -mu = zeros(size(SMALL.DL)); %coherence +mu = zeros(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs,blockSize); %cumulative coherence dic(size(SMALL.DL)) = dictionary; %initialise dictionary objects -for iInitDict=1:nInitDicts - for iCorrLevels=1:nCorrLevels - for iDecorrAlgs=1:nDecorrAlgs - for iDicUpdates=1:nDicUpdates +for iTrial=1:nTrials + for iInitDicts=1:nInitDicts + for iCorrLevels=1:nCorrLevels + for iDecorrAlgs=1:nDecorrAlgs %Sparse representation - SMALL.Problem.A = SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).D; + SMALL.Problem.A = SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).D; tempSolver = SMALL_solve(SMALL.Problem,solver); %calculate snr - sr(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates) = ... - snr(SMALL.Problem.b,SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).D*tempSolver.solution); + sr(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs) = ... + snr(SMALL.Problem.b,SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).D*tempSolver.solution); %calculate mu - dic(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates) = ... - dictionary(SMALL.DL(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).D); - mu(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates) = ... - dic(iInitDicts,iCorrLevels,iDecorrAlgs,iDicUpdates).coherence; + dic(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs) = ... + dictionary(SMALL.DL(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).D); + mu(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs,:) = ... + dic(iTrial,iInitDicts,iCorrLevels,iDecorrAlgs).cumcoherence; end end end @@ -99,15 +95,15 @@ %% Plot results minMu = sqrt((dictSize-blockSize)/(blockSize*(dictSize-1))); %lowe bound on coherence -initDictsNames = {'Data','DCT','Gabor'}; -dicDecorrNames = {'K-SVD','INK-SVD','Grassmannian','New'}; -lineStyles = {'ks-','kd-','ko-','k*-'}; +initDictsNames = {'Data','Gabor'}; +dicDecorrNames = {'Iter. Proj. + Rotation','INK-SVD','Iter. Proj.'}; +lineStyles = {'ks-','kd-','ko-'}; for iInitDict=1:nInitDicts figure, hold on, grid on title([initDictsNames{iInitDict} ' Initialisation']); plot([1 1],[0 25],'k-'); for iDecorrAlgs=1:nDecorrAlgs - plot(mu(iInitDicts,:,iDecorrAlgs,1),sr(iInitDicts,:,iDecorrAlgs,1),... + plot(mu(1,iInitDict,:,iDecorrAlgs,1),sr(1,iInitDict,:,iDecorrAlgs),... lineStyles{iDecorrAlgs}); end plot([minMu minMu],[0 25],'k--')