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