-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathdemo_ObservationWeight.m
More file actions
38 lines (32 loc) · 930 Bytes
/
demo_ObservationWeight.m
File metadata and controls
38 lines (32 loc) · 930 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
%{
Demonstration of observation-weighted SVDD model.
%}
clc
close all
addpath(genpath(pwd))
% generate dataset
ocdata = BinaryDataset();
ocdata.generate;
[trainData, trainLabel, testData, testLabel] = ocdata.partition;
% set parameter
cost = 0.9;
kernel = BaseKernel('type', 'gaussian', 'gamma', 1.5);
%{
Here, 'weight' is just used as an example, you can define a
weight vector (m*1). The size of 'weigh' should be m×1,
where m is the number of training samples.
%}
weight = rand(size(trainData, 1), 1);
svddParameter = struct('cost', cost, ...
'kernelFunc', kernel, ...
'weight', weight);
% 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);