-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexperiments.m
More file actions
59 lines (51 loc) · 1.67 KB
/
Copy pathexperiments.m
File metadata and controls
59 lines (51 loc) · 1.67 KB
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
function [] = experiments(Xtr, ytr, Xte, yte, pk, rk)
% LDA
[W, mi] = LDA(Xtr, ytr);
yy = nearest_neighbor(W * Xte, W * mi);
fprintf('LDA: %.2f%%\n', sum(yy == yte) / numel(yte) * 100);
% LDA then SVM
XW = W * Xtr;
Q = multi_SVM_DC(XW, ytr, 10, 0);
XWte = W * Xte;
yy = argmax(Q * XWte);
fprintf('LDA/SVM: %.2f%%\n', sum(yy == yte) / numel(yte) * 100);
% SVM
Q = multi_SVM_DC(Xtr, ytr, 10, 0);
yy = argmax(Q * Xte);
fprintf('SVM: %.2f%%\n', sum(yy == yte) / numel(yte) * 100);
% Random projection then SVM
R = rand_proj(size(Xtr, 1), rk);
XR = R * Xtr;
Q = multi_SVM_DC(XR, ytr, 10, 0);
XRte = R * Xte;
yy = argmax(Q * XRte);
fprintf('RND/SVM: %.2f%%\n', sum(yy == yte) / numel(yte) * 100);
% Random projection then LDA
[W, mi] = LDA(XR, ytr);
yy = nearest_neighbor(W * XRte, W * mi);
fprintf('RND/LDA: %.2f%%\n', sum(yy == yte) / numel(yte) * 100);
% PCA then SVM
[P, m] = PCA(Xtr, pk);
XP = P * bsxfun(@minus, Xtr, m);
Q = multi_SVM_DC(XP, ytr, 10, 0);
XPte = P * bsxfun(@minus, Xte, m);
yy = argmax(Q * XPte);
fprintf('PCA/SVM: %.2f%%\n', sum(yy == yte) / numel(yte) * 100);
% PCA then LDA
[W, mi] = LDA(XP, ytr);
yy = nearest_neighbor(W * XPte, W * mi);
fprintf('PCA/LDA: %.2f%%\n', sum(yy == yte) / numel(yte) * 100);
% Random projection then LDA then SVM
[W, mi] = LDA(XR, ytr);
XW = W * XR;
Q = multi_SVM_DC(XW, ytr, 10, 0);
XWte = W * XRte;
yy = argmax(Q * XWte);
fprintf('RND/LDA/SVM: %.2f%%\n', sum(yy == yte) / numel(yte) * 100);
% PCA then LDA then SVM
[W, mi] = LDA(XP, ytr);
XW = W * XP;
Q = multi_SVM_DC(XW, ytr, 10, 0);
XWte = W * XPte;
yy = argmax(Q * XWte);
fprintf('PCA/LDA/SVM: %.2f%%\n', sum(yy == yte) / numel(yte) * 100);