Dawn@4: function [] = SVM_HNR_Singing( inputFileName ) 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( 'SVM_Singing_HNR.txt', 'a' ); Dawn@4: outputFileName = ['SVM_' inputFileName]; Dawn@4: masterFileOutputID = fopen( outputFileName, 'a' ); Dawn@4: Dawn@4: % input results file name Dawn@4: % inputFileName = 'singingBasicHNRStats.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/SVM_Results_'; Dawn@4: % resultsFileName = 'SVM_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: % fileSVMOutputID = 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: groups = []; Dawn@4: 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: groups( fileCount ) = 1; Dawn@4: elseif( ~(isempty(strfind(thestr,'neg')))) Dawn@4: % sample is negative Dawn@4: sampleEmotion( fileCount ) = 'N'; Dawn@4: groups( fileCount ) = 0; 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 SVM classifier ------------------------ Dawn@4: Dawn@4: G1E1 = []; G1E2 = []; G2E1 = []; G2E2 = []; UE1 = []; UE2 = []; Dawn@4: Dawn@4: noOfIterations = 10; Dawn@4: Dawn@4: for n = 1:noOfIterations Dawn@4: % Randomly select training and test sets Dawn@4: [train, test] = crossvalind('holdOut',groups); Dawn@4: cp = classperf(groups); Dawn@4: Dawn@4: % Use a linear support vector machine classifier Dawn@4: svmStruct = svmtrain(data(train,:),groups(train),'showplot',true); Dawn@4: classes = svmclassify(svmStruct,data(test,:),'showplot',true); Dawn@4: % See how well the classifier performed Dawn@4: classperf(cp,classes,test); Dawn@4: numbers = cp.CountingMatrix; Dawn@4: Dawn@4: G1E1(n) = numbers(1,1); Dawn@4: G1E2(n) = numbers(1,2); Dawn@4: G2E1(n) = numbers(2,1); Dawn@4: G2E2(n) = numbers(2,2); Dawn@4: UE1(n) = numbers(3,1); Dawn@4: UE2(n) = numbers(3,2); Dawn@4: Dawn@4: end Dawn@4: Dawn@4: G1E1 = sum(G1E1) / noOfIterations; Dawn@4: G1E2 = sum(G1E2) / noOfIterations; Dawn@4: G2E1 = sum(G2E1) / noOfIterations; Dawn@4: G2E2 = sum(G2E2) / noOfIterations; Dawn@4: % Dawn@4: % fprintf( fileOutputID, '\n' ); Dawn@4: % fclose( fileOutputID ); Dawn@4: % fprintf( fileSVMOutputID, '\n' ); Dawn@4: % fclose( fileKMeansOutputID ); Dawn@4: fprintf( masterFileOutputID, '\n' ); Dawn@4: fclose( masterFileOutputID ); Dawn@4: Dawn@4: end Dawn@4: Dawn@4: