-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathdemo_ParameterOptimization.m
More file actions
42 lines (35 loc) · 1013 Bytes
/
demo_ParameterOptimization.m
File metadata and controls
42 lines (35 loc) · 1013 Bytes
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
%{
Demonstration of SVDD parameter optimization.
%}
clc
close all
addpath(genpath(pwd))
ocdata = BinaryDataset();
ocdata.generate;
[trainData, trainLabel, testData, testLabel] = ocdata.partition;
% set parameter
cost = 0.9;
kernel = BaseKernel('type', 'gaussian', 'gamma', 1.5);
% optimization setting
opt.method = 'pso'; % bayes, ga pso
opt.variableName = { 'cost', 'gamma'};
opt.variableType = {'real', 'real'}; % 'integer' 'real'
opt.lowerBound = [10^-2, 2^-6];
opt.upperBound = [10^0, 2^6];
opt.maxIteration = 20;
opt.points = 3;
opt.display = 'on';
svddParameter = struct('cost', cost, ...
'kernelFunc', kernel, ...
'optimization', opt, ...
'KFold', 5);
% creat an SVDD object
svdd = BaseSVDD(svddParameter);
% train SVDD model
svdd.train(trainData, trainLabel);
% test SVDD model
results = svdd.test(testData, testLabel);
% Visualization
svplot = SvddVisualization();
svplot.boundary(svdd);
svplot.distance(svdd, results);