comparison examples/Automatic Music Transcription/SMALL_AMT_KSVD_Err_test.m @ 6:f72603404233

(none)
author idamnjanovic
date Mon, 22 Mar 2010 10:45:01 +0000
parents
children cbf3521c25eb
comparison
equal deleted inserted replaced
5:f44689e95ea4 6:f72603404233
1 %% DICTIONARY LEARNING FOR AUTOMATIC MUSIC TRANSCRIPTION
2 % This file contains an example of how SMALLbox can be used to test diferent
3 % dictionary learning techniques in Automatic Music Transcription problem.
4 % 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
6 % converted to wave and original midi file will be used for comparison with
7 % results of dictionary learning and reconstruction.
8 % The function will generarte the Problem structure that is used to learn
9 % Problem.p notes spectrograms from training set Problem.b using
10 % dictionary learning technique defined in DL structure.
11 %
12 % Ivan Damnjanovic 2010
13 %%
14
15 clear;
16
17
18 % Defining Automatic Transcription of Piano tune as Dictionary Learning
19 % Problem
20
21 SMALL.Problem = generateAMT_Learning_Problem();
22 TPmax=0;
23 for i=1:5
24 %%
25 % Use KSVD Dictionary Learning Algorithm to Learn 88 notes (defined in
26 % SMALL.Problem.p) using sparsity constrain only
27
28 % Initialising Dictionary structure
29 % Setting Dictionary structure fields (toolbox, name, param, D and time)
30 % to zero values
31
32 SMALL.DL(i)=SMALL_init_DL(i);
33
34 % Defining the parameters needed for dictionary learning
35
36 SMALL.DL(i).toolbox = 'KSVD';
37 SMALL.DL(i).name = 'ksvd';
38
39 % Defining the parameters for KSVD
40 % In this example we are learning 88 atoms in 100 iterations, so that
41 % every frame in the training set can be represented with maximum 10
42 % dictionary elements. However, our aim here is to show how individual
43 % parameters can be ested in the AMT problem. We test five different
44 % values for residual error (Edata) in KSVD algorithm.
45 % Type help ksvd in MATLAB prompt for more options.
46
47 Edata(i)=8+i*2;
48 SMALL.DL(i).param=struct(...
49 'Edata', Edata(i),...
50 'dictsize', SMALL.Problem.p,...
51 'iternum', 100,...
52 'maxatoms', 10);
53
54 % Learn the dictionary
55
56 SMALL.DL(i) = SMALL_learn(SMALL.Problem, SMALL.DL(i));
57
58 % Set SMALL.Problem.A dictionary and reconstruction function
59 % (backward compatiblity with SPARCO: solver structure communicate
60 % only with Problem structure, ie no direct communication between DL and
61 % solver structures)
62
63 SMALL.Problem.A = SMALL.DL(i).D;
64 SMALL.Problem.reconstruct = @(x) SMALL_midiGenerate(x, SMALL.Problem);
65
66 %%
67 % Initialising solver structure
68 % Setting solver structure fields (toolbox, name, param, solution,
69 % reconstructed and time) to zero values
70 % As an example, SPAMS (Julien Mairal 2009) implementation of LARS
71 % algorithm is used for representation of training set in the learned
72 % dictionary.
73
74 SMALL.solver(1)=SMALL_init_solver;
75
76 % Defining the parameters needed for sparse representation
77
78 SMALL.solver(1).toolbox='SPAMS';
79 SMALL.solver(1).name='mexLasso';
80 SMALL.solver(1).param=struct('lambda', 2, 'pos', 1, 'mode', 2);
81
82 %Represent Training set in the learned dictionary
83
84 SMALL.solver(1)=SMALL_solve(SMALL.Problem, SMALL.solver(1));
85
86 %%
87 % Analysis of the result of automatic music transcription. If groundtruth
88 % exists, we can compare transcribed notes and original and get usual
89 % True Positives, False Positives and False Negatives measures.
90
91 AMT_res(i) = AMT_analysis(SMALL.Problem, SMALL.solver(1));
92
93 if AMT_res(i).TP>TPmax
94 TPmax=AMT_res(i).TP;
95 BLmidi=SMALL.solver(1).reconstructed.midi;
96 max=i;
97 end
98
99 end %end of for loop
100
101 %%
102 % Plot results and save midi files
103
104 figAMTbest=SMALL_AMT_plot(SMALL, AMT_res(max));
105
106 resFig=figure('Name', 'Automatic Music Transcription KSVD Error TEST');
107
108 subplot (3,1,1); plot(Edata(:), [AMT_res(:).TP], 'ro-');
109 title('True Positives vs Edata');
110
111 subplot (3,1,2); plot(Edata(:), [AMT_res(:).FN], 'ro-');
112 title('False Negatives vs Edata');
113
114 subplot (3,1,3); plot(Edata(:), [AMT_res(:).FP], 'ro-');
115 title('False Positives vs Edata');
116
117 FS=filesep;
118 [pathstr1, name, ext, versn] = fileparts(which('SMALLboxSetup.m'));
119 cd([pathstr1,FS,'results']);
120 [filename,pathname] = uiputfile({' *.mid;' },'Save midi');
121 if filename~=0 writemidi(BLmidi, [pathname,FS,filename]);end
122 [filename,pathname] = uiputfile({' *.fig;' },'Save figure TP/FN/FP vs lambda');
123 if filename~=0 saveas(resFig, [pathname,FS,filename]);end
124
125 [filename,pathname] = uiputfile({' *.fig;' },'Save BEST AMT figure');
126 if filename~=0 saveas(figAMTbest, [pathname,FS,filename]);end
127