comparison 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
comparison
equal deleted inserted replaced
3:e1cfa7765647 4:92ca03a8fa99
1 function [] = SVM_MFCC_Singing( varargin )
2
3 cd 'C:\Users\dawn\Dropbox\TestResults'
4
5 DEBUG = 1;
6 % output results file name
7 masterFileOutputID = fopen( 'SVM_Singing_MFCC_VoicedAndUnvoiced_Unsmoothed.txt', 'a' );
8 % input results file name
9 inputFileName = 'singingMFCCStats_VoicedAndUnvoiced_Unsmoothed.txt';
10
11 fprintf( masterFileOutputID, '\n RESULTS FILE NAME: %s\n', inputFileName);
12 inputFileID = fopen( inputFileName );
13
14 noOfArguments = length(varargin);
15
16 outputFileName = 'individualResults/SVM_Results_';
17 resultsFileName = 'SVM_Results_';
18 titleName = '';
19 for i=1 : noOfArguments
20 titleName = [ titleName varargin{i} '_'];
21 fprintf( masterFileOutputID, '%s_', varargin{i} );
22 end
23
24 outputFileName = [ outputFileName titleName ];
25 resultsFileName = [ resultsFileName titleName ];
26
27 fprintf( masterFileOutputID, '\t' );
28
29 outputFileName = [ outputFileName '.txt'];
30 resultsFileName = [ resultsFileName '.txt'];
31
32 fileOutputID = fopen( outputFileName, 'w' );
33 fileSVMOutputID = fopen( resultsFileName, 'w' );
34
35 % -------------------- get the data from the results file ---------------
36 lineCount = 0;
37 fileCount = 0;
38 data = [];
39 groups = [];
40
41 while( ~(feof(inputFileID)) )
42
43 outputValues = [];
44 thestr = fgetl(inputFileID);
45 fileCount = fileCount + 1;
46
47 % determine whether we have a positive or negative sample
48 sampleEmotion( fileCount ) = 'U';
49 if( ~(isempty(strfind(thestr,'pos'))))
50 % sample is positive
51 sampleEmotion( fileCount ) = 'P';
52 groups( fileCount ) = 1;
53 elseif( ~(isempty(strfind(thestr,'neg'))))
54 % sample is negative
55 sampleEmotion( fileCount ) = 'N';
56 groups( fileCount ) = 0;
57 else
58 disp('EEEK!');
59 pause;
60 end
61
62 % determine whether we have a male, female or trans sample
63 gender( fileCount ) = '?';
64 if( ~(isempty(strfind(thestr,'fem'))))
65 % gender is female
66 gender( fileCount ) = 'F';
67 elseif( ~(isempty(strfind(thestr,'male'))))
68 % gender is male
69 gender( fileCount ) = 'M';
70 elseif( ~(isempty(strfind(thestr,'trans'))))
71 % gender is trans
72 gender( fileCount ) = 'T';
73 else
74 disp('EEEK!');
75 pause;
76 end
77
78 %how many values are in the string?
79 spaces = strfind( thestr, ' ' );
80 numberstr = thestr( spaces(1) : end ); % chop off the file name
81 vars = sscanf( numberstr, '%f', inf );
82 data( fileCount, : ) = vars;
83
84 lineCount = lineCount + 1;
85
86 end
87 fclose(inputFileID);
88
89 % ------------ apply the SVM classifier ------------------------
90
91 G1E1 = []; G1E2 = []; G2E1 = []; G2E2 = []; UE1 = []; UE2 = [];
92
93 noOfIterations = 10;
94
95 for n = 1:noOfIterations
96 % Randomly select training and test sets
97 [train, test] = crossvalind('holdOut',groups);
98 cp = classperf(groups);
99
100 % Use a linear support vector machine classifier
101 svmStruct = svmtrain(data(train,:),groups(train),'showplot',true);
102 classes = svmclassify(svmStruct,data(test,:),'showplot',true);
103 % See how well the classifier performed
104 classperf(cp,classes,test);
105 numbers = cp.CountingMatrix;
106
107 G1E1(n) = numbers(1,1);
108 G1E2(n) = numbers(1,2);
109 G2E1(n) = numbers(2,1);
110 G2E2(n) = numbers(2,2);
111 UE1(n) = numbers(3,1);
112 UE2(n) = numbers(3,2);
113
114 end
115
116 G1E1 = sum(G1E1) / noOfIterations;
117 G1E2 = sum(G1E2) / noOfIterations;
118 G2E1 = sum(G2E1) / noOfIterations;
119 G2E2 = sum(G2E2) / noOfIterations;
120
121 fprintf( fileOutputID, '\n' );
122 fclose( fileOutputID );
123 fprintf( fileSVMOutputID, '\n' );
124 fclose( fileSVMOutputID );
125 fprintf( masterFileOutputID, '\n' );
126 fclose( masterFileOutputID );
127
128 end
129
130