comparison 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
comparison
equal deleted inserted replaced
85:fd1c32cda22c 107:dab78a3598b6
1 %% DICTIONARY LEARNING FOR AUTOMATIC MUSIC TRANSCRIPTION EXAMPLE 1 1 %% DICTIONARY LEARNING FOR AUTOMATIC MUSIC TRANSCRIPTION EXAMPLE 1
2 %
3 % Centre for Digital Music, Queen Mary, University of London.
4 % This file copyright 2010 Ivan Damnjanovic.
5 %
6 % This program is free software; you can redistribute it and/or
7 % modify it under the terms of the GNU General Public License as
8 % published by the Free Software Foundation; either version 2 of the
9 % License, or (at your option) any later version. See the file
10 % COPYING included with this distribution for more information.
11 % 2 %
12 % This file contains an example of how SMALLbox can be used to test diferent 3 % This file contains an example of how SMALLbox can be used to test diferent
13 % dictionary learning techniques in Automatic Music Transcription problem. 4 % dictionary learning techniques in Automatic Music Transcription problem.
14 % It calls generateAMT_Learning_Problem that will let you to choose midi, 5 % It calls generateAMT_Learning_Problem that will let you to choose midi,
15 % wave or mat file to be transcribe. If file is midi it will be first 6 % wave or mat file to be transcribe. If file is midi it will be first
16 % converted to wave and original midi file will be used for comparison with 7 % converted to wave and original midi file will be used for comparison with
17 % results of dictionary learning and reconstruction. 8 % results of dictionary learning and reconstruction.
18 % The function will generarte the Problem structure that is used to learn 9 % The function will generarte the Problem structure that is used to learn
19 % Problem.p notes spectrograms from training set Problem.b using 10 % Problem.p notes spectrograms from training set Problem.b using
20 % dictionary learning technique defined in DL structure. 11 % dictionary learning technique defined in DL structure.
12
21 % 13 %
14 % Centre for Digital Music, Queen Mary, University of London.
15 % This file copyright 2010 Ivan Damnjanovic.
16 %
17 % This program is free software; you can redistribute it and/or
18 % modify it under the terms of the GNU General Public License as
19 % published by the Free Software Foundation; either version 2 of the
20 % License, or (at your option) any later version. See the file
21 % COPYING included with this distribution for more information.
22 %% 22 %%
23 23
24 clear; 24 clear;
25 25
26 26
43 43
44 SMALL.DL(1).toolbox = 'KSVD'; 44 SMALL.DL(1).toolbox = 'KSVD';
45 SMALL.DL(1).name = 'ksvd'; 45 SMALL.DL(1).name = 'ksvd';
46 % Defining the parameters for KSVD 46 % Defining the parameters for KSVD
47 % In this example we are learning 88 atoms in 100 iterations, so that 47 % In this example we are learning 88 atoms in 100 iterations, so that
48 % every frame in the training set can be represented with maximum 3 48 % every frame in the training set can be represented with maximum Tdata
49 % dictionary elements. Type help ksvd in MATLAB prompt for more options. 49 % dictionary elements. Type help ksvd in MATLAB prompt for more options.
50 50
51 SMALL.DL(1).param=struct(... 51 SMALL.DL(1).param=struct(...
52 'Tdata', 10,... 52 'Tdata', 3,...
53 'dictsize', SMALL.Problem.p,... 53 'dictsize', SMALL.Problem.p,...
54 'iternum', 100); 54 'iternum', 50);
55 55
56 % Learn the dictionary 56 % Learn the dictionary
57 57
58 SMALL.DL(1) = SMALL_learn(SMALL.Problem, SMALL.DL(1)); 58 SMALL.DL(1) = SMALL_learn(SMALL.Problem, SMALL.DL(1));
59 59
108 end 108 end
109 109
110 110
111 %% 111 %%
112 112
113 % % Here we solve the same problem using non-negative sparse coding with 113 % Here we solve the same problem using non-negative sparse coding with
114 % % SPAMS online dictionary learning (Julien Mairal 2009) 114 % SPAMS online dictionary learning (Julien Mairal 2009)
115 % % 115 %
116 % 116
117 % % Initialising Dictionary structure 117 % Initialising Dictionary structure
118 % % Setting Dictionary structure fields (toolbox, name, param, D and time) 118 % Setting Dictionary structure fields (toolbox, name, param, D and time)
119 % % to zero values 119 % to zero values
120 % 120
121 % SMALL.DL(2)=SMALL_init_DL(); 121 SMALL.DL(2)=SMALL_init_DL();
122 % 122
123 % 123
124 % % Defining fields needed for dictionary learning 124 % Defining fields needed for dictionary learning
125 % 125
126 % SMALL.DL(2).toolbox = 'SPAMS'; 126 SMALL.DL(2).toolbox = 'SPAMS';
127 % SMALL.DL(2).name = 'mexTrainDL'; 127 SMALL.DL(2).name = 'mexTrainDL';
128 % 128
129 % % Type 'help mexTrainDL in MATLAB prompt for explanation of parameters. 129 % Type 'help mexTrainDL in MATLAB prompt for explanation of parameters.
130 % 130
131 % SMALL.DL(2).param=struct(... 131 SMALL.DL(2).param=struct(...
132 % 'K', SMALL.Problem.p,... 132 'K', SMALL.Problem.p,...
133 % 'lambda', 3,... 133 'lambda', 3,...
134 % 'iter', 300,... 134 'iter', 300,...
135 % 'posAlpha', 1,... 135 'posAlpha', 1,...
136 % 'posD', 1,... 136 'posD', 1,...
137 % 'whiten', 0,... 137 'whiten', 0,...
138 % 'mode', 2); 138 'mode', 2);
139 % 139
140 % % Learn the dictionary 140 % Learn the dictionary
141 % 141
142 % SMALL.DL(2) = SMALL_learn(SMALL.Problem, SMALL.DL(2)); 142 SMALL.DL(2) = SMALL_learn(SMALL.Problem, SMALL.DL(2));
143 % 143
144 % % Set SMALL.Problem.A dictionary and reconstruction function 144 % Set SMALL.Problem.A dictionary and reconstruction function
145 % % (backward compatiblity with SPARCO: solver structure communicate 145 % (backward compatiblity with SPARCO: solver structure communicate
146 % % only with Problem structure, ie no direct communication between DL and 146 % only with Problem structure, ie no direct communication between DL and
147 % % solver structures) 147 % solver structures)
148 % 148
149 % SMALL.Problem.A = SMALL.DL(2).D; 149 SMALL.Problem.A = SMALL.DL(2).D;
150 % SMALL.Problem.reconstruct=@(x) SMALL_midiGenerate(x, SMALL.Problem); 150 SMALL.Problem.reconstruct=@(x) SMALL_midiGenerate(x, SMALL.Problem);
151 % 151
152 % %% 152 %%
153 % % Initialising solver structure 153 % Initialising solver structure
154 % % Setting solver structure fields (toolbox, name, param, solution, 154 % Setting solver structure fields (toolbox, name, param, solution,
155 % % reconstructed and time) to zero values 155 % reconstructed and time) to zero values
156 % % As an example, SPAMS (Julien Mairal 2009) implementation of LARS 156 % As an example, SPAMS (Julien Mairal 2009) implementation of LARS
157 % % algorithm is used for representation of training set in the learned 157 % algorithm is used for representation of training set in the learned
158 % % dictionary. 158 % dictionary.
159 % 159
160 % SMALL.solver(2)=SMALL_init_solver; 160 SMALL.solver(2)=SMALL_init_solver;
161 % 161
162 % % Defining the parameters needed for sparse representation 162 % Defining the parameters needed for sparse representation
163 % 163
164 % SMALL.solver(2).toolbox='SPAMS'; 164 SMALL.solver(2).toolbox='SPAMS';
165 % SMALL.solver(2).name='mexLasso'; 165 SMALL.solver(2).name='mexLasso';
166 % 166
167 % % Here we use mexLasso mode=2, with lambda=3, lambda2=0 and positivity 167 % Here we use mexLasso mode=2, with lambda=3, lambda2=0 and positivity
168 % % constrain (type 'help mexLasso' for more information about modes): 168 % constrain (type 'help mexLasso' for more information about modes):
169 % % 169 %
170 % % min_{alpha_i} (1/2)||x_i-Dalpha_i||_2^2 + lambda||alpha_i||_1 + (1/2)lambda2||alpha_i||_2^2 170 % min_{alpha_i} (1/2)||x_i-Dalpha_i||_2^2 + lambda||alpha_i||_1 + (1/2)lambda2||alpha_i||_2^2
171 % 171
172 % SMALL.solver(2).param=struct('lambda', 3, 'pos', 1, 'mode', 2); 172 SMALL.solver(2).param=struct('lambda', 3, 'pos', 1, 'mode', 2);
173 % 173
174 % % Call SMALL_soolve to represent the signal in the given dictionary. 174 % Call SMALL_soolve to represent the signal in the given dictionary.
175 % % As a final command SMALL_solve will call above defined reconstruction 175 % As a final command SMALL_solve will call above defined reconstruction
176 % % function to reconstruct the training set (Problem.b) in the learned 176 % function to reconstruct the training set (Problem.b) in the learned
177 % % dictionary (Problem.A) 177 % dictionary (Problem.A)
178 % 178
179 % SMALL.solver(2)=SMALL_solve(SMALL.Problem, SMALL.solver(2)); 179 SMALL.solver(2)=SMALL_solve(SMALL.Problem, SMALL.solver(2));
180 % 180
181 % %% 181 %%
182 % % Analysis of the result of automatic music transcription. If groundtruth 182 % Analysis of the result of automatic music transcription. If groundtruth
183 % % exists, we can compare transcribed notes and original and get usual 183 % exists, we can compare transcribed notes and original and get usual
184 % % True Positives, False Positives and False Negatives measures. 184 % True Positives, False Positives and False Negatives measures.
185 % 185
186 % if ~isempty(SMALL.Problem.notesOriginal) 186 if ~isempty(SMALL.Problem.notesOriginal)
187 % AMT_res(2) = AMT_analysis(SMALL.Problem, SMALL.solver(2)); 187 AMT_res(2) = AMT_analysis(SMALL.Problem, SMALL.solver(2));
188 % end 188 end
189 189
190 %% 190 %%
191 % Plot results and save midi files 191 % Plot results and save midi files
192 192
193 if ~isempty(SMALL.Problem.notesOriginal) 193 if ~isempty(SMALL.Problem.notesOriginal)