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