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