Mercurial > hg > smallbox
comparison examples/Automatic Music Transcription/SMALL_AMT_DL_test.m @ 25:cbf3521c25eb
(none)
author | idamnjanovic |
---|---|
date | Tue, 27 Apr 2010 13:33:13 +0000 |
parents | f72603404233 |
children | dab78a3598b6 |
comparison
equal
deleted
inserted
replaced
24:fc395272d53e | 25:cbf3521c25eb |
---|---|
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 % This file contains an example of how SMALLbox can be used to test diferent | 12 % This file contains an example of how SMALLbox can be used to test diferent |
3 % dictionary learning techniques in Automatic Music Transcription problem. | 13 % dictionary learning techniques in Automatic Music Transcription problem. |
4 % It calls generateAMT_Learning_Problem that will let you to choose midi, | 14 % It calls generateAMT_Learning_Problem that will let you to choose midi, |
5 % wave or mat file to be transcribe. If file is midi it will be first | 15 % wave or mat file to be transcribe. If file is midi it will be first |
6 % converted to wave and original midi file will be used for comparison with | 16 % converted to wave and original midi file will be used for comparison with |
7 % results of dictionary learning and reconstruction. | 17 % results of dictionary learning and reconstruction. |
8 % The function will generarte the Problem structure that is used to learn | 18 % The function will generarte the Problem structure that is used to learn |
9 % Problem.p notes spectrograms from training set Problem.b using | 19 % Problem.p notes spectrograms from training set Problem.b using |
10 % dictionary learning technique defined in DL structure. | 20 % dictionary learning technique defined in DL structure. |
11 % | 21 % |
12 % Ivan Damnjanovic 2010 | |
13 %% | 22 %% |
14 | 23 |
15 clear; | 24 clear; |
16 | 25 |
17 | 26 |
38 % 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 |
39 % every frame in the training set can be represented with maximum 3 | 48 % every frame in the training set can be represented with maximum 3 |
40 % dictionary elements. Type help ksvd in MATLAB prompt for more options. | 49 % dictionary elements. Type help ksvd in MATLAB prompt for more options. |
41 | 50 |
42 SMALL.DL(1).param=struct(... | 51 SMALL.DL(1).param=struct(... |
43 'Tdata', 3,... | 52 'Tdata', 10,... |
44 'dictsize', SMALL.Problem.p,... | 53 'dictsize', SMALL.Problem.p,... |
45 'iternum', 100); | 54 'iternum', 100); |
46 | 55 |
47 % Learn the dictionary | 56 % Learn the dictionary |
48 | 57 |
66 | 75 |
67 SMALL.solver(1)=SMALL_init_solver; | 76 SMALL.solver(1)=SMALL_init_solver; |
68 | 77 |
69 % Defining the parameters needed for sparse representation | 78 % Defining the parameters needed for sparse representation |
70 | 79 |
71 SMALL.solver(1).toolbox='SPAMS'; | 80 SMALL.solver(1).toolbox='SMALL'; |
72 SMALL.solver(1).name='mexLasso'; | 81 SMALL.solver(1).name='SMALL_cgp'; |
73 | 82 |
74 % Here we use mexLasso mode=2, with lambda=2, lambda2=0 and positivity | 83 % Here we use mexLasso mode=2, with lambda=2, lambda2=0 and positivity |
75 % constrain (type 'help mexLasso' for more information about modes): | 84 % constrain (type 'help mexLasso' for more information about modes): |
76 % | 85 % |
77 % min_{alpha_i} (1/2)||x_i-Dalpha_i||_2^2 + lambda||alpha_i||_1 + (1/2)lambda2||alpha_i||_2^2 | 86 % min_{alpha_i} (1/2)||x_i-Dalpha_i||_2^2 + lambda||alpha_i||_1 + (1/2)lambda2||alpha_i||_2^2 |
78 | 87 |
79 SMALL.solver(1).param=struct(... | 88 SMALL.solver(1).param='20, 1e-2'; |
80 'lambda', 2,... | 89 % struct(... |
81 'pos', 1,... | 90 % 'lambda', 2,... |
82 'mode', 2); | 91 % 'pos', 1,... |
92 % 'mode', 2); | |
83 | 93 |
84 % Call SMALL_soolve to represent the signal in the given dictionary. | 94 % Call SMALL_soolve to represent the signal in the given dictionary. |
85 % As a final command SMALL_solve will call above defined reconstruction | 95 % As a final command SMALL_solve will call above defined reconstruction |
86 % function to reconstruct the training set (Problem.b) in the learned | 96 % function to reconstruct the training set (Problem.b) in the learned |
87 % dictionary (Problem.A) | 97 % dictionary (Problem.A) |
97 AMT_res(1) = AMT_analysis(SMALL.Problem, SMALL.solver(1)); | 107 AMT_res(1) = AMT_analysis(SMALL.Problem, SMALL.solver(1)); |
98 end | 108 end |
99 | 109 |
100 | 110 |
101 %% | 111 %% |
102 % Here we solve the same problem using non-negative sparse coding with | 112 |
103 % SPAMS online dictionary learning (Julien Mairal 2009) | 113 % % Here we solve the same problem using non-negative sparse coding with |
104 % | 114 % % SPAMS online dictionary learning (Julien Mairal 2009) |
105 | 115 % % |
106 % Initialising Dictionary structure | 116 % |
107 % Setting Dictionary structure fields (toolbox, name, param, D and time) | 117 % % Initialising Dictionary structure |
108 % to zero values | 118 % % Setting Dictionary structure fields (toolbox, name, param, D and time) |
109 | 119 % % to zero values |
110 SMALL.DL(2)=SMALL_init_DL(); | 120 % |
111 | 121 % SMALL.DL(2)=SMALL_init_DL(); |
112 | 122 % |
113 % Defining fields needed for dictionary learning | 123 % |
114 | 124 % % Defining fields needed for dictionary learning |
115 SMALL.DL(2).toolbox = 'SPAMS'; | 125 % |
116 SMALL.DL(2).name = 'mexTrainDL'; | 126 % SMALL.DL(2).toolbox = 'SPAMS'; |
117 | 127 % SMALL.DL(2).name = 'mexTrainDL'; |
118 % Type 'help mexTrainDL in MATLAB prompt for explanation of parameters. | 128 % |
119 | 129 % % Type 'help mexTrainDL in MATLAB prompt for explanation of parameters. |
120 SMALL.DL(2).param=struct(... | 130 % |
121 'K', SMALL.Problem.p,... | 131 % SMALL.DL(2).param=struct(... |
122 'lambda', 3,... | 132 % 'K', SMALL.Problem.p,... |
123 'iter', 300,... | 133 % 'lambda', 3,... |
124 'posAlpha', 1,... | 134 % 'iter', 300,... |
125 'posD', 1,... | 135 % 'posAlpha', 1,... |
126 'whiten', 0,... | 136 % 'posD', 1,... |
127 'mode', 2); | 137 % 'whiten', 0,... |
128 | 138 % 'mode', 2); |
129 % Learn the dictionary | 139 % |
130 | 140 % % Learn the dictionary |
131 SMALL.DL(2) = SMALL_learn(SMALL.Problem, SMALL.DL(2)); | 141 % |
132 | 142 % SMALL.DL(2) = SMALL_learn(SMALL.Problem, SMALL.DL(2)); |
133 % Set SMALL.Problem.A dictionary and reconstruction function | 143 % |
134 % (backward compatiblity with SPARCO: solver structure communicate | 144 % % Set SMALL.Problem.A dictionary and reconstruction function |
135 % only with Problem structure, ie no direct communication between DL and | 145 % % (backward compatiblity with SPARCO: solver structure communicate |
136 % solver structures) | 146 % % only with Problem structure, ie no direct communication between DL and |
137 | 147 % % solver structures) |
138 SMALL.Problem.A = SMALL.DL(2).D; | 148 % |
139 SMALL.Problem.reconstruct=@(x) SMALL_midiGenerate(x, SMALL.Problem); | 149 % SMALL.Problem.A = SMALL.DL(2).D; |
140 | 150 % SMALL.Problem.reconstruct=@(x) SMALL_midiGenerate(x, SMALL.Problem); |
141 %% | 151 % |
142 % Initialising solver structure | 152 % %% |
143 % Setting solver structure fields (toolbox, name, param, solution, | 153 % % Initialising solver structure |
144 % reconstructed and time) to zero values | 154 % % Setting solver structure fields (toolbox, name, param, solution, |
145 % As an example, SPAMS (Julien Mairal 2009) implementation of LARS | 155 % % reconstructed and time) to zero values |
146 % algorithm is used for representation of training set in the learned | 156 % % As an example, SPAMS (Julien Mairal 2009) implementation of LARS |
147 % dictionary. | 157 % % algorithm is used for representation of training set in the learned |
148 | 158 % % dictionary. |
149 SMALL.solver(2)=SMALL_init_solver; | 159 % |
150 | 160 % SMALL.solver(2)=SMALL_init_solver; |
151 % Defining the parameters needed for sparse representation | 161 % |
152 | 162 % % Defining the parameters needed for sparse representation |
153 SMALL.solver(2).toolbox='SPAMS'; | 163 % |
154 SMALL.solver(2).name='mexLasso'; | 164 % SMALL.solver(2).toolbox='SPAMS'; |
155 | 165 % SMALL.solver(2).name='mexLasso'; |
156 % Here we use mexLasso mode=2, with lambda=3, lambda2=0 and positivity | 166 % |
157 % constrain (type 'help mexLasso' for more information about modes): | 167 % % Here we use mexLasso mode=2, with lambda=3, lambda2=0 and positivity |
158 % | 168 % % constrain (type 'help mexLasso' for more information about modes): |
159 % min_{alpha_i} (1/2)||x_i-Dalpha_i||_2^2 + lambda||alpha_i||_1 + (1/2)lambda2||alpha_i||_2^2 | 169 % % |
160 | 170 % % min_{alpha_i} (1/2)||x_i-Dalpha_i||_2^2 + lambda||alpha_i||_1 + (1/2)lambda2||alpha_i||_2^2 |
161 SMALL.solver(2).param=struct('lambda', 3, 'pos', 1, 'mode', 2); | 171 % |
162 | 172 % SMALL.solver(2).param=struct('lambda', 3, 'pos', 1, 'mode', 2); |
163 % Call SMALL_soolve to represent the signal in the given dictionary. | 173 % |
164 % As a final command SMALL_solve will call above defined reconstruction | 174 % % Call SMALL_soolve to represent the signal in the given dictionary. |
165 % function to reconstruct the training set (Problem.b) in the learned | 175 % % As a final command SMALL_solve will call above defined reconstruction |
166 % dictionary (Problem.A) | 176 % % function to reconstruct the training set (Problem.b) in the learned |
167 | 177 % % dictionary (Problem.A) |
168 SMALL.solver(2)=SMALL_solve(SMALL.Problem, SMALL.solver(2)); | 178 % |
169 | 179 % SMALL.solver(2)=SMALL_solve(SMALL.Problem, SMALL.solver(2)); |
170 %% | 180 % |
171 % Analysis of the result of automatic music transcription. If groundtruth | 181 % %% |
172 % exists, we can compare transcribed notes and original and get usual | 182 % % Analysis of the result of automatic music transcription. If groundtruth |
173 % True Positives, False Positives and False Negatives measures. | 183 % % exists, we can compare transcribed notes and original and get usual |
174 | 184 % % True Positives, False Positives and False Negatives measures. |
175 if ~isempty(SMALL.Problem.notesOriginal) | 185 % |
176 AMT_res(2) = AMT_analysis(SMALL.Problem, SMALL.solver(2)); | 186 % if ~isempty(SMALL.Problem.notesOriginal) |
177 end | 187 % AMT_res(2) = AMT_analysis(SMALL.Problem, SMALL.solver(2)); |
188 % end | |
178 | 189 |
179 %% | 190 %% |
180 % Plot results and save midi files | 191 % Plot results and save midi files |
181 | 192 |
182 if ~isempty(SMALL.Problem.notesOriginal) | 193 if ~isempty(SMALL.Problem.notesOriginal) |