comparison Code/Classifiers/kmeans_MFCC_Singing.m @ 4:92ca03a8fa99 tip

Update to ICASSP 2013 benchmark
author Dawn Black
date Wed, 13 Feb 2013 11:02:39 +0000
parents
children
comparison
equal deleted inserted replaced
3:e1cfa7765647 4:92ca03a8fa99
1 function [] = kmeans_MFCC_Singing( inputFileName, outputFileName )
2
3 cd 'C:\Users\dawn\Dropbox\TestResults'
4 inputFileName
5
6 DEBUG = 1;
7 % output results file name
8 masterFileOutputID = fopen( outputFileName, 'a' ); %fopen( 'kmeans_Singing_MFCC.txt', 'a' );
9 % % input results file name
10 % inputFileName = 'singingMFCCStats_VoicedAndUnvoiced.txt';
11
12 fprintf( masterFileOutputID, '\n RESULTS FILE NAME: %s\n', inputFileName);
13 inputFileID = fopen( inputFileName );
14
15 % noOfArguments = length(varargin);
16 %
17 % outputFileName = 'individualResults/kmeans_Results_';
18 % resultsFileName = 'kmeans_Results_';
19 titleName = '';
20 % for i=1 : noOfArguments
21 % titleName = [ titleName varargin{i} '_'];
22 % fprintf( masterFileOutputID, '%s_', varargin{i} );
23 % end
24 %
25 % outputFileName = [ outputFileName titleName ];
26 % resultsFileName = [ resultsFileName titleName ];
27
28 fprintf( masterFileOutputID, '\t' );
29
30 % outputFileName = [ outputFileName '.txt'];
31 % resultsFileName = [ resultsFileName '.txt'];
32
33 % fileOutputID = fopen( outputFileName, 'w' );
34 % fileKMeansOutputID = fopen( resultsFileName, 'w' );
35
36 % -------------------- get the data from the results file ---------------
37 lineCount = 0;
38 fileCount = 0;
39 data = [];
40 while( ~(feof(inputFileID)) )
41
42 outputValues = [];
43 thestr = fgetl(inputFileID);
44 fileCount = fileCount + 1;
45
46 % determine whether we have a positive or negative sample
47 sampleEmotion( fileCount ) = 'U';
48 if( ~(isempty(strfind(thestr,'pos'))))
49 % sample is positive
50 sampleEmotion( fileCount ) = 'P';
51 elseif( ~(isempty(strfind(thestr,'neg'))))
52 % sample is negative
53 sampleEmotion( fileCount ) = 'N';
54 else
55 disp('EEEK!');
56 pause;
57 end
58
59 % determine whether we have a male, female or trans sample
60 gender( fileCount ) = '?';
61 if( ~(isempty(strfind(thestr,'fem'))))
62 % gender is female
63 gender( fileCount ) = 'F';
64 elseif( ~(isempty(strfind(thestr,'male'))))
65 % gender is male
66 gender( fileCount ) = 'M';
67 elseif( ~(isempty(strfind(thestr,'trans'))))
68 % gender is trans
69 gender( fileCount ) = 'T';
70 else
71 disp('EEEK!');
72 pause;
73 end
74
75 %how many values are in the string?
76 spaces = strfind( thestr, ' ' );
77 numberstr = thestr( spaces(1) : end ); % chop off the file name
78 vars = sscanf( numberstr, '%f', inf );
79 data( fileCount, : ) = vars;
80
81 lineCount = lineCount + 1;
82
83 end
84 fclose(inputFileID);
85
86 % try with and without different metrics classes
87 % data is a 162 variable array of MFCC stats
88 % first there are 6 metrics for each of the 13 frequency bands (mean, median, var, min, max, range)
89 % then there are 6 metrics for the 1st derivative of the 13 frequency bands (mean, median, var, min, max, range)
90 % then there are 6 metrics for the mean of all frequency bands
91
92 % dataOptions = (1:1:(13*12)+6); % fprintf( masterFileOutputID, '\n try with all \n');
93 % dataOptions = (1:1:13*6); fprintf( masterFileOutputID, '\n try with just the ordinary 13 frequency bands \n');
94 % dataOptions = (1:1:13*6); fprintf( masterFileOutputID, '\n try with just the ordinary 13 frequency bands and without the median or range \n');
95
96 % ------------ apply the k-means classifier ------------------------
97
98 noOfClusters = 2; % we are only trying to identify positive and negative emotions
99
100
101 [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,...
102 'start', 'sample', 'Distance', 'cityblock');
103
104 %display results grouped by emotion
105 fprintf( masterFileOutputID, '\n Emotion grouping \n');
106 fprintf( masterFileOutputID, 'cityblock \n');
107 [ groupStats, groupNames ] = processKMeansResults( 'cityblock', idx, sampleEmotion, masterFileOutputID, titleName, DEBUG );
108 [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID );
109 % if(DEBUG == 1)
110 % disp('press space');
111 % pause;
112 % end
113
114 fprintf( masterFileOutputID, 'sqEuclidean \n');
115 [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,...
116 'start', 'sample', 'Distance', 'sqEuclidean');
117
118 [ groupStats, groupNames ] = processKMeansResults( 'sqEuclidean', idx, sampleEmotion, masterFileOutputID, titleName, DEBUG );
119 [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID );
120
121 % if(DEBUG == 1)
122 % disp('press space');
123 % pause;
124 % end
125
126 % display results grouped by gender
127 fprintf( masterFileOutputID, '\n Gender grouping \n');
128 noOfClusters = 3;
129
130 [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,...
131 'start', 'sample', 'Distance', 'cityblock');
132
133 fprintf( masterFileOutputID, 'cityblock \n');
134 [ groupStats, groupNames ] = processKMeansResults( 'cityblock', idx, gender, masterFileOutputID, titleName, DEBUG );
135 [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID );
136
137 [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,...
138 'start', 'sample', 'Distance', 'sqEuclidean');
139
140 fprintf( masterFileOutputID, 'sqEuclidean \n');
141 [ groupStats, groupNames ] = processKMeansResults( 'sqEuclidean', idx, gender, masterFileOutputID, titleName, DEBUG );
142 [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID );
143
144
145 % fprintf( fileOutputID, '\n' );
146 % fclose( fileOutputID );
147 % fprintf( fileKMeansOutputID, '\n' );
148 % fclose( fileKMeansOutputID );
149 fprintf( masterFileOutputID, '\n' );
150 fclose( masterFileOutputID );
151
152 end
153
154