-
Notifications
You must be signed in to change notification settings - Fork 1
/
DepthCoefficients.py
executable file
·77 lines (50 loc) · 2.07 KB
/
DepthCoefficients.py
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
import numpy as np
import networkx as nx
def max_SP_of_single_modality(Graphs_m):
"""
Find the maximum of shortest path for the m-th modality ("Graphs_m").
The result is the average of maximum shortest paths found in each graph-i of "Graphs_m"
Parameters:
----------
Graphs_m : Graphs of single modality (m) with shape (N_m, n_m, n_m)
Return:
-------
out : float,
average of the maximums of shortest paths calculated for each graph in "Graphs_m".
"""
max_list = []
for graph_i in Graphs_m:
G = nx.from_numpy_matrix(graph_i)
SP = list(dict(nx.all_pairs_dijkstra_path_length(G)).values())
SP = np.array([np.array(list(SP[i].values())) for i in range(len(SP))])
Max_of_SP = np.max(SP[:,-1])
max_list.append(Max_of_SP)
avg_max = np.mean(max_list)
return avg_max
def max_SP(All_Graphs):
"""
Find the maximums of shortest paths for all M modalities in "All_Graphs".
These values will be used in "depth coefficient" calculations in DB based alignment.
Parameters:
----------
All_Graphs : list, tuple, array. If it is list/tuple, it must contain M distinct modalities,
each has shape (N_m, n_m, n_m). If it is array, it must be a single modality with shape (N_m, n_m, n_m).
Return:
-------
out : list of maximum shortest paths (floats), each for a corresponding modality, if "All_Graphs" is list/tuple of modalities
or single maximum shortest path (float), if "All_Graphs" consists of single modality.
"""
if isinstance(All_Graphs, np.ndarray):
if len(All_Graphs.shape)==3:
maxSP = max_SP_of_single_modality(All_Graphs)
return maxSP
else:
raise ValueError('Input parameter "All_Graphs" is not in the correct format!!')
elif isinstance(All_Graphs, (tuple, list)):
if len(All_Graphs[0].shape)==3:
maxSP = [max_SP_of_single_modality(Graphs_m) for Graphs_m in All_Graphs]
return np.array(maxSP)
else:
raise ValueError('Input parameter "All_Graphs" is not in the correct format!!')
else:
raise ValueError('Input parameter "All_Graphs" is ambiguous.')