-
Notifications
You must be signed in to change notification settings - Fork 36
/
NystromMatrixDictionary.m
48 lines (36 loc) · 1.13 KB
/
NystromMatrixDictionary.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
function [AbsFroError,RelFroError,NormFroError] = NystromMatrixDictionary(KM, X, Dictionary, gamma)
% KM: nXn kernel matrix, where n # of time series of m length
% Dictionary: kxm matrxi containing the dictionary atoms
% Absolute and Relative errors for Nystrom Approximation
[nrowsX, ncolumnsX] = size(X);
[nrowsDic, ncolumnsDic] = size(Dictionary);
W = zeros(nrowsDic,nrowsDic);
for i=1:nrowsDic
for j=1:nrowsDic
W(i,j) = SINK(Dictionary(i,:),Dictionary(j,:),gamma);
end
end
E = zeros(nrowsX,nrowsDic);
for i=1:nrowsX
for j=1:nrowsDic
E(i,j) = SINK(X(i,:),Dictionary(j,:),gamma);
end
end
[Ve, Va] = eig(W);
va = diag(Va);
inVa = diag(va.^(-0.5));
Zexact = CheckNaNInfComplex( E * Ve * inVa );
KMtilde = Zexact*Zexact';
AbsFroError = ( norm(KM-KMtilde,'fro') );
RelFroError = ( norm(KM-KMtilde,'fro')/norm(KM,'fro') );
NormFroError = ( norm(KM-KMtilde,'fro')/nrowsX^2);
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;
end
end
end
end