-
Notifications
You must be signed in to change notification settings - Fork 21
/
KPCA_proj.m
53 lines (39 loc) · 1.13 KB
/
KPCA_proj.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
function [X_Train_PCAProj,X_Test_PCAProj] = KPCA_proj(X_Train, X_Test, Dim)
% addpath('.\KEDcode')
% addpath('.\drtoolbox\techniques')
% %
% options.KernelType = 'Gaussian';
% %Sigma = 1;
%
%
data=[X_Train X_Test]'; %NoSample *NoFeature
%
%
% %KPCA: Project Testing data and training data together
% options.t = 1;
% options.ReducedDim=Dim;
%
addpath('.\KEDcode')
options.KernelType = 'Polynomial';
options.d= 2;
[eigvector, ~,K] = KPCA(data, options,Dim);
%
%
X_PCA_Proj= K * eigvector;
%[mappedX, mapping] = kernel_pca(X, no_dims, kernel, param1, param2)
%[X_PCA_Proj, ~] = kernel_pca(data, Dim,'poly',1,2);
X_Train_PCAProj=X_PCA_Proj(1:size(X_Train,2),:);
X_PCA_Proj(1:size(X_Train,2),:)=[];
X_Test_PCAProj=X_PCA_Proj;
end
%%
%------------------example
% options.KernelType = 'Gaussian';
% options.t = 1;
% options.ReducedDim = 4;
% fea = rand(7,10); %7sample,10 dimension
% [eigvector,eigvalue] = KPCA(fea,options);
%
% feaTest = rand(3,10);
% Ktest = constructKernel(feaTest,fea,options)
% Y = Ktest*eigvector;