medusa.graph_theory package
Submodules
medusa.graph_theory.assortativity module
- medusa.graph_theory.assortativity.assortativity(W, mode)[source]
Calculates the assortativity, which is a preference of nodes to attach to other nodes that are somehow similar to them
- Parameters
W (numpy 2D matrix) – Graph matrix. ChannelsXChannels.
mode (string) – GPU or CPU
- Returns
global_assort – Global assortativity
- Return type
numpy array
medusa.graph_theory.betweeenness_centrality module
- medusa.graph_theory.betweeenness_centrality.betweenness(W, norm=True)[source]
Calculates the betweenness centrality of the graph, which is the probability that node i belong to one of the network shortest paths
Note: W must be converted to a connection-length matrix. It is common to obtain it via mapping from weight to length. BC is normalised to the range [0 1] as BC/[(N-1)(N-2)]
- Parameters
W (numpy 2D matrix) – Graph matrix. ChannelsXChannels.
norm (bool) – Normalisation. 0 = no, 1 = yes. Default = True
- Returns
BC – Network betweenness centrality.
- Return type
numpy array
medusa.graph_theory.clustering_coefficient module
medusa.graph_theory.complexity module
medusa.graph_theory.degree module
medusa.graph_theory.density module
medusa.graph_theory.efficiency module
- medusa.graph_theory.efficiency.efficiency(W)[source]
Calculates the graph efficiency. Globally is the mean of the inverse shortests path length, and is inversely related to path length. Nodally/Locally is the same as globally but calculated on the neighbourhood of the node, and is related with clustering coefficient.
- Parameters
W (numpy 2D matrix) – Graph matrix. ChannelsXChannels.
- Returns
global_eff (numpy array) – Global efficiency.
nodal_eff (numpy array) – Nodal/Local efficiency.
medusa.graph_theory.eigen_centrality module
- medusa.graph_theory.eigen_centrality.eigen_centrality(W)[source]
Calculates the eigenvector centrality, which is a centrality measure based on the adjacency matrix eigenvectors
- Parameters
W (numpy 2D matrix) – Graph matrix. ChannelsXChannels.
mode (string) – GPU or CPU
- Returns
nodal_eig – Nodal eigenvector centrality
- Return type
numpy array
medusa.graph_theory.modularity module
- medusa.graph_theory.modularity.modularity(W, gamma)[source]
Calculates the optimal node comunity and the modularity
Note: The optimal community structure subdivides the network in groups of nodes (non-overlapping), maximizing withing-groups edges while minimising between-groups edges. Modularity quantifies the degree to which the graph could be subdivided into the aforementioned communities
- Parameters
W (numpy 2D matrix) – Graph matrix. ChannelsXChannels.
gamma (float) –
- modularity resolution parameter
gamma>1 smaller modules 0<=gamma<1 larger modules gamma=1 (default) classic modularity function
- Returns
Q (int) – Network modularity.
Ci (numpy array) – Network communities.
medusa.graph_theory.participation_coefficient module
- medusa.graph_theory.participation_coefficient.participation_coefficient(W)[source]
Calculates the participation coefficient, which is the diversity of the between-module connections of each node
- Parameters
W (numpy 2D matrix) – Graph matrix. ChannelsXChannels.
- Returns
nodal_part – Nodal participation coefficient.
- Return type
numpy array
medusa.graph_theory.path_length module
- medusa.graph_theory.path_length.path_length(W, diagonal_dist=None, infinite_dist=None)[source]
Calculates the path length and other graph integration parameters
Note: L must be a connection-length matrix. One way of generating it is the inverse of the weight matrix.
- Parameters
W (numpy 2D matrix) – Graph matrix. ChannelsXChannels.
- Returns
global_pl (int) – Path lenght.
efficiency (int) – Network efficiency.
nodal_ecc (numpy array) – Network eccentricity.
radius (int) – Network radius.
diameter (int) – Network diameter.
nodal_d (numpy 2D matrix) – Shortest distances matrix.
medusa.graph_theory.surrogate_graph module
medusa.graph_theory.transitivity module
- medusa.graph_theory.transitivity.transitivity(W, mode)[source]
Calculates the transitivity, which is the number of triangles divided by the number of triples.
- Parameters
W (numpy 2D matrix) – Graph matrix. ChannelsXChannels.
mode (string) – GPU or CPU
- Returns
global_trans – Global transitivity.
- Return type
int