Mercurial > hg > emotion-detection-top-level
view 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 |
line wrap: on
line source
function [] = kmeans_Singing( inputFileName ) cd 'C:\Users\dawn\Dropbox\TestResults' inputFileName DEBUG = 1; % output results file name outputFileName = ['kmeans_' inputFileName]; masterFileOutputID = fopen( outputFileName, 'a' ); fprintf( masterFileOutputID, '\n RESULTS FILE NAME: %s\n', inputFileName); inputFileID = fopen( inputFileName ); titleName = ''; fprintf( masterFileOutputID, '\t' ); % -------------------- get the data from the results file --------------- lineCount = 0; fileCount = 0; data = []; while( ~(feof(inputFileID)) ) outputValues = []; thestr = fgetl(inputFileID); fileCount = fileCount + 1; % determine whether we have a positive or negative sample sampleEmotion( fileCount ) = 'U'; if( ~(isempty(strfind(thestr,'pos')))) % sample is positive sampleEmotion( fileCount ) = 'P'; elseif( ~(isempty(strfind(thestr,'neg')))) % sample is negative sampleEmotion( fileCount ) = 'N'; else disp('EEEK!'); fileCount = fileCount - 1; % pause; end % determine whether we have a male, female or trans sample % gender( fileCount ) = '?'; % if( ~(isempty(strfind(thestr,'fem')))) % % gender is female % gender( fileCount ) = 'F'; % elseif( ~(isempty(strfind(thestr,'male')))) % % gender is male % gender( fileCount ) = 'M'; % elseif( ~(isempty(strfind(thestr,'trans')))) % % gender is trans % gender( fileCount ) = 'T'; % else % disp('EEEK!'); % pause; % end if(( ~(isempty(strfind(thestr,'pos')))) || ( ~(isempty(strfind(thestr,'neg')))) ) %how many values are in the string? % spaces = strfind( thestr, ' ' ); spaces = [ strfind( thestr, sprintf('\t')) strfind( thestr, ' ' )]; numberstr = thestr( spaces(1) : end ); % chop off the file name vars = sscanf( numberstr, '%f', inf ); data( fileCount, : ) = vars; end lineCount = lineCount + 1; end fclose(inputFileID); % ------------ apply the k-means classifier ------------------------ noOfClusters = 2; % we are only trying to identify positive and negative emotions [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,... 'start', 'sample', 'Distance', 'cityblock'); %display results grouped by emotion fprintf( masterFileOutputID, '\n Emotion grouping \n'); fprintf( masterFileOutputID, 'cityblock \n'); [ groupStats, groupNames ] = processKMeansResults( 'cityblock', idx, sampleEmotion, masterFileOutputID, titleName, DEBUG ); [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID, 'cityblock' ); fprintf( masterFileOutputID, 'sqEuclidean \n'); [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,... 'start', 'sample', 'Distance', 'sqEuclidean'); [ groupStats, groupNames ] = processKMeansResults( 'sqEuclidean', idx, sampleEmotion, masterFileOutputID, titleName, DEBUG ); [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID, 'sqEuclidean' ); fprintf( masterFileOutputID, 'cosine \n'); [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,... 'start', 'sample', 'Distance', 'cosine'); [ groupStats, groupNames ] = processKMeansResults( 'cosine', idx, sampleEmotion, masterFileOutputID, titleName, DEBUG ); [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID, 'cosine' ); fprintf( masterFileOutputID, 'correlation \n'); [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,... 'start', 'sample', 'Distance', 'correlation'); [ groupStats, groupNames ] = processKMeansResults( 'correlation', idx, sampleEmotion, masterFileOutputID, titleName, DEBUG ); [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID, 'correlation' ); % -------------------------------------------------------------------- % display results grouped by gender % fprintf( masterFileOutputID, '\n Gender grouping \n'); % noOfClusters = 3; % % [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,... % 'start', 'sample', 'Distance', 'cityblock'); % % fprintf( masterFileOutputID, 'cityblock \n'); % [ groupStats, groupNames ] = processKMeansResults( 'cityblock', idx, gender, masterFileOutputID, titleName, DEBUG ); % [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID ); % % [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,... % 'start', 'sample', 'Distance', 'sqEuclidean'); % % fprintf( masterFileOutputID, 'sqEuclidean \n'); % [ groupStats, groupNames ] = processKMeansResults( 'sqEuclidean', idx, gender, masterFileOutputID, titleName, DEBUG ); % [ confusionMatrix ] = getConfusionMatrix( groupStats, groupNames, masterFileOutputID ); fprintf( masterFileOutputID, '\n' ); fclose( masterFileOutputID ); end