Content¶
-
nngt.analysis.
adjacency_matrix
(graph, types=True, weights=True)[source]¶ Adjacency matrix of the graph.
Parameters: - graph (
Graph
or subclass) – Network to analyze. - types (bool, optional (default: True)) – Whether the excitatory/inhibitory type of the connnections should be considered (only if the weighing factor is the synaptic strength).
- weights (bool or string, optional (default: True)) – Whether weights should be taken into account; if True, then connections are weighed by their synaptic strength, if False, then a binary matrix is returned, if weights is a string, then the ponderation is the correponding value of the edge attribute (e.g. “distance” will return an adjacency matrix where each connection is multiplied by its length).
Returns: a
csr_matrix
.- graph (
-
nngt.analysis.
assortativity
(graph, deg_type='total')[source]¶ Assortativity of the graph.
Parameters: - graph (
Graph
or subclass) – Network to analyze. - deg_type (string, optional (default: ‘total’)) – Type of degree to take into account (among ‘in’, ‘out’ or ‘total’).
Returns: a float quantifying the graph assortativity.
- graph (
-
nngt.analysis.
betweenness_distrib
(graph, use_weights=True, nodes=None, num_nbins=None, num_ebins=None, log=False)[source]¶ Betweenness distribution of a graph.
Parameters: - graph (
Graph
or subclass) – the graph to analyze. - use_weights (bool, optional (default: True)) – use weighted degrees (do not take the sign into account : all weights are positive).
- nodes (list or numpy.array of ints, optional (default: all nodes)) – Restrict the distribution to a set of nodes (only impacts the node attribute).
- log (bool, optional (default: False)) – use log-spaced bins.
Returns: - ncounts (
numpy.array
) – number of nodes in each bin - nbetw (
numpy.array
) – bins for node betweenness - ecounts (
numpy.array
) – number of edges in each bin - ebetw (
numpy.array
) – bins for edge betweenness
- graph (
-
nngt.analysis.
closeness
(graph, nodes=None, use_weights=False)[source]¶ Return the closeness centrality for each node in nodes.
Parameters: - graph (
Graph
object) – Graph to analyze. - nodes (array-like container with node ids, optional (default = all nodes)) – Nodes for which the local clustering coefficient should be computed.
- use_weights (bool, optional (default: False)) – Whether weighted closeness should be used.
- graph (
-
nngt.analysis.
clustering
(graph)[source]¶ Global clustering coefficient of the graph, defined as
\[c = 3 \times \frac{\text{triangles}}{\text{connected triples}}\]
-
nngt.analysis.
degree_distrib
(graph, deg_type='total', node_list=None, use_weights=False, log=False, num_bins=30)[source]¶ Degree distribution of a graph.
Parameters: - graph (
Graph
or subclass) – the graph to analyze. - deg_type (string, optional (default: “total”)) – type of degree to consider (“in”, “out”, or “total”).
- node_list (list or numpy.array of ints, optional (default: None)) – Restrict the distribution to a set of nodes (default: all nodes).
- use_weights (bool, optional (default: False)) – use weighted degrees (do not take the sign into account: all weights are positive).
- log (bool, optional (default: False)) – use log-spaced bins.
Returns: - counts (
numpy.array
) – number of nodes in each bin - deg (
numpy.array
) – bins
- graph (
-
nngt.analysis.
local_clustering
(graph, nodes=None)[source]¶ Local clustering coefficient of the nodes, defined as
\[c_i = 3 \times \frac{\text{triangles}}{\text{connected triples}}\]Parameters: - graph (
Graph
object) – Graph to analyze. - nodes (array-like container with node ids, optional (default = all nodes)) – Nodes for which the local clustering coefficient should be computed.
- graph (
-
nngt.analysis.
node_attributes
(network, attributes, nodes=None)[source]¶ Return node attributes for a set of nodes.
Parameters: - network (
Graph
) – The graph where the nodes belong. - attributes (str or list) – Attributes which should be returned, among: * “betweenness” * “clustering” * “in-degree”, “out-degree”, “total-degree” * “subgraph_centrality”
- nodes (list, optional (default: all nodes)) – Nodes for which the attributes should be returned.
Returns: values (array-like or dict) – Returns the attributes, either as an array if only one attribute is required (attributes is a
str
) or as adict
of arrays.- network (
-
nngt.analysis.
num_scc
(graph, listing=False)[source]¶ Returns the number of strongly connected components, i.e. ensembles where all nodes inside the ensemble can reach any other node in the ensemble using the directed edges.
See also
-
nngt.analysis.
num_wcc
(graph, listing=False)[source]¶ Connected components if the directivity of the edges is ignored (i.e. all edges are considered as bidirectional).
See also
-
nngt.analysis.
reciprocity
(graph)[source]¶ Graph reciprocity, defined as \(E^\leftrightarrow/E\), where \(E^\leftrightarrow\) and \(E\) are, respectively, the number of bidirectional edges and the total number of edges in the graph.
Returns: a float quantifying the reciprocity.
-
nngt.analysis.
spectral_radius
(graph, typed=True, weighted=True)[source]¶ Spectral radius of the graph, defined as the eigenvalue of greatest module.
Parameters: - graph (
Graph
or subclass) – Network to analyze. - typed (bool, optional (default: True)) – Whether the excitatory/inhibitory type of the connnections should be considered.
- weighted (bool, optional (default: True)) – Whether the weights should be taken into account.
Returns: the spectral radius as a float.
- graph (
-
nngt.analysis.
subgraph_centrality
(graph, weights=True, normalize='max_centrality')[source]¶ Subgraph centrality, accordign to [Estrada2005], for each node in the graph.
[Estrada2005]: Ernesto Estrada and Juan A. Rodríguez-Velázquez, Subgraph centrality in complex networks, PHYSICAL REVIEW E 71, 056103 (2005), available on ArXiv.
Parameters: - graph (
Graph
or subclass) – Network to analyze. - weights (bool or string, optional (default: True)) – Whether weights should be taken into account; if True, then connections are weighed by their synaptic strength, if False, then a binary matrix is returned, if weights is a string, then the ponderation is the correponding value of the edge attribute (e.g. “distance” will return an adjacency matrix where each connection is multiplied by its length).
- normalize (str, optional (default: “max_centrality”)) – Whether the centrality should be normalized. Accepted normalizations are “max_eigenvalue” and “max_centrality”; the first rescales the adjacency matrix by the its largest eigenvalue before taking the exponential, the second sets the maximum centrality to one.
Returns: centralities (
numpy.ndarray
) – The subgraph centrality of each node.- graph (