-
Notifications
You must be signed in to change notification settings - Fork 81
/
demo_DR_Contirbution.m
52 lines (44 loc) · 1.3 KB
/
demo_DR_Contirbution.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
%{
Demonstration of dimensionality reduction using KPCA.
%}
clc
clear all
close all
addpath(genpath(pwd))
load('.\data\TE.mat', 'trainData')
kernel = Kernel('type', 'gaussian', 'gamma', 1/128^2);
%% case 1
%{
The number of components is determined by the given explained level.
The given explained level should be 0 < explained level < 1.
For example, when explained level is set to 0.75, the parameter should
be set as:
parameter = struct('numComponents', 0.75, ...
'kernelFunc', kernel);
%}
parameter = struct('numComponents', 0.75, ...
'kernelFunc', kernel);
% build a KPCA object
kpca = KernelPCA(parameter);
% train KPCA model
kpca.train(trainData);
% Visualization
kplot = KernelPCAVisualization();
kplot.cumContribution(kpca)
%% case 2
%{
The number of components is determined by the given number.
For example, when the given number is set to 24, the parameter should
be set as:
parameter = struct('numComponents', 24, ...
'kernelFunc', kernel);
%}
parameter = struct('numComponents', 24, ...
'kernelFunc', kernel);
% build a KPCA object
kpca = KernelPCA(parameter);
% train KPCA model
kpca.train(trainData);
% Visualization
kplot = KernelPCAVisualization();
kplot.cumContribution(kpca)