changeset 181:0dc98f1c60bb danieleb

minor edits
author Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk>
date Thu, 05 Jan 2012 15:46:13 +0000
parents 28b20fd46ba7
children f8bc99a5470c
files examples/SMALL_test_mocod.m
diffstat 1 files changed, 61 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/examples/SMALL_test_mocod.m	Thu Nov 17 13:01:55 2011 +0000
+++ b/examples/SMALL_test_mocod.m	Thu Jan 05 15:46:13 2012 +0000
@@ -1,18 +1,25 @@
+%% SMALL_test_mocod
+% Script that tests the twostep dictionary learning algorithm with MOCOD
+% dictionary update.
+%
+% REFERENCES
+% D. Barchiesi and M. D. Plumbely, Learning incoherenct dictionaries for 
+% sparse approximation using iterative projections and rotations.
+%% Clear and close
 clc, clear, close all
 
 %% Parameteres
-nTrials   = 10;										%number of trials of the experiment
+nTrials   = 10;					%number of trials of the experiment
 
 % Dictionary learning parameters
-toolbox   = 'TwoStepDL';							%dictionary learning toolbox
-dicUpdate = 'mocod';								%dictionary learning updates
-zeta	  = logspace(-2,2,10); 
-eta  	  = logspace(-2,2,10); 
-
-iterNum   = 20;				%number of iterations
-epsilon   = 1e-6;			%tolerance level
-dictSize  = 512;			%number of atoms in the dictionary
-percActiveAtoms = 5;		%percentage of active atoms
+toolbox   = 'TwoStepDL';		%dictionary learning toolbox
+dicUpdate = 'mocod';			%dictionary learning updates
+zeta	  = logspace(-2,2,10);	%range of values for the incoherence term				
+eta  	  = logspace(-2,2,10);	%range of values for the unit norm term
+iterNum   = 20;					%number of iterations
+epsilon   = 1e-6;				%tolerance level
+dictSize  = 512;				%number of atoms in the dictionary
+percActiveAtoms = 5;			%percentage of active atoms
 
 % Test signal parameters
 signal    = audio('music03_16kHz.wav'); %audio signal
@@ -25,23 +32,29 @@
 % Initial dictionaries
 gaborParam = struct('N',blockSize,'redundancyFactor',2,'wd',@rectwin);
 gaborDict = Gabor_Dictionary(gaborParam);
-initDicts = {[],gaborDict};
+initDicts = {[],gaborDict};				%cell containing initial dictionaries
 
 %% Generate audio approximation problem
-signal			 = buffer(signal,blockSize,blockSize*overlap,@rectwin);	%buffer frames of audio into columns of the matrix S
+%buffer frames of audio into columns of the matrix S
+signal			 = buffer(signal,blockSize,blockSize*overlap,@rectwin);	
 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)
 
-% omp2 sparse representation solver
-ompParam = struct('X',SMALL.Problem.b,'epsilon',epsilon,'maxatoms',nActiveAtoms); %parameters
+%copy signals from training set b to test set b1 (needed for later functions)
+SMALL.Problem.b1 = SMALL.Problem.b;
+
+%omp2 sparse representation solver
+ompParam = struct('X',SMALL.Problem.b,...
+				  'epsilon',epsilon,...
+				  'maxatoms',nActiveAtoms); %parameters
 solver	 = SMALL_init_solver('ompbox','omp2',ompParam,false); %solver structure
 
 %% Test
-nInitDicts  = length(initDicts);		%number of initial dictionaries
-nZetas = length(zeta);
-nEtas  = length(eta);
+nInitDicts  = length(initDicts);%number of initial dictionaries
+nZetas = length(zeta);			%number of incoherence penalty parameters
+nEtas  = length(eta);			%number of unit norm penalty parameters
 
-SMALL.DL(nTrials,nInitDicts,nZetas,nEtas) = SMALL_init_DL(toolbox); %create dictionary learning structures
+%create dictionary learning structures
+SMALL.DL(nTrials,nInitDicts,nZetas,nEtas) = SMALL_init_DL(toolbox); 
 for iTrial=1:nTrials
 	for iInitDicts=1:nInitDicts
 		for iZetas=1:nZetas
@@ -50,15 +63,16 @@
 				SMALL.DL(iTrial,iInitDicts,iZetas,iEtas).name = dicUpdate;
 				SMALL.DL(iTrial,iInitDicts,iZetas,iEtas).profile = true;
 				SMALL.DL(iTrial,iInitDicts,iZetas,iEtas).param = ...
-					struct('data',SMALL.Problem.b,...
-					'Tdata',nActiveAtoms,...
-					'dictsize',dictSize,...
-					'iternum',iterNum,...
-					'memusage','high',...
-					'solver',solver,...
-					'initdict',initDicts(iInitDicts),...
-					'zeta',zeta(iZetas),...
-					'eta',eta(iEtas));
+					struct('data',SMALL.Problem.b,...	%observed data
+					'Tdata',nActiveAtoms,...			%active atoms
+					'dictsize',dictSize,...				%number of atoms
+					'iternum',iterNum,...				%number of iterations
+					'memusage','high',...				%memory usage
+					'solver',solver,...					%sparse approx solver
+					'initdict',initDicts(iInitDicts),...%initial dictionary
+					'zeta',zeta(iZetas),...				%incoherence penalty factor
+					'eta',eta(iEtas));					%unit norm penalty factor
+				%learn dictionary
 				SMALL.DL(iTrial,iInitDicts,iZetas,iEtas) = ...
 					SMALL_learn(SMALL.Problem,SMALL.DL(iTrial,iInitDicts,iZetas,iEtas));
 			end
@@ -66,10 +80,10 @@
 	end
 end
 
-%% Evaluate coherence and snr of representation for the various methods
-sr = zeros(size(SMALL.DL));				%signal to noise ratio
+%% Evaluate coherence and snr of representation
+sr = zeros(size(SMALL.DL));					%signal to noise ratio
 mu = zeros(iTrial,iInitDicts,iZetas,iEtas);	%coherence
-dic(size(SMALL.DL)) = dictionary;		%initialise dictionary objects
+dic(size(SMALL.DL)) = dictionary;			%initialise dictionary objects
 for iTrial=1:nTrials
 	for iInitDicts=1:nInitDicts
 		for iZetas=1:nZetas
@@ -79,7 +93,8 @@
 				tempSolver = SMALL_solve(SMALL.Problem,solver);
 				%calculate snr
 				sr(iTrial,iInitDicts,iZetas,iEtas) = ...
-					snr(SMALL.Problem.b,SMALL.DL(iTrial,iInitDicts,iZetas,iEtas).D*tempSolver.solution);
+					snr(SMALL.Problem.b,...
+					SMALL.DL(iTrial,iInitDicts,iZetas,iEtas).D*tempSolver.solution);
 				%calculate mu
 				dic(iTrial,iInitDicts,iZetas,iEtas) = ...
 					dictionary(SMALL.DL(iTrial,iInitDicts,iZetas,iEtas).D);
@@ -90,18 +105,23 @@
 	end
 end
 
-save('MOCOD.mat')
-
 %% Plot results
-minMu = sqrt((dictSize-blockSize)/(blockSize*(dictSize-1)));	%lowe bound on coherence
-initDictsNames = {'Data','Gabor'};
-lineStyles     = {'k.-','r*-','b+-'};
+minMu = sqrt((dictSize-blockSize)/(blockSize*(dictSize-1)));%lower bound on coherence
+initDictsNames = {'Data','Gabor'};							%names of initial dictionaries
+lineStyles     = {'k.-','r*-','b+-'};						
 for iInitDict=1:nInitDicts
 	figure, hold on, grid on
-	title([initDictsNames{iInitDict} ' Initialisation']);
+	%print initial dictionary as figure title
+	DisplayFigureTitle([initDictsNames{iInitDict} ' Initialisation']);
+% 	set(gcf,'Units','Normalized');
+% 	txh = annotation(gcf,'textbox',[0.4,0.95,0.2,0.05]);
+% 	set(txh,'String',[initDictsNames{iInitDict} ' Initialisation'],...
+% 		'LineStyle','none','HorizontalAlignment','center');
+	%calculate mean coherence levels and SNRs over trials
 	coherenceLevels = squeeze(mean(mu(:,iInitDict,:,:),1));
 	meanSNRs		= squeeze(mean(sr(:,iInitDict,:,:),1));
-	%stdSNRs				= squeeze(std(sr(:,iInitDict,iZetas,iEtas),0,1));
+%	stdSNRs		= squeeze(std(sr(:,iInitDict,iZetas,iEtas),0,1));
+	%plot coherence levels
 	subplot(2,2,1)
 	surf(eta,zeta,coherenceLevels);
 	set(gca,'Xscale','log','Yscale','log','ZLim',[0 1.4]);
@@ -111,6 +131,7 @@
 	zlabel('\mu');
 	title('Coherence')
 	
+	%plot SNRs
 	subplot(2,2,2)
 	surf(eta,zeta,meanSNRs);
 	set(gca,'Xscale','log','Yscale','log','ZLim',[0 25]);
@@ -120,6 +141,7 @@
 	zlabel('SNR (dB)');
 	title('Reconstruction Error')
 	
+	%plot mu/SNR scatter
 	subplot(2,2,[3 4])
 	mus = mu(:,iInitDict,:,:);
 	mus = mus(:);