Mercurial > hg > smallbox
diff examples/Automatic Music Transcription/SMALL_AMT_DL_test.m @ 107:dab78a3598b6
changes to comments for couple of scripts
author | Ivan Damnjanovic lnx <ivan.damnjanovic@eecs.qmul.ac.uk> |
---|---|
date | Wed, 18 May 2011 11:50:12 +0100 |
parents | cbf3521c25eb |
children | 8e660fd14774 |
line wrap: on
line diff
--- a/examples/Automatic Music Transcription/SMALL_AMT_DL_test.m Tue Apr 05 17:03:26 2011 +0100 +++ b/examples/Automatic Music Transcription/SMALL_AMT_DL_test.m Wed May 18 11:50:12 2011 +0100 @@ -1,13 +1,4 @@ %% DICTIONARY LEARNING FOR AUTOMATIC MUSIC TRANSCRIPTION EXAMPLE 1 -% -% Centre for Digital Music, Queen Mary, University of London. -% This file copyright 2010 Ivan Damnjanovic. -% -% This program is free software; you can redistribute it and/or -% modify it under the terms of the GNU General Public License as -% published by the Free Software Foundation; either version 2 of the -% License, or (at your option) any later version. See the file -% COPYING included with this distribution for more information. % % This file contains an example of how SMALLbox can be used to test diferent % dictionary learning techniques in Automatic Music Transcription problem. @@ -18,7 +9,16 @@ % The function will generarte the Problem structure that is used to learn % Problem.p notes spectrograms from training set Problem.b using % dictionary learning technique defined in DL structure. + % +% Centre for Digital Music, Queen Mary, University of London. +% This file copyright 2010 Ivan Damnjanovic. +% +% This program is free software; you can redistribute it and/or +% modify it under the terms of the GNU General Public License as +% published by the Free Software Foundation; either version 2 of the +% License, or (at your option) any later version. See the file +% COPYING included with this distribution for more information. %% clear; @@ -45,13 +45,13 @@ SMALL.DL(1).name = 'ksvd'; % Defining the parameters for KSVD % In this example we are learning 88 atoms in 100 iterations, so that -% every frame in the training set can be represented with maximum 3 +% every frame in the training set can be represented with maximum Tdata % dictionary elements. Type help ksvd in MATLAB prompt for more options. SMALL.DL(1).param=struct(... - 'Tdata', 10,... + 'Tdata', 3,... 'dictsize', SMALL.Problem.p,... - 'iternum', 100); + 'iternum', 50); % Learn the dictionary @@ -110,82 +110,82 @@ %% -% % Here we solve the same problem using non-negative sparse coding with -% % SPAMS online dictionary learning (Julien Mairal 2009) -% % -% -% % Initialising Dictionary structure -% % Setting Dictionary structure fields (toolbox, name, param, D and time) -% % to zero values -% -% SMALL.DL(2)=SMALL_init_DL(); -% -% -% % Defining fields needed for dictionary learning -% -% SMALL.DL(2).toolbox = 'SPAMS'; -% SMALL.DL(2).name = 'mexTrainDL'; -% -% % Type 'help mexTrainDL in MATLAB prompt for explanation of parameters. -% -% SMALL.DL(2).param=struct(... -% 'K', SMALL.Problem.p,... -% 'lambda', 3,... -% 'iter', 300,... -% 'posAlpha', 1,... -% 'posD', 1,... -% 'whiten', 0,... -% 'mode', 2); -% -% % Learn the dictionary -% -% SMALL.DL(2) = SMALL_learn(SMALL.Problem, SMALL.DL(2)); -% -% % Set SMALL.Problem.A dictionary and reconstruction function -% % (backward compatiblity with SPARCO: solver structure communicate -% % only with Problem structure, ie no direct communication between DL and -% % solver structures) -% -% SMALL.Problem.A = SMALL.DL(2).D; -% SMALL.Problem.reconstruct=@(x) SMALL_midiGenerate(x, SMALL.Problem); -% -% %% -% % Initialising solver structure -% % Setting solver structure fields (toolbox, name, param, solution, -% % reconstructed and time) to zero values -% % As an example, SPAMS (Julien Mairal 2009) implementation of LARS -% % algorithm is used for representation of training set in the learned -% % dictionary. -% -% SMALL.solver(2)=SMALL_init_solver; -% -% % Defining the parameters needed for sparse representation -% -% SMALL.solver(2).toolbox='SPAMS'; -% SMALL.solver(2).name='mexLasso'; -% -% % Here we use mexLasso mode=2, with lambda=3, lambda2=0 and positivity -% % constrain (type 'help mexLasso' for more information about modes): -% % -% % min_{alpha_i} (1/2)||x_i-Dalpha_i||_2^2 + lambda||alpha_i||_1 + (1/2)lambda2||alpha_i||_2^2 -% -% SMALL.solver(2).param=struct('lambda', 3, 'pos', 1, 'mode', 2); -% -% % Call SMALL_soolve to represent the signal in the given dictionary. -% % As a final command SMALL_solve will call above defined reconstruction -% % function to reconstruct the training set (Problem.b) in the learned -% % dictionary (Problem.A) -% -% SMALL.solver(2)=SMALL_solve(SMALL.Problem, SMALL.solver(2)); -% -% %% -% % Analysis of the result of automatic music transcription. If groundtruth -% % exists, we can compare transcribed notes and original and get usual -% % True Positives, False Positives and False Negatives measures. -% -% if ~isempty(SMALL.Problem.notesOriginal) -% AMT_res(2) = AMT_analysis(SMALL.Problem, SMALL.solver(2)); -% end +% Here we solve the same problem using non-negative sparse coding with +% SPAMS online dictionary learning (Julien Mairal 2009) +% + +% Initialising Dictionary structure +% Setting Dictionary structure fields (toolbox, name, param, D and time) +% to zero values + +SMALL.DL(2)=SMALL_init_DL(); + + +% Defining fields needed for dictionary learning + +SMALL.DL(2).toolbox = 'SPAMS'; +SMALL.DL(2).name = 'mexTrainDL'; + +% Type 'help mexTrainDL in MATLAB prompt for explanation of parameters. + +SMALL.DL(2).param=struct(... + 'K', SMALL.Problem.p,... + 'lambda', 3,... + 'iter', 300,... + 'posAlpha', 1,... + 'posD', 1,... + 'whiten', 0,... + 'mode', 2); + +% Learn the dictionary + +SMALL.DL(2) = SMALL_learn(SMALL.Problem, SMALL.DL(2)); + +% Set SMALL.Problem.A dictionary and reconstruction function +% (backward compatiblity with SPARCO: solver structure communicate +% only with Problem structure, ie no direct communication between DL and +% solver structures) + +SMALL.Problem.A = SMALL.DL(2).D; +SMALL.Problem.reconstruct=@(x) SMALL_midiGenerate(x, SMALL.Problem); + +%% +% Initialising solver structure +% Setting solver structure fields (toolbox, name, param, solution, +% reconstructed and time) to zero values +% As an example, SPAMS (Julien Mairal 2009) implementation of LARS +% algorithm is used for representation of training set in the learned +% dictionary. + +SMALL.solver(2)=SMALL_init_solver; + +% Defining the parameters needed for sparse representation + +SMALL.solver(2).toolbox='SPAMS'; +SMALL.solver(2).name='mexLasso'; + +% Here we use mexLasso mode=2, with lambda=3, lambda2=0 and positivity +% constrain (type 'help mexLasso' for more information about modes): +% +% min_{alpha_i} (1/2)||x_i-Dalpha_i||_2^2 + lambda||alpha_i||_1 + (1/2)lambda2||alpha_i||_2^2 + +SMALL.solver(2).param=struct('lambda', 3, 'pos', 1, 'mode', 2); + +% Call SMALL_soolve to represent the signal in the given dictionary. +% As a final command SMALL_solve will call above defined reconstruction +% function to reconstruct the training set (Problem.b) in the learned +% dictionary (Problem.A) + +SMALL.solver(2)=SMALL_solve(SMALL.Problem, SMALL.solver(2)); + +%% +% Analysis of the result of automatic music transcription. If groundtruth +% exists, we can compare transcribed notes and original and get usual +% True Positives, False Positives and False Negatives measures. + +if ~isempty(SMALL.Problem.notesOriginal) + AMT_res(2) = AMT_analysis(SMALL.Problem, SMALL.solver(2)); +end %% % Plot results and save midi files