comparison Code/Classifiers/kmeans_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_Singing( inputFileName )
2
3 cd 'C:\Users\dawn\Dropbox\TestResults'
4 inputFileName
5
6 DEBUG = 1;
7 % output results file name
8 outputFileName = ['kmeans_' inputFileName];
9 masterFileOutputID = fopen( outputFileName, 'a' );
10
11 fprintf( masterFileOutputID, '\n RESULTS FILE NAME: %s\n', inputFileName);
12 inputFileID = fopen( inputFileName );
13
14 titleName = '';
15
16 fprintf( masterFileOutputID, '\t' );
17
18 % -------------------- get the data from the results file ---------------
19
20 lineCount = 0;
21 fileCount = 0;
22 data = [];
23 while( ~(feof(inputFileID)) )
24
25 outputValues = [];
26 thestr = fgetl(inputFileID);
27 fileCount = fileCount + 1;
28
29 % determine whether we have a positive or negative sample
30 sampleEmotion( fileCount ) = 'U';
31 if( ~(isempty(strfind(thestr,'pos'))))
32 % sample is positive
33 sampleEmotion( fileCount ) = 'P';
34 elseif( ~(isempty(strfind(thestr,'neg'))))
35 % sample is negative
36 sampleEmotion( fileCount ) = 'N';
37 else
38 disp('EEEK!');
39 fileCount = fileCount - 1;
40 % pause;
41 end
42
43 % determine whether we have a male, female or trans sample
44 % gender( fileCount ) = '?';
45 % if( ~(isempty(strfind(thestr,'fem'))))
46 % % gender is female
47 % gender( fileCount ) = 'F';
48 % elseif( ~(isempty(strfind(thestr,'male'))))
49 % % gender is male
50 % gender( fileCount ) = 'M';
51 % elseif( ~(isempty(strfind(thestr,'trans'))))
52 % % gender is trans
53 % gender( fileCount ) = 'T';
54 % else
55 % disp('EEEK!');
56 % pause;
57 % end
58
59 if(( ~(isempty(strfind(thestr,'pos')))) || ( ~(isempty(strfind(thestr,'neg')))) )
60 %how many values are in the string?
61 % spaces = strfind( thestr, ' ' );
62 spaces = [ strfind( thestr, sprintf('\t')) strfind( thestr, ' ' )];
63 numberstr = thestr( spaces(1) : end ); % chop off the file name
64 vars = sscanf( numberstr, '%f', inf );
65 data( fileCount, : ) = vars;
66 end
67 lineCount = lineCount + 1;
68
69 end
70 fclose(inputFileID);
71
72 % ------------ apply the k-means classifier ------------------------
73
74 noOfClusters = 2; % we are only trying to identify positive and negative emotions
75
76
77 [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,...
78 'start', 'sample', 'Distance', 'cityblock');
79
80 %display results grouped by emotion
81 fprintf( masterFileOutputID, '\n Emotion grouping \n');
82 fprintf( masterFileOutputID, 'cityblock \n');
83 [ groupStats, groupNames ] = processKMeansResults( 'cityblock', idx, sampleEmotion, masterFileOutputID, titleName, DEBUG );
84 [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID, 'cityblock' );
85
86
87 fprintf( masterFileOutputID, 'sqEuclidean \n');
88 [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,...
89 'start', 'sample', 'Distance', 'sqEuclidean');
90
91 [ groupStats, groupNames ] = processKMeansResults( 'sqEuclidean', idx, sampleEmotion, masterFileOutputID, titleName, DEBUG );
92 [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID, 'sqEuclidean' );
93
94
95 fprintf( masterFileOutputID, 'cosine \n');
96 [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,...
97 'start', 'sample', 'Distance', 'cosine');
98
99 [ groupStats, groupNames ] = processKMeansResults( 'cosine', idx, sampleEmotion, masterFileOutputID, titleName, DEBUG );
100 [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID, 'cosine' );
101
102
103 fprintf( masterFileOutputID, 'correlation \n');
104 [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,...
105 'start', 'sample', 'Distance', 'correlation');
106
107 [ groupStats, groupNames ] = processKMeansResults( 'correlation', idx, sampleEmotion, masterFileOutputID, titleName, DEBUG );
108 [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID, 'correlation' );
109
110 % --------------------------------------------------------------------
111
112 % display results grouped by gender
113 % fprintf( masterFileOutputID, '\n Gender grouping \n');
114 % noOfClusters = 3;
115 %
116 % [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,...
117 % 'start', 'sample', 'Distance', 'cityblock');
118 %
119 % fprintf( masterFileOutputID, 'cityblock \n');
120 % [ groupStats, groupNames ] = processKMeansResults( 'cityblock', idx, gender, masterFileOutputID, titleName, DEBUG );
121 % [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID );
122 %
123 % [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,...
124 % 'start', 'sample', 'Distance', 'sqEuclidean');
125 %
126 % fprintf( masterFileOutputID, 'sqEuclidean \n');
127 % [ groupStats, groupNames ] = processKMeansResults( 'sqEuclidean', idx, gender, masterFileOutputID, titleName, DEBUG );
128 % [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID );
129
130 fprintf( masterFileOutputID, '\n' );
131 fclose( masterFileOutputID );
132
133 end
134
135