-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorzKPCA.m
More file actions
63 lines (53 loc) · 1.21 KB
/
orzKPCA.m
File metadata and controls
63 lines (53 loc) · 1.21 KB
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
function [A,D,C,K] = orzKPCA(X,Y,nSigma,varargin)
X = X(:,:);
[nDim,nNum] =size(X);
flgM = true;
useRFF = false;
numRandFeats = 0;
if nargin == 4
if varargin{1} == 'R'
flgM = false;
end
end
if nargin > 4
if varargin{1} == 'R'
flgM = false;
end
if varargin{2} > 0
useRFF = true;
numRandFeats = varargin{2};
end
end
% K = zeros(nNum,nNum);
if useRFF
K = cvtKernelGramMatrixRFF(X, numRandFeats, nSigma);
else
K = cvtKernelGramMatrix(X, nSigma);
end
if flgM==true
IN = ones(nNum,nNum)/nNum;
K = K - IN*K - K*IN + IN*K*IN;
end
if Y <= 1 % ��^��
cRate = Y;
[A B] = eig(K);
[B ind] = sort(diag(B),'descend');
A=A(:,ind);
D = B/nNum;
nSubDim = find(cumsum(D)/sum(D)>=cRate, 1 );
A=A(:,1:nSubDim);
B=B(1:nSubDim);
A = A/sqrt(diag(B));
%U = X*A;
D = D(1:nSubDim);
C = sum(D);
elseif Y > 1 % �听����Ԃ̎���
nSubDim = floor(Y);
OPTS.disp = 0;
[A B] = eigs(K,nSubDim,'lm',OPTS); %[A B] = eigs(K,nSubDim);
[B ind] = sort(diag(B),'descend');
A=A(:,ind);
D = B/nNum;
A = A/sqrt(diag(B));
C = sum(D);
end