comparison examples/Automatic Music Transcription/SMALL_AMT_KSVD_Sparsity_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 EXAMPLE 1
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
23 TPmax=0;
24
25 for i=1:10
26
27 %%
28 % Use KSVD Dictionary Learning Algorithm to Learn 88 notes (defined in
29 % SMALL.Problem.p) using sparsity constrain only
30
31 % Initialising Dictionary structure
32 % Setting Dictionary structure fields (toolbox, name, param, D and time)
33 % to zero values
34
35 SMALL.DL(i)=SMALL_init_DL(i);
36
37 % Defining fields needed for dictionary learning
38
39 SMALL.DL(i).toolbox = 'KSVD';
40 SMALL.DL(i).name = 'ksvd';
41
42 % Defining the parameters for KSVD
43 % In this example we are learning 88 atoms in 100 iterations.
44 % our aim here is to show how individual parameters can be tested in
45 % the AMT problem. We test ten different values for sparity (Tdata)
46 % in KSVD algorithm.
47 % Type help ksvd in MATLAB prompt for more options.
48 Tdata(i)=i;
49 SMALL.DL(i).param=struct('Tdata', Tdata(i), 'dictsize', SMALL.Problem.p, 'iternum', 100);
50
51 % Learn the dictionary
52
53 SMALL.DL(i) = SMALL_learn(SMALL.Problem, SMALL.DL(i));
54
55 % Set SMALL.Problem.A dictionary and reconstruction function
56 % (backward compatiblity with SPARCO: solver structure communicate
57 % only with Problem structure, ie no direct communication between DL and
58 % solver structures)
59
60 SMALL.Problem.A = SMALL.DL(i).D;
61 SMALL.Problem.reconstruct = @(x) SMALL_midiGenerate(x, SMALL.Problem);
62
63 %%
64 % Initialising solver structure
65 % Setting solver structure fields (toolbox, name, param, solution,
66 % reconstructed and time) to zero values
67 % As an example, SPAMS (Julien Mairal 2009) implementation of LARS
68 % algorithm is used for representation of training set in the learned
69 % dictionary.
70
71 SMALL.solver(1)=SMALL_init_solver;
72
73 % Defining the parameters needed for sparse representation
74
75 SMALL.solver(1).toolbox='SPAMS';
76 SMALL.solver(1).name='mexLasso';
77
78 %%
79 % Initialising solver structure
80 % Setting solver structure fields (toolbox, name, param, solution,
81 % reconstructed and time) to zero values
82 % As an example, SPAMS (Julien Mairal 2009) implementation of LARS
83 % algorithm is used for representation of training set in the learned
84 % dictionary.
85
86 SMALL.solver(1).param=struct(...
87 'lambda', 2,...
88 'pos', 1,...
89 'mode', 2);
90
91 % Call SMALL_soolve to represent the signal in the given dictionary.
92 % As a final command SMALL_solve will call above defined reconstruction
93 % function to reconstruct the training set (Problem.b) in the learned
94 % dictionary (Problem.A)
95
96
97 SMALL.solver(1)=SMALL_solve(SMALL.Problem, SMALL.solver(1));
98
99 %%
100 % Analysis of the result of automatic music transcription. If groundtruth
101 % exists, we can compare transcribed notes and original and get usual
102 % True Positives, False Positives and False Negatives measures.
103
104 AMT_res(i) = AMT_analysis(SMALL.Problem, SMALL.solver(1));
105 if AMT_res(i).TP>TPmax
106 TPmax=AMT_res(i).TP;
107 BLmidi=SMALL.solver(1).reconstructed.midi;
108 max=i;
109 end
110 end % end of for loop
111
112 %%
113 % Plot results and save midi files
114
115 figAMTbest=SMALL_AMT_plot(SMALL, AMT_res(max));
116
117 resFig=figure('Name', 'Automatic Music Transcription KSVD Sparsity TEST');
118
119 subplot (3,1,1); plot(Tdata(:), [AMT_res(:).TP], 'ro-');
120 title('True Positives vs Tdata');
121
122 subplot (3,1,2); plot(Tdata(:), [AMT_res(:).FN], 'ro-');
123 title('False Negatives vs Tdata');
124
125 subplot (3,1,3); plot(Tdata(:), [AMT_res(:).FP], 'ro-');
126 title('False Positives vs Tdata');
127
128 FS=filesep;
129 [pathstr1, name, ext, versn] = fileparts(which('SMALLboxSetup.m'));
130 cd([pathstr1,FS,'results']);
131 [filename,pathname] = uiputfile({' *.mid;' },'Save midi');
132 if filename~=0 writemidi(BLmidi, [pathname,FS,filename]);end
133 [filename,pathname] = uiputfile({' *.fig;' },'Save figure TP/FN/FP vs Tdata');
134 if filename~=0 saveas(resFig, [pathname,FS,filename]);end
135
136 [filename,pathname] = uiputfile({' *.fig;' },'Save BEST AMT figure');
137 if filename~=0 saveas(figAMTbest, [pathname,FS,filename]);end
138