annotate Code/Classifiers/SVM_MFCC_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 [] = SVM_MFCC_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( 'SVM_Singing_MFCC_VoicedAndUnvoiced_Unsmoothed.txt', 'a' );
Dawn@4 8 % input results file name
Dawn@4 9 inputFileName = 'singingMFCCStats_VoicedAndUnvoiced_Unsmoothed.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/SVM_Results_';
Dawn@4 17 resultsFileName = 'SVM_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 fileSVMOutputID = 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 groups = [];
Dawn@4 40
Dawn@4 41 while( ~(feof(inputFileID)) )
Dawn@4 42
Dawn@4 43 outputValues = [];
Dawn@4 44 thestr = fgetl(inputFileID);
Dawn@4 45 fileCount = fileCount + 1;
Dawn@4 46
Dawn@4 47 % determine whether we have a positive or negative sample
Dawn@4 48 sampleEmotion( fileCount ) = 'U';
Dawn@4 49 if( ~(isempty(strfind(thestr,'pos'))))
Dawn@4 50 % sample is positive
Dawn@4 51 sampleEmotion( fileCount ) = 'P';
Dawn@4 52 groups( fileCount ) = 1;
Dawn@4 53 elseif( ~(isempty(strfind(thestr,'neg'))))
Dawn@4 54 % sample is negative
Dawn@4 55 sampleEmotion( fileCount ) = 'N';
Dawn@4 56 groups( fileCount ) = 0;
Dawn@4 57 else
Dawn@4 58 disp('EEEK!');
Dawn@4 59 pause;
Dawn@4 60 end
Dawn@4 61
Dawn@4 62 % determine whether we have a male, female or trans sample
Dawn@4 63 gender( fileCount ) = '?';
Dawn@4 64 if( ~(isempty(strfind(thestr,'fem'))))
Dawn@4 65 % gender is female
Dawn@4 66 gender( fileCount ) = 'F';
Dawn@4 67 elseif( ~(isempty(strfind(thestr,'male'))))
Dawn@4 68 % gender is male
Dawn@4 69 gender( fileCount ) = 'M';
Dawn@4 70 elseif( ~(isempty(strfind(thestr,'trans'))))
Dawn@4 71 % gender is trans
Dawn@4 72 gender( fileCount ) = 'T';
Dawn@4 73 else
Dawn@4 74 disp('EEEK!');
Dawn@4 75 pause;
Dawn@4 76 end
Dawn@4 77
Dawn@4 78 %how many values are in the string?
Dawn@4 79 spaces = strfind( thestr, ' ' );
Dawn@4 80 numberstr = thestr( spaces(1) : end ); % chop off the file name
Dawn@4 81 vars = sscanf( numberstr, '%f', inf );
Dawn@4 82 data( fileCount, : ) = vars;
Dawn@4 83
Dawn@4 84 lineCount = lineCount + 1;
Dawn@4 85
Dawn@4 86 end
Dawn@4 87 fclose(inputFileID);
Dawn@4 88
Dawn@4 89 % ------------ apply the SVM classifier ------------------------
Dawn@4 90
Dawn@4 91 G1E1 = []; G1E2 = []; G2E1 = []; G2E2 = []; UE1 = []; UE2 = [];
Dawn@4 92
Dawn@4 93 noOfIterations = 10;
Dawn@4 94
Dawn@4 95 for n = 1:noOfIterations
Dawn@4 96 % Randomly select training and test sets
Dawn@4 97 [train, test] = crossvalind('holdOut',groups);
Dawn@4 98 cp = classperf(groups);
Dawn@4 99
Dawn@4 100 % Use a linear support vector machine classifier
Dawn@4 101 svmStruct = svmtrain(data(train,:),groups(train),'showplot',true);
Dawn@4 102 classes = svmclassify(svmStruct,data(test,:),'showplot',true);
Dawn@4 103 % See how well the classifier performed
Dawn@4 104 classperf(cp,classes,test);
Dawn@4 105 numbers = cp.CountingMatrix;
Dawn@4 106
Dawn@4 107 G1E1(n) = numbers(1,1);
Dawn@4 108 G1E2(n) = numbers(1,2);
Dawn@4 109 G2E1(n) = numbers(2,1);
Dawn@4 110 G2E2(n) = numbers(2,2);
Dawn@4 111 UE1(n) = numbers(3,1);
Dawn@4 112 UE2(n) = numbers(3,2);
Dawn@4 113
Dawn@4 114 end
Dawn@4 115
Dawn@4 116 G1E1 = sum(G1E1) / noOfIterations;
Dawn@4 117 G1E2 = sum(G1E2) / noOfIterations;
Dawn@4 118 G2E1 = sum(G2E1) / noOfIterations;
Dawn@4 119 G2E2 = sum(G2E2) / noOfIterations;
Dawn@4 120
Dawn@4 121 fprintf( fileOutputID, '\n' );
Dawn@4 122 fclose( fileOutputID );
Dawn@4 123 fprintf( fileSVMOutputID, '\n' );
Dawn@4 124 fclose( fileSVMOutputID );
Dawn@4 125 fprintf( masterFileOutputID, '\n' );
Dawn@4 126 fclose( masterFileOutputID );
Dawn@4 127
Dawn@4 128 end
Dawn@4 129
Dawn@4 130