Mercurial > hg > emotion-detection-top-level
diff Code/Classifiers/SVM_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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Code/Classifiers/SVM_HNR_Singing.m Wed Feb 13 11:02:39 2013 +0000 @@ -0,0 +1,133 @@ +function [] = SVM_HNR_Singing( inputFileName ) + +cd 'C:\Users\dawn\Dropbox\TestResults' + +DEBUG = 1; +% output results file name +% masterFileOutputID = fopen( 'SVM_Singing_HNR.txt', 'a' ); +outputFileName = ['SVM_' inputFileName]; +masterFileOutputID = fopen( outputFileName, 'a' ); + +% input results file name +% inputFileName = 'singingBasicHNRStats.txt'; + +% fprintf( masterFileOutputID, '\n RESULTS FILE NAME: %s\n', inputFileName); +inputFileID = fopen( inputFileName ); + +% noOfArguments = length(varargin); + +% outputFileName = 'individualResults/SVM_Results_'; +% resultsFileName = 'SVM_Results_'; +% titleName = ''; +% for i=1 : noOfArguments +% titleName = [ titleName varargin{i} '_']; +% fprintf( masterFileOutputID, '%s_', varargin{i} ); +% end + +% outputFileName = [ outputFileName titleName ]; +% resultsFileName = [ resultsFileName titleName ]; + +fprintf( masterFileOutputID, '\t' ); + +% outputFileName = [ outputFileName '.txt']; +% resultsFileName = [ resultsFileName '.txt']; +% +% fileOutputID = fopen( outputFileName, 'w' ); +% fileSVMOutputID = fopen( resultsFileName, 'w' ); + +% -------------------- get the data from the results file --------------- +lineCount = 0; +fileCount = 0; +data = []; +groups = []; + +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'; + groups( fileCount ) = 1; + elseif( ~(isempty(strfind(thestr,'neg')))) + % sample is negative + sampleEmotion( fileCount ) = 'N'; + groups( fileCount ) = 0; + else + disp('EEEK!'); + 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 + + %how many values are in the string? + spaces = strfind( thestr, ' ' ); + numberstr = thestr( spaces(1) : end ); % chop off the file name + vars = sscanf( numberstr, '%f', inf ); + data( fileCount, : ) = vars; + + lineCount = lineCount + 1; + +end +fclose(inputFileID); + +% ------------ apply the SVM classifier ------------------------ + +G1E1 = []; G1E2 = []; G2E1 = []; G2E2 = []; UE1 = []; UE2 = []; + +noOfIterations = 10; + +for n = 1:noOfIterations + % Randomly select training and test sets + [train, test] = crossvalind('holdOut',groups); + cp = classperf(groups); + + % Use a linear support vector machine classifier + svmStruct = svmtrain(data(train,:),groups(train),'showplot',true); + classes = svmclassify(svmStruct,data(test,:),'showplot',true); + % See how well the classifier performed + classperf(cp,classes,test); + numbers = cp.CountingMatrix; + + G1E1(n) = numbers(1,1); + G1E2(n) = numbers(1,2); + G2E1(n) = numbers(2,1); + G2E2(n) = numbers(2,2); + UE1(n) = numbers(3,1); + UE2(n) = numbers(3,2); + +end + +G1E1 = sum(G1E1) / noOfIterations; +G1E2 = sum(G1E2) / noOfIterations; +G2E1 = sum(G2E1) / noOfIterations; +G2E2 = sum(G2E2) / noOfIterations; +% +% fprintf( fileOutputID, '\n' ); +% fclose( fileOutputID ); +% fprintf( fileSVMOutputID, '\n' ); +% fclose( fileKMeansOutputID ); +fprintf( masterFileOutputID, '\n' ); +fclose( masterFileOutputID ); + +end + +