brainconn.distance
.distance_wei¶
-
distance_wei
(G)[source]¶ The distance matrix contains lengths of shortest paths between all pairs of nodes. An entry (u,v) represents the length of shortest path from node u to node v. The average shortest path length is the characteristic path length of the network.
Parameters: L (NxN numpy.ndarray
) – Directed/undirected connection-length matrix. NB L is not the adjacency matrix. See below.Returns: - D (NxN
numpy.ndarray
) – distance (shortest weighted path) matrix - B (NxN
numpy.ndarray
) – matrix of number of edges in shortest weighted path
Notes
The input matrix must be a connection-length matrix, typically
obtained via a mapping from weight to length. For instance, in a weighted correlation network higher correlations are more naturally interpreted as shorter distances and the input matrix should consequently be some inverse of the connectivity matrix.
The number of edges in shortest weighted paths may in generalexceed the number of edges in shortest binary paths (i.e. shortest paths computed on the binarized connectivity matrix), because shortest weighted paths have the minimal weighted distance, but not necessarily the minimal number of edges.
Lengths between disconnected nodes are set to Inf. Lengths on the main diagonal are set to 0.Algorithm: Dijkstra’s algorithm.
- D (NxN