-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel.m
74 lines (70 loc) · 1.59 KB
/
kernel.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
function [result] = kernel( A,method,param1)
%KERNEL calculates graph kernel from the adjacency matrix
% KCT: commute time kernel
[n,~]=size(A);
result=zeros(n);
[A,OK]=checkData(A);
switch(method)
case 'CT'
L=laplacian(A);
K=pinv(L);
case 'MD'
n = size(A,1);
P=transition(A);
P(P==0)=1/(n*n);
t=5; %t=param1;
I=eye(n);
Zt=1/t*(I-P)^(-1)*(I-P^t)*P;
K=Zt*Zt';
case 'RED'
n = size(A,1);
P=transition(A);
P(P==0)=1/(n*n);
t=1; %param1;
I=eye(n);
Zt=1/t*(I-P)^(-1)*(I-P^t)*P;
K=Zt*log(Zt')+log(Zt)*Zt';
case 'RWR'
Ds=sum(A,2);
D=diag(Ds);
a=1; %param1;
K=inv(D-a*A)*D;
case 'RW'
K=kernel(A,'RWR',0.9999);
case 'LEXP'
L=laplacian(A);
K=expm(-param1*L);
case 'EXP'
param1 = 1;
K=expm(param1*A);
case 'RL'
n = size(A,1);
I=eye(n);
L=laplacian(A);
rad = max(abs(eig(L)));
alf = 1./(2*rad);
K=inv(I+alf*L);
case 'RCT'
param1=0.9;
Ds=sum(A,2);
D=diag(Ds);
a=param1;
K=pinv(D-a*A);
case 'VND'
param1 = 0.3;
n = size(A,1);
I=eye(n);
K=inv(I-param1*A);
otherwise
disp('unknown kernel type');
end;
result(OK)=K;
result(~OK)=NaN;
function [A,OK]=checkData(A)
toKeep=sum(A~=0)>0;
OK=zeros(size(A));
A=A(toKeep,toKeep);
OK(toKeep,toKeep)=1;
OK=OK==1;
end
end