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