-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathRepLearnKM.m
54 lines (43 loc) · 1.89 KB
/
RepLearnKM.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
54
function [Z99per,Z98per,Z97per,Z95per,Z90per,Z85per,Z80per,Ztop20,Ztop10,Ztop5,RepLearnTime]=RepLearnKM(KM)
% Input
% KM: Kernel matrix (nxn)
% Dim: Dimensions to keep in the end over the learned representation
% Output
% Ktilde: Approximated kernel matrix (nxn)
% Z: New learned representation (nxDim)
tic;
[Q,L]=eig(KM);
eigValue=diag(L);
[~,IX]=sort(eigValue,'descend');
eigVector=Q(:,IX);
eigValue=eigValue(IX);
VarExplainedCumSum = cumsum(eigValue)/sum(eigValue);
DimFor99 = find(VarExplainedCumSum>=0.99,1);
DimFor98 = find(VarExplainedCumSum>=0.98,1);
DimFor97 = find(VarExplainedCumSum>=0.97,1);
DimFor95 = find(VarExplainedCumSum>=0.95,1);
DimFor90 = find(VarExplainedCumSum>=0.90,1);
DimFor85 = find(VarExplainedCumSum>=0.85,1);
DimFor80 = find(VarExplainedCumSum>=0.80,1);
RepLearnTime = toc;
Z99per = CheckNaNInfComplex( eigVector(:,1:DimFor99)*sqrt(diag(eigValue(1:DimFor99))) );
Z98per = CheckNaNInfComplex( eigVector(:,1:DimFor98)*sqrt(diag(eigValue(1:DimFor98))) );
Z97per = CheckNaNInfComplex( eigVector(:,1:DimFor97)*sqrt(diag(eigValue(1:DimFor97))) );
Z95per = CheckNaNInfComplex( eigVector(:,1:DimFor95)*sqrt(diag(eigValue(1:DimFor95))) );
Z90per = CheckNaNInfComplex( eigVector(:,1:DimFor90)*sqrt(diag(eigValue(1:DimFor90))) );
Z85per = CheckNaNInfComplex( eigVector(:,1:DimFor85)*sqrt(diag(eigValue(1:DimFor85))) );
Z80per = CheckNaNInfComplex( eigVector(:,1:DimFor80)*sqrt(diag(eigValue(1:DimFor80))) );
Ztop20 = CheckNaNInfComplex( eigVector(:,1:20)*sqrt(diag(eigValue(1:20))) );
Ztop10 = CheckNaNInfComplex( eigVector(:,1:10)*sqrt(diag(eigValue(1:10))) );
Ztop5 = CheckNaNInfComplex( eigVector(:,1:5)*sqrt(diag(eigValue(1:5))) );
end
function Z = CheckNaNInfComplex(Z)
for i=1:size(Z,1)
for j=1:size(Z,2)
if (isnan(Z(i,j)) || isinf(Z(i,j)) || ~isreal(Z(i,j)))
Z(i,j)=0;
disp('ERROR ON REPRESENTATION');
end
end
end
end