comparison toolboxes/MIRtoolbox1.3.2/MIRToolboxDemos/demo8classification.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function demo8classification
2 % To get familiar with different approaches of classification using
3 % MIRtoolbox, and to assess their performances.
4
5 % Part 1. The aim of this experiment is to categorize a set of very short
6 % musical excerpts according to their genres, through a supervised learning.
7
8 % 1.3. Select the training set for current directory.
9 try
10 cd train_set
11 catch
12 error('Please change current directory to ''MIRtoolboxDemos'' directory')
13 end
14
15 % Load all the files of the folder into one audio structure (called for
16 % instance training), and associate for each folder a label defined by the
17 % first two letters of the respective file name.
18 train = miraudio('Folder','Label',1:2);
19 cd ..
20
21 % In the same way, select the testing set for current directory, and load
22 % all the files including their labels:
23 cd test_set
24 test = miraudio('Folder','Label',1:2);
25 cd ..
26
27 % 1.4. Compute the mel-frequency cepstrum coefficient for each different
28 % audio file of both sets:
29 mfcc_train = mirmfcc(train);
30 mfcc_test = mirmfcc(test);
31
32 % 1.5. Estimate the label (i.e., genre) of each file from the testing set,
33 % based on a prior learning using the training set. Use for this purpose
34 % the classify function.
35 help mirclassify
36
37 % Let's first try a classification based of mfcc, for instance, using the
38 % minimum distance strategy:
39 mirclassify(test,mfcc_test,train,mfcc_train)
40
41 % The results indicates the outcomes and the total correct classification
42 % rate (CCR).
43
44 % 1.6. Let's try a k-nearest-neighbour strategy. For instance, for k = 5:
45 mirclassify(test,mfcc_test,train,mfcc_train,5)
46
47 % 1.7. Use a Gaussian mixture modelling with one gaussian per class:
48 mirclassify(test,mfcc_test,train,mfcc_train,'GMM',1)
49
50 % try also with three Gaussians per class.
51 mirclassify(test,mfcc_test,train,mfcc_train,'GMM',3)
52
53 % As this strategy is stochastic, the results vary for every trial.
54 mirclassify(test,mfcc_test,train,mfcc_train,'GMM',1)
55 mirclassify(test,mfcc_test,train,mfcc_train,'GMM',1)
56 mirclassify(test,mfcc_test,train,mfcc_train,'GMM',3)
57 mirclassify(test,mfcc_test,train,mfcc_train,'GMM',3)
58
59 % 1.8. Carry out the classification using other features such as spectral
60 % centroid:
61 spectrum_train = mirspectrum(train);
62 spectrum_test = mirspectrum(test);
63 centroid_train = mircentroid(spectrum_train);
64 centroid_test = mircentroid(spectrum_test);
65 mirclassify(test,centroid_test,train,centroid_train,'GMM',1)
66 mirclassify(test,centroid_test,train,centroid_train,'GMM',1)
67 mirclassify(test,centroid_test,train,centroid_train,'GMM',3)
68 mirclassify(test,centroid_test,train,centroid_train,'GMM',3)
69
70 % try also spectral entropy and spectral irregularity.
71 entropy_train = mirentropy(spectrum_train);
72 entropy_test = mirentropy(spectrum_test);
73 mirclassify(test,entropy_test,train,entropy_train,'GMM',1)
74 mirclassify(test,entropy_test,train,entropy_train,'GMM',1)
75 mirclassify(test,entropy_test,train,entropy_train,'GMM',3)
76 mirclassify(test,entropy_test,train,entropy_train,'GMM',3)
77
78 irregularity_train = mirregularity(spectrum_train,'Contrast',.1);
79 irregularity_test = mirregularity(spectrum_test,'Contrast',.1);
80 mirclassify(test,irregularity_test,train,irregularity_train,'GMM',1)
81 mirclassify(test,irregularity_test,train,irregularity_train,'GMM',1)
82 mirclassify(test,irregularity_test,train,irregularity_train,'GMM',3)
83 mirclassify(test,irregularity_test,train,irregularity_train,'GMM',3)
84
85 % Try classification based on a set of features such as:
86 mirclassify(test,{entropy_test,centroid_test},...
87 train,{entropy_train,centroid_train},'GMM',1)
88 mirclassify(test,{entropy_test,centroid_test},...
89 train,{entropy_train,centroid_train},'GMM',1)
90 mirclassify(test,{entropy_test,centroid_test},...
91 train,{entropy_train,centroid_train},'GMM',3)
92 mirclassify(test,{entropy_test,centroid_test},...
93 train,{entropy_train,centroid_train},'GMM',3)
94
95 % 1.9. By varying the features used for classification, the strategies and
96 % their parameters, try to find an optimal strategy that give best correct
97 % classification rate.
98 bright_train = mirbrightness(spectrum_train);
99 bright_test = mirbrightness(spectrum_test);
100 rolloff_train = mirbrightness(spectrum_train);
101 rolloff_test = mirbrightness(spectrum_test);
102 spread_train = mirspread(spectrum_train);
103 spread_test = mirspread(spectrum_test);
104 mirclassify(test,{bright_test,rolloff_test,spread_test},...
105 train,{bright_train,rolloff_train,spread_train},'GMM',3)
106 skew_train = mirskewness(spectrum_train);
107 skew_test = mirskewness(spectrum_test);
108 kurtosis_train = mirkurtosis(spectrum_train);
109 kurtosis_test = mirkurtosis(spectrum_test);
110 flat_train = mirflatness(spectrum_train);
111 flat_test = mirflatness(spectrum_test);
112 mirclassify(test,{skew_test,kurtosis_test,flat_test},...
113 train,{skew_train,kurtosis_train,flat_train},'GMM',3)
114 for i = 1:3
115 mirclassify(test,{mfcc_test,centroid_test,skew_test,kurtosis_test,...
116 flat_test,entropy_test,irregularity_test,...
117 bright_test,rolloff_test,spread_test},...
118 train,{mfcc_train,centroid_train,skew_train,kurtosis_train,...
119 flat_train,entropy_train,irregularity_train,...
120 bright_train,rolloff_train,spread_train},'GMM',3)
121 end
122
123 % You can also try to change the size of the training and testing sets (by
124 % simply interverting them for instance).
125 for i = 1:3
126 mirclassify(train,{mfcc_train,centroid_train,skew_train,kurtosis_train,...
127 flat_train,entropy_train,irregularity_train,...
128 bright_train,rolloff_train,spread_train},...
129 test,{mfcc_test,centroid_test,skew_test,kurtosis_test,...
130 flat_test,entropy_test,irregularity_test,...
131 bright_test,rolloff_test,spread_test},'GMM',3)
132 end
133
134 %%
135 % Part 2. In this second experiment, we will try to cluster the segments of
136 % an audio file according to their mutual similarity.
137
138 % 2.1. To simplify the computation, downsample
139 % the audio file to 11025 Hz.
140 a = miraudio('czardas','Sampling',11025);
141
142 % 2.2. Decompose the file into successive frames of 2 seconds with half-
143 % overlapping.
144 f = mirframe(a,2,.1);
145
146 % 2.3. Segment the file based on the novelty of the key strengths.
147 n = mirnovelty(mirkeystrength(f),'KernelSize',5)
148 p = mirpeaks(n)
149 s = mirsegment(a,p)
150
151 % 2.4. Compute the key strengths of each segment.
152 ks = mirkeystrength(s)
153
154 % 2.5. Cluster the segments according to their key strengths.
155 help mircluster
156 mircluster(s,ks)
157
158 % The k means algorithm used in the clustering is stochastic, and its
159 % results may vary at each run. By default, the algorithm is run 5 times
160 % and the best result is selected. Try the analysis with a higher number of
161 % runs:
162 mircluster(s,ks,'Runs',10)