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