-
Notifications
You must be signed in to change notification settings - Fork 0
/
trainSVM.m
55 lines (44 loc) · 1.12 KB
/
trainSVM.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
function [alphas,b]=trainSVM(Kern,Cslack, trainLabels)
% K = kernel(trainPoints,trainPoints);
% c = margin
%TRAINSVM Summary of this function goes here
% Detailed explanation goes here
%main function
global K E B Alphas Labels Eps C;
Labels = trainLabels;
K = Kern;
C = Cslack;
%precision point
Eps = 10^(-3);
% equivalent to size(Labels,2)
dataSetSize = length(Labels);
B = 0;
Alphas = zeros(dataSetSize,1);
% set error to be the worst, so it will be improved
%FIXME: does this work?
E = -Labels;
numChanged = 0;
examineAll = 1;
while numChanged >0 || examineAll
numChanged = 0;
if (examineAll)
% loop over all training examples
for i=1:length(Labels)
numChanged = numChanged + examineExample(i);
end
else
% loop over examples where alpha is not 0 and not C
for i=1:length(Labels)
if (Alphas(i)> 0 && Alphas(i) < C)
numChanged = numChanged + examineExample(i);
end
end
end
if (examineAll == 1)
examineAll = 0;
elseif (numChanged == 0)
examineAll = 1;
end
end
b = B;
alphas = Alphas;