-
Notifications
You must be signed in to change notification settings - Fork 0
/
SVM_TRAINQP.asv
70 lines (53 loc) · 1.44 KB
/
SVM_TRAINQP.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
function oplossing =SVM_TRAINQP(X,Y,epsilon,type_nummer,C,par)
% De trainingsmodule van de Vapnik SVM.
% De parameters:
% x is de matrix van de trainingssamples als kolommen van X
% y zijn de labels is van de inputvectoren in een kolom
% alpha zijn de Langrange multiplicatoren
% bias
% test arguments
tekstuitvoer=0;%imprimir
if tekstuitvoer
fprintf('Training of the SVM...\n')
fprintf('type: %s \n',type)
fprintf('de kost C %d \n',C)
switch type
case 'gaussian_rbf'
fprintf('sigma= %d \n',par1)
case 'exponential_rbf'
fprintf('sigma= %d \n',par1)
case 'polynomial'
fprintf('degree of polynomial= %d \n',par1)
end
end
N=length(X(1,:));
Aeq=Y';
beq=[0];
lb=zeros(N,1);
if C==inf
C=[];
else
ub=C*ones(N,1);
end
f=-1*ones(N,1);
% Bepaling H:
K=full(kernel2(X,[],type_nummer,par));
H=diag(Y)*K*diag(Y);
% subplot(1,2,1),contourf(K)
% colorbar
% title('Strucuur in K');
options=optimset('MaxIter',1000,'LargeScale','off');
alpha=quadprog(H,f,[],[],Aeq,beq,lb,ub,[],options);
figure(10),plot(sort(alpha)),ylabel('\alpha')
% bepalen van de bias
%********************
svi=find(abs(alpha)>epsilon);
aantalsup=length(svi);
if tekstuitvoer
fprintf('Support Vectors : %d (%3.1f%%)\n\n',aantalsup,100*aantalsup/N);
end
bias=bias_B(alpha,K,X,Y,epsilon);
clear H K;
oplossing=cell(1,2);
oplossing{1,1}=alpha;
oplossing{1,2}=bias;