-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkmeansKPCA.m
More file actions
44 lines (39 loc) · 1.04 KB
/
kmeansKPCA.m
File metadata and controls
44 lines (39 loc) · 1.04 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
function [A,D,C,K] = kmeansKPCA(X,Lc,Y,nSigma,varargin)
useRFF = false;
numRandFeats = 0;
X = X(:,:);
[nDim,nNum] =size(X);
if nargin > 4 && strcmp(varargin{1},'RFF') && isnumeric(varargin{2})
useRFF = true;
numRandFeats = varargin{2};
end
if useRFF
Kt = cvtKernelGramMatrixRFF(X, numRandFeats, nSigma);
else
Kt = cvtKernelGramMatrix(X, nSigma);
end
K = diag(sqrt(Lc))*Kt*diag(sqrt(Lc));
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));
D = D(1:nSubDim);
C = sum(D);
elseif Y > 1 % Žå¬•ª‹ó�?��?ÌŽŸŒ³
nSubDim = floor(Y);
%[A B] = eigs(K,nSubDim);
OPTS.disp = 0;
size(K);
[A B] = eigs(K,nSubDim,'lm',OPTS); %[A B] = eigs(K,nSubDim);
[B ind] = sort(diag(B),'descend');
A=A(:,ind);
D = B/sum(Lc);
A = A/sqrt(diag(B));
C = sum(D);
end