-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.m
57 lines (52 loc) · 1.68 KB
/
main.m
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
load('mnist.mat')
Delta = [0, 1, 1, 1, 1, 1, 1, 1, 1, 1;
1, 0, 1, 1, 1, 1, 1, 1, 1, 1;
1, 1, 0, 1, 1, 1, 1, 1, 1, 1;
1, 1, 1, 0, 1, 1, 1, 1, 1, 1;
1, 1, 1, 1, 0, 1, 1, 1, 1, 1;
1, 1, 1, 1, 1, 0, 1, 1, 1, 1;
1, 1, 1, 1, 1, 1, 0, 1, 1, 1;
1, 1, 1, 1, 1, 1, 1, 0, 1, 1;
1, 1, 1, 1, 1, 1, 1, 1, 0, 1;
1, 1, 1, 1, 1, 1, 1, 1, 1, 0];
Delta2 = [0, 1, 2, 2, 2, 2, 2, 2, 2, 2;
1, 0, 1, 2, 2, 2, 2, 2, 2, 2;
2, 1, 0, 1, 2, 2, 2, 2, 2, 2;
2, 2, 1, 0, 1, 2, 2, 2, 2, 2;
2, 2, 2, 1, 0, 1, 2, 2, 2, 2;
2, 2, 2, 2, 1, 0, 1, 2, 2, 2;
2, 2, 2, 2, 2, 1, 0, 1, 2, 2;
2, 2, 2, 2, 2, 2, 1, 0, 1, 2;
2, 2, 2, 2, 2, 2, 2, 1, 0, 1;
2, 2, 2, 2, 2, 2, 2, 2, 1, 0];
% SGD with multiclass hinge loss
% I took each row as a sample in Xtr
%Xtr = Xtr';
%ytr = ytr';
%Xte = Xte';
%yte = yte';
%[w] = train_multiclass_hinge_sgd(Xtr, ytr, Delta2);
%[ypred] = test_multiclass_hinge_sgd(w, Xte);
%yte = yte-min(yte)+1;
%count = 0;
%for i = 1:size(ypred,1)
% if yte(i)~=ypred(i)
% count = count + 1;
% end
%end
%Loss = count/size(ypred,1);
%ConfusionMatrix = confusionmat(yte , ypred);
% SGD with multiclass hinge loss with polynomial kernel
% I took each column as a sample in Xtr
[alpha, Xsv] = train_mhinge_krnel_sgd(Xtr, ytr, Delta, 5);
[ypred] = test_mhinge_kernel_sgd(alpha, Xsv, Xte, 5);
% 0-1 Loss
yte = yte-min(yte)+1;
count = 0;
for i = 1:size(ypred,2)
if yte(i)~=ypred(i)
count = count + 1;
end
end
Loss = count/size(ypred,2);
ConfusionMatrix = confusionmat(yte , ypred);