Dawn@4: function [] = kmeans_HNR_Singing( varargin ) Dawn@4: Dawn@4: cd 'C:\Users\dawn\Dropbox\TestResults' Dawn@4: Dawn@4: DEBUG = 1; Dawn@4: % output results file name Dawn@4: masterFileOutputID = fopen( 'kmeans_Singing_MedianHNR_male01.txt', 'a' ); Dawn@4: % input results file name Dawn@4: inputFileName = 'singingMedianHNRStats_male01.txt'; Dawn@4: Dawn@4: fprintf( masterFileOutputID, '\n RESULTS FILE NAME: %s\n', inputFileName); Dawn@4: inputFileID = fopen( inputFileName ); Dawn@4: Dawn@4: noOfArguments = length(varargin); Dawn@4: Dawn@4: outputFileName = 'individualResults/kmeans_Results_'; Dawn@4: resultsFileName = 'kmeans_Results_'; Dawn@4: titleName = ''; Dawn@4: for i=1 : noOfArguments Dawn@4: titleName = [ titleName varargin{i} '_']; Dawn@4: fprintf( masterFileOutputID, '%s_', varargin{i} ); Dawn@4: end Dawn@4: Dawn@4: outputFileName = [ outputFileName titleName ]; Dawn@4: resultsFileName = [ resultsFileName titleName ]; Dawn@4: Dawn@4: fprintf( masterFileOutputID, '\t' ); Dawn@4: Dawn@4: outputFileName = [ outputFileName '.txt']; Dawn@4: resultsFileName = [ resultsFileName '.txt']; Dawn@4: Dawn@4: fileOutputID = fopen( outputFileName, 'w' ); Dawn@4: fileKMeansOutputID = fopen( resultsFileName, 'w' ); Dawn@4: Dawn@4: % -------------------- get the data from the results file --------------- 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: 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: %how many values are in the string? Dawn@4: spaces = 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: 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: processKMeansResults( 'cityblock', idx, sampleEmotion, fileOutputID, fileKMeansOutputID, masterFileOutputID, titleName, DEBUG ); Dawn@4: Dawn@4: if(DEBUG == 1) Dawn@4: disp('press space'); Dawn@4: pause; Dawn@4: end Dawn@4: Dawn@4: [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,... Dawn@4: 'start', 'sample', 'Distance', 'sqEuclidean'); Dawn@4: Dawn@4: processKMeansResults( 'sqEuclidean', idx, sampleEmotion, fileOutputID, fileKMeansOutputID, masterFileOutputID, titleName, DEBUG ); Dawn@4: Dawn@4: if(DEBUG == 1) Dawn@4: disp('press space'); Dawn@4: pause; Dawn@4: end 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: processKMeansResults( 'cityblock', idx, gender, fileOutputID, fileKMeansOutputID, masterFileOutputID, titleName, DEBUG ); Dawn@4: Dawn@4: if(DEBUG == 1) Dawn@4: disp('press space'); Dawn@4: pause; Dawn@4: end Dawn@4: Dawn@4: [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,... Dawn@4: 'start', 'sample', 'Distance', 'sqEuclidean'); Dawn@4: Dawn@4: processKMeansResults( 'sqEuclidean', idx, gender, fileOutputID, fileKMeansOutputID, masterFileOutputID, titleName, DEBUG ); Dawn@4: Dawn@4: if(DEBUG == 1) Dawn@4: disp('press space'); Dawn@4: pause; Dawn@4: end Dawn@4: Dawn@4: Dawn@4: fprintf( fileOutputID, '\n' ); Dawn@4: fclose( fileOutputID ); Dawn@4: fprintf( fileKMeansOutputID, '\n' ); Dawn@4: fclose( fileKMeansOutputID ); Dawn@4: fprintf( masterFileOutputID, '\n' ); Dawn@4: fclose( masterFileOutputID ); Dawn@4: Dawn@4: end Dawn@4: Dawn@4: