forked from ipsorakis/GeneralNetworkTools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
node_similarity.m
80 lines (71 loc) · 1.99 KB
/
node_similarity.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
74
75
76
77
78
79
80
function S = node_similarity(W,similarity_measure,parameter1,parameter2)
A = 1*(W>0);
N = size(W,1);
if ~exist('similarity_measure','var')
similarity_measure = 'donetti_munoz';
end
if strcmp(similarity_measure,'geodesic')
%% similarity by geodesic distance
S = get_node_distances(A);
S = max(max(S)) - S;
elseif strcmp(similarity_measure,'degree')
%% similarity by degree (crap)
SPs = get_node_distances(A);
S = zeros(N);
for i=1:N
for j=1:N
if i~=j
S(i,j) = degree(A,j)-degree(A,i) - SPs(i,j);
end
end
end
elseif strcmp(similarity_measure,'co-occurence')
%% similarity by co-occurences
S = zeros(N,N);
for i=1:N
for j=1:N
if i~=j
S(i,j) = W(i,j)/strength(W,j);
end
end
end
elseif strcmp(similarity_measure,'donetti_munoz')
%% Donetti Munoz method
L = get_laplacian(W);
[V D] = eig(L);
if ~exist('parameter1','var') || (exist('parameter1','var') && parameter1>N) || parameter1==-1
parameter1 = ceil(N/4);
end
M=parameter1;
%find projection space
PS = V(:,N-M+1:N);
if ~exist('parameter2','var')
parameter2='angular';
end
if strcmp(parameter2,'angular')
%angular distsance
S = PS*PS'./(repmat(sqrt(sum(PS.^2,2)),1,N).*repmat(sqrt(sum(PS.^2,2))',N,1));
S = abs(S);
else
S = zeros(N);
%eucledian distance
for i=1:N
for j=1:N
S(i,j) = norm(PS(i,:)-PS(j,:),2);
end
end
end
S(~A)=-inf;
elseif strcmp(similarity_measure,'capocci')
%% Capocci method
% get normal matrix
Normal = W./sum(sum(W));
[V D] = eig(Normal);
S = get_pearson_matrix(V);
S(~A)=-inf;
elseif strcmp(similarity_measure,'pearson')
%% Pearson
S = get_pearson_matrix(W);
S(~A)=-inf;
end
end