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