-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemotion_classify_compare.asv
101 lines (76 loc) · 2.98 KB
/
emotion_classify_compare.asv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
clear
%READ FROM FILES
cd Emo_features
features_sv_a=dlmread('emo_a.dat');
features_sv_f=dlmread('emo_f.dat');
features_sv_n=dlmread('emo_n.dat');
features_sv_w=dlmread('emo_w.dat');
cd ..
%STORE LENGTHS OF EACH TYPE OF FEATURE
len_fea(1)=size(features_sv_a,1);
len_fea(2)=size(features_sv_f,1);
len_fea(3)=size(features_sv_n,1);
len_fea(4)=size(features_sv_w,1);
n=4;
max_len=max(len_fea);
emo_features=zeros(max_len,60,n);
%ICORPORATE ALL FEATURES IN A 3-D ARRAY
emo_features(1:len_fea(1),:,1)=features_sv_a;
emo_features(1:len_fea(2),:,2)=features_sv_f;
emo_features(1:len_fea(3),:,3)=features_sv_n;
emo_features(1:len_fea(4),:,4)=features_sv_w;
group=ones(max_len,n);
for i=[1:n]
group(:,i)=group(:,i)*i;
end
perc=zeros(5,n+1);
total=zeros(5,n);
incorrect=zeros(5,n);
for x=[1:5]
%-----------------------------------------------------------------%
%SEPERATE TEST AND TRAIN FILES
train=logical(zeros(max_len,n));
test=logical(zeros(max_len,n));
for i=[1:n]
[train_n, test_n] = crossvalind('holdOut', group(1:len_fea(i),i) ,0.3);
train(1:len_fea(i),i)=train_n;
test(1:len_fea(i),i)=test_n;
end
%-----------------------------------------------------------------%
%CREATE SVM STRUCTS AFTER TRAINING
k=1;
for i=[1:n-1]
for j=[i+1:n]
svm(k)=svmtrain( [emo_features( train(:,i),:,i);emo_features(train(:,j),:,j)] , [group(train(:,i),i);group(train(:,j),j)] );
k=k+1;
end
end
k=k-1;
%-----------------------------------------------------------------%
%CLASSIFY TEST DATA
label=zeros( max_len , k ,n);
for i=[1:n]
for j=[1:k]
label_new=svmclassify( svm(j),emo_features( test(:,i),:,i) );
len_label(i)=length(label_new);
label(1:len_label(i),j,i)=label_new;
end
end
%-----------------------------------------------------------------%
%COMPUTE FINAL EMOTION AND RESULTS
len1=floor(max_len*0.3);
emo=zeros(len1,n);
for i=[1:n]
for j=[1: (len_fea(i)*0.3)]
emo(j,i)=mode( label(j,:,i));
total(x,i)=total(x,i)+1;
if not(emo(j,i)==i)
incorrect(x,i)=incorrect(x,i)+1;
end
end
perc(x,i)=double(incorrect(x,i)/total(x,i));
end
perc(x,n+1)=double(sum(incorrect(x,:))/sum(total(x,:)));
%-------------------------------------------------------------%
%ADABOOST
end