forked from iqiukp/RVM-MATLAB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_optimization_kernel.m
72 lines (58 loc) · 2.06 KB
/
demo_optimization_kernel.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
% demo: optimize the kernel parameters
clc
clear all
close all
addpath(genpath(pwd))
load UCI_data
%{
------------------------------------------------------------------------
Notice:
training samples
x sample data (input, n*d)
n: number of samples
d: number of features
y sample data (ouput, n*1)
n: number of samples
test samples
xt sample data (input, n*d)
n: number of samples
d: number of features
yt sample data (ouput, n*1)
n: number of samples
------------------------------------------------------------------------
%}
% kernel function
kernel = Kernel('type', 'gauss', 'width', 2);
%{
------------------------------------------------------------------------
Notice:
'method' 'pso' or 'ga'
'target' name of the kernel that need to be optimized
single kernel: {{kernel}}
hybrid kernel: {{kernel_1, kernel_2}}
'lb' lower boundary of parameters
'ub' upper boundary of parameters
'numVariable' number of parameters that need to be optimized
'maxIter' max iterations
optional
'Kfolds' K fold cross validation
------------------------------------------------------------------------
%}
optimization = struct('method', 'ga',...
'target', {{kernel}},...
'lb', 2^-6,...
'ub', 2^6,...
'numVariable', 1,...
'maxIter', 10,...
'Kfolds', 5);
% parameter setting
parameter = struct( 'freeBasis', 'on',...
'display', 'on',...
'maxIter', 1000,...
'kernel', kernel,...
'optimization', optimization);
% RVM model training, testing, and visualization
rvm = RVM(parameter);
rvm.train(x, y);
rvm.test(xt, yt);
rvm.draw