-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain_psvm_2v.m
54 lines (50 loc) · 1.67 KB
/
train_psvm_2v.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 model=train_psvm_2v(x,x2,y,kerType,Ca,Cb,D,gamma,gamma4psvm)
epsilon=0.001;
model.kerType=kerType;
model.gamma=gamma;
[~,~] = size(x);
[n,~] =size(x2);
x=[x,ones(n,1)];
x2=[x2,ones(n,1)];
options = optimset;
options.LargeScale = 'off';
options.Display = 'off';
temp1=kernel(x,x,kerType,gamma);
temp2=(1/gamma4psvm)*kernel(x2,x2,kerType,gamma);
tempy=ones(n,1)*y';
A1=(y*y').*temp1;
A2=tempy.*temp1;
A3=(y*y').*temp2;
A4=tempy.*temp2;
A5=temp1+temp2;
A6=temp2;
A7=temp1;
H=[A1,zeros(n,n),-A2',A2',zeros(n,n),-A1;
zeros(n,n),A3,A4',-A4',-A3,zeros(n,n);
-A2,A4,A5,-A5',-A4,A2;
A2,-A4,-A5,A5,A4,-A2;
zeros(n,n),-A3,-A4',A4',A3,zeros(n,n);
-A1,zeros(n,n),A2',-A2',zeros(n,n),A1];
f=[-ones(2*n,1);epsilon*ones(2*n,1);zeros(2*n,1)];
A = [eye(n),zeros(n,3*n),eye(n),zeros(n,n);
zeros(n,n),eye(n),zeros(n,3*n),eye(n);
zeros(n,2*n),eye(n),eye(n),zeros(n,2*n)];
b = [Ca*ones(n,1);Cb*ones(n,1);D*ones(n,1)];
lb = zeros(6*n,1);
ub = [Ca*ones(n,1);Cb*ones(n,1);D*ones(2*n,1);Ca*ones(n,1);Cb*ones(n,1)];
a0 = zeros(6*n,1);
options.Algorithm='interior-point-convex';
[a] = quadprog(H,f,A,b,[],[],lb,[],a0,options);
alpha_a=a(1:n);
alpha_b=a(n+1:2*n);
beta_a=a(2*n+1:3*n);
beta_b=a(3*n+1:4*n);
lamda_a=a(4*n+1:5*n);
lamda_b=a(5*n+1:6*n);
model.Wa=beta_b-beta_a+alpha_a.*y-lamda_b.*y;
model.Wb=(1/gamma4psvm)*(beta_a-beta_b+alpha_b.*y-lamda_a.*y);
model.x=x;
model.x2=x2;
model.y=y;
model.gamma4psvm=gamma4psvm;
end