-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrainKernel.m
43 lines (32 loc) · 1.65 KB
/
TrainKernel.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
function [Y2hat,results,model] = TrainKernel(K,K2,Y,Y2,D,p,gamma,e,C,regression)
if strcmpi(regression,'l2')
H = K + gamma*eye(size(K));
model = H\Y(p+1:end-D);
Y2hat = K2*model;
elseif strcmpi(regression,'eps')
% -----------------------------------------------------------------------------
% Training
% -----------------------------------------------------------------------------
H = K; % Standard SVR
model = svmtrain(Y(p+1:end-D),H,['-t 4 -s 3 -c ' num2str(C) ' -p ' num2str(e)]);
% -----------------------------------------------------------------------------
% Testing
% -----------------------------------------------------------------------------
H2 = K2; % Standard SVR
[Y2hat,mse,dec] = svmpredict(Y2(p+1:end-D),H2,model);
elseif strcmpi(regression,'ehuber')
% -----------------------------------------------------------------------------
% Training
% -----------------------------------------------------------------------------
H = K + gamma*eye(size(K));
model = svmtrain(Y(p+1:end-D),H,['-t 4 -s 3 -c ' num2str(C) ' -p ' num2str(e)]);
% -----------------------------------------------------------------------------
% Testing
% -----------------------------------------------------------------------------
H2 = K2;
Y2hat = svmpredict(Y2(p+1:end-D),H2,model);
end;
% --------------------------------------------------------------------------------------------------------------------------
% Results in test
% --------------------------------------------------------------------------------------------------------------------------
results = ComputeResults(Y2hat,Y2(p+1:end-D));