annotate examples/MajorizationMinimization tests/SMALL_AudioDenoise_DL_test_KSVDvsSPAMS.m @ 199:751fa3bddd30 luisf_dev

Added config file for SMALL_solve (removed the if/else code from SMALL_solve); added headers to both config files;
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Tue, 20 Mar 2012 14:28:51 +0000
parents f42aa8bcb82f
children 4337e28183f1
rev   line source
ivan@161 1 %% DICTIONARY LEARNING FOR AUDIO DENOISING
ivan@161 2 % This file contains an example of how SMALLbox can be used to test different
ivan@161 3 % dictionary learning techniques in Audio Denoising problem.
ivan@161 4 % It calls generateAudioDenoiseProblem that will let you to choose audio file,
ivan@161 5 % add noise and use noisy audio to generate training set for dictionary
ivan@161 6 % learning.
ivan@161 7 %
ivan@161 8 %
ivan@161 9 % Centre for Digital Music, Queen Mary, University of London.
ivan@161 10 % This file copyright 2011 Ivan Damnjanovic.
ivan@161 11 %
ivan@161 12 % This program is free software; you can redistribute it and/or
ivan@161 13 % modify it under the terms of the GNU General Public License as
ivan@161 14 % published by the Free Software Foundation; either version 2 of the
ivan@161 15 % License, or (at your option) any later version. See the file
ivan@161 16 % COPYING included with this distribution for more information.
ivan@161 17 %
ivan@161 18 %%
ivan@161 19
ivan@161 20 clear;
ivan@161 21
ivan@161 22 % Defining Audio Denoising Problem as Dictionary Learning
ivan@161 23 % Problem
ivan@161 24
ivan@161 25 SMALL.Problem = generateAudioDenoiseProblem('male01_8kHz',0.1,512,1/128,'','','',4);
ivan@161 26
ivan@161 27 %%
ivan@161 28 % Initialising solver structure
ivan@161 29 % Setting solver structure fields (toolbox, name, param, solution,
ivan@161 30 % reconstructed and time) to zero values
ivan@161 31
ivan@161 32 SMALL.solver(1)=SMALL_init_solver('MMbox', 'mm1', '', 1);
ivan@161 33
ivan@161 34 % Defining the parameters needed for image denoising
ivan@161 35
ivan@161 36 SMALL.solver(1).param=struct(...
ivan@161 37 'lambda', 0.2,...
ivan@161 38 'epsilon', 3*10^-4,...
ivan@161 39 'iternum',10);
ivan@161 40
ivan@161 41 % Initialising Dictionary structure
ivan@161 42 % Setting Dictionary structure fields (toolbox, name, param, D and time)
ivan@161 43 % to zero values
ivan@161 44
ivan@161 45 SMALL.DL(1)=SMALL_init_DL('MMbox', 'MM_cn', '', 1);
ivan@161 46
ivan@161 47
ivan@161 48 % Defining the parameters for MOD
ivan@161 49 % In this example we are learning 256 atoms in 20 iterations, so that
ivan@161 50 % every patch in the training set can be represented with target error in
ivan@161 51 % L2-norm (EData)
ivan@161 52 % Type help ksvd in MATLAB prompt for more options.
ivan@161 53
ivan@161 54
ivan@161 55 SMALL.DL(1).param=struct(...
ivan@161 56 'solver', SMALL.solver(1),...
ivan@161 57 'initdict', SMALL.Problem.initdict,...
ivan@161 58 'dictsize', SMALL.Problem.p,...
ivan@161 59 'iternum', 20,...
ivan@161 60 'iterDictUpdate', 10,...
ivan@161 61 'epsDictUpdate', 10^-7,...
ivan@161 62 'cvset',0,...
ivan@161 63 'show_dict', 0);
ivan@161 64
ivan@161 65 % Learn the dictionary
ivan@161 66
ivan@161 67 SMALL.DL(1) = SMALL_learn(SMALL.Problem, SMALL.DL(1));
ivan@161 68
ivan@161 69 % Set SMALL.Problem.A dictionary
ivan@161 70 % (backward compatiblity with SPARCO: solver structure communicate
ivan@161 71 % only with Problem structure, ie no direct communication between DL and
ivan@161 72 % solver structures)
ivan@161 73
ivan@161 74 SMALL.Problem.A = SMALL.DL(1).D;
ivan@161 75 SMALL.Problem.reconstruct = @(x) AudioDenoise_reconstruct(x, SMALL.Problem);
ivan@161 76 % Denoising the image - find the sparse solution in the learned
ivan@161 77 % dictionary for all patches in the image and the end it uses
ivan@161 78 % reconstruction function to reconstruct the patches and put them into a
ivan@161 79 % denoised image
ivan@161 80
ivan@161 81 SMALL.solver(1)=SMALL_solve(SMALL.Problem, SMALL.solver(1));
ivan@161 82
ivan@161 83 %%
ivan@161 84 %%
ivan@161 85 % % sparse coding using SPAMS online dictionary learning
ivan@161 86 %
ivan@161 87
ivan@161 88 SMALL.DL(2)=SMALL_init_DL();
ivan@161 89 SMALL.DL(2).toolbox = 'SPAMS';
ivan@161 90 SMALL.DL(2).name = 'mexTrainDL';
ivan@161 91 SMALL.DL(2).param=struct('D', SMALL.Problem.initdict, 'K', SMALL.Problem.p, 'lambda', 0.2, 'iter', 200, 'mode', 3, 'modeD', 0);
ivan@161 92
ivan@161 93
ivan@161 94 SMALL.DL(2) = SMALL_learn(SMALL.Problem, SMALL.DL(2));
ivan@161 95
ivan@161 96 % Defining Reconstruction function
ivan@161 97
ivan@161 98 SMALL.Problem.A = SMALL.DL(2).D;
ivan@161 99
ivan@161 100
ivan@161 101 %%
ivan@161 102 % Initialising solver structure
ivan@161 103 % Setting toolbox, name, param, solution, reconstructed and time to zero values
ivan@161 104
ivan@161 105 SMALL.solver(2)=SMALL_init_solver;
ivan@161 106
ivan@161 107 % Defining the parameters needed for sparse representation
ivan@161 108
ivan@161 109 SMALL.solver(2).toolbox='ompbox';
ivan@161 110 SMALL.solver(2).name='omp2';
ivan@161 111 SMALL.solver(2).param=struct(...
ivan@161 112 'epsilon',0.2,...
ivan@161 113 'maxatoms', 128);
ivan@161 114 % Represent Training set in the learned dictionary
ivan@161 115
ivan@161 116 SMALL.solver(2)=SMALL_solve(SMALL.Problem, SMALL.solver(2));
ivan@161 117
ivan@161 118
ivan@161 119
ivan@161 120
ivan@161 121 %%
ivan@161 122 % Plot results and save midi files
ivan@161 123
ivan@161 124 % show results %
ivan@161 125
ivan@161 126
ivan@161 127 SMALL_AudioDeNoiseResult(SMALL);
ivan@161 128