-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNetworkDistance.py
More file actions
24 lines (18 loc) · 786 Bytes
/
Copy pathNetworkDistance.py
File metadata and controls
24 lines (18 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import numpy as np
def Dist(strengthmap1,strengthmap2,seed=1):
"""
This function computes a normalised network distance
measure between two complex networks. The two inputs,
'strengthmap1' and 'strengthmap2' are assumed to be
both 2D arrays where each grid cell contains the
network strength value of the node in which that cell
belongs. The function then returns a float value.
"""
np.random.seed(seed)
strengthmap1[np.isnan(strengthmap1)] = 0
strengthmap2[np.isnan(strengthmap2)] = 0
d_metric = np.abs(strengthmap1-strengthmap2).sum()
shuffle1 = np.random.permutation(strengthmap1.ravel())
shuffle2 = np.random.permutation(strengthmap2.ravel())
d_metric_random = np.abs(shuffle1-shuffle2).sum()
return 1 - d_metric/d_metric_random