neurostatx.network.metrics
Classes
| Name | Description |
|---|---|
PathLengthsMethods | Shortest-path algorithms accepted by NetworkX path-length helpers. |
Functions
| Name | Description |
|---|---|
betweennesscentrality | Compute betweenness centrality for every node. |
closenesscentrality | Compute closeness centrality for every node. |
closenessvitality | Compute closeness vitality for a single node. |
clustering | Compute the clustering coefficient for every node. |
constraint | Compute Burt's constraint for the requested nodes. |
currentflowbc | Compute current-flow betweenness centrality for every node. |
degree | Return the degree of every node. |
eccentricity | Compute eccentricity for every node. |
effectivesize | Compute effective size for the requested nodes. |
eigencentrality | Compute eigenvector centrality for every node. |
get_metrics_ops | Return the mapping of metric names to callable implementations. |
harmoniccentrality | Compute harmonic centrality for every node. |
informationcentrality | Compute information centrality for every node. |
loadcentrality | Compute load centrality for every node. |
weightedpath | Average weighted path length for a group, with a permutation p-value. |
PathLengthsMethodsclass#
class PathLengthsMethods(str, Enum)Shortest-path algorithms accepted by NetworkX path-length helpers.
BellmanFordattributeclass attributeinstance attribute#
BellmanFord = ('bellman-ford')Dijkstraattributeclass attributeinstance attribute#
Dijkstra = ('dijkstra')FloydWarshallattributeclass attributeinstance attribute#
FloydWarshall = ('floyd-warshall')FloydWarshallNumpyattributeclass attributeinstance attribute#
FloydWarshallNumpy = 'floyd-warshall-numpy'betweennesscentralityfunction#
def betweennesscentrality(graph, weight=None)Compute betweenness centrality for every node.
Parameters
Returns
scoresdict- Betweenness centrality for each node.
Examples
>>> import networkx as nx>>> from neurostatx.network.metrics import betweennesscentrality>>> betweennesscentrality(nx.path_graph(3))closenesscentralityfunction#
def closenesscentrality(graph, weight=None)Compute closeness centrality for every node.
Parameters
Returns
scoresdict- Closeness centrality for each node.
Examples
>>> import networkx as nx>>> from neurostatx.network.metrics import closenesscentrality>>> closenesscentrality(nx.path_graph(3))closenessvitalityfunction#
def closenessvitality(graph, nodes, weight=None)Compute closeness vitality for a single node.
Parameters
Returns
scorefloat- Closeness vitality of
nodes.
Examples
>>> import networkx as nx>>> from neurostatx.network.metrics import closenessvitality>>> closenessvitality(nx.path_graph(3), nodes=1)clusteringfunction#
def clustering(graph, weight=None)Compute the clustering coefficient for every node.
Parameters
Returns
scoresdict- Clustering coefficient for each node.
Examples
>>> import networkx as nx>>> from neurostatx.network.metrics import clustering>>> clustering(nx.complete_graph(4))constraintfunction#
def constraint(graph, nodes, weight=None)Compute Burt’s constraint for the requested nodes.
Parameters
Returns
scoresdict- Constraint for each requested node.
Examples
>>> import networkx as nx>>> from neurostatx.network.metrics import constraint>>> constraint(nx.path_graph(3), nodes="0 1")currentflowbcfunction#
def currentflowbc(graph, weight=None)Compute current-flow betweenness centrality for every node.
Parameters
Returns
scoresdict- Current-flow betweenness centrality for each node.
Examples
>>> import networkx as nx>>> from neurostatx.network.metrics import currentflowbc>>> currentflowbc(nx.path_graph(3))degreefunction#
def degree(graph, weight=None)Return the degree of every node.
Parameters
Returns
degreesnetworkx.DegreeView- Degree of each node.
Examples
>>> import networkx as nx>>> from neurostatx.network.metrics import degree>>> dict(degree(nx.path_graph(3))){0: 1, 1: 2, 2: 1}eccentricityfunction#
def eccentricity(graph, weight=None)Compute eccentricity for every node.
Parameters
Returns
scoresdict- Eccentricity for each node.
Examples
>>> import networkx as nx>>> from neurostatx.network.metrics import eccentricity>>> eccentricity(nx.path_graph(3))effectivesizefunction#
def effectivesize(graph, nodes, weight=None)Compute effective size for the requested nodes.
Parameters
Returns
scoresdict- Effective size for each requested node.
Examples
>>> import networkx as nx>>> from neurostatx.network.metrics import effectivesize>>> effectivesize(nx.path_graph(3), nodes="0 1")eigencentralityfunction#
def eigencentrality(graph, weight=None)Compute eigenvector centrality for every node.
Parameters
Returns
scoresdict- Eigenvector centrality for each node.
Examples
>>> import networkx as nx>>> from neurostatx.network.metrics import eigencentrality>>> eigencentrality(nx.path_graph(3))get_metrics_opsfunction#
def get_metrics_ops()Return the mapping of metric names to callable implementations.
Returns
metricsdict- Ordered mapping of metric name to function.
Examples
>>> from neurostatx.network.metrics import get_metrics_ops>>> "eigencentrality" in get_metrics_ops()Trueharmoniccentralityfunction#
def harmoniccentrality(graph, weight=None)Compute harmonic centrality for every node.
Parameters
Returns
scoresdict- Harmonic centrality for each node.
Examples
>>> import networkx as nx>>> from neurostatx.network.metrics import harmoniccentrality>>> harmoniccentrality(nx.path_graph(3))informationcentralityfunction#
def informationcentrality(graph, weight=None)Compute information centrality for every node.
Parameters
Returns
scoresdict- Information centrality for each node.
Examples
>>> import networkx as nx>>> from neurostatx.network.metrics import informationcentrality>>> informationcentrality(nx.path_graph(3))loadcentralityfunction#
def loadcentrality(graph, weight=None)Compute load centrality for every node.
Parameters
Returns
scoresdict- Load centrality for each node.
Examples
>>> import networkx as nx>>> from neurostatx.network.metrics import loadcentrality>>> loadcentrality(nx.path_graph(3))weightedpathfunction#
def weightedpath(graph, df, label_name, cohort=None, iterations=1000, weight=None, method='dijkstra', distribution=None, processes=1, verbose=False)Average weighted path length for a group, with a permutation p-value.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
graph | networkx.Graph | required | Input graph. |
df | pandas.DataFrame | required | Table of nodes. The index must match graph node labels. |
label_name | str | required | Column containing the group label. Nodes with value 0 are excluded. |
cohort | str | None | If set, restrict df to this cohort value. Defaults to None. |
iterations | int | 1000 | Number of null-distribution draws. Defaults to 1000. |
weight | str | None | Edge attribute used as weight. Defaults to None. |
method | str | 'dijkstra' | Shortest-path algorithm. Defaults to "dijkstra". |
distribution | pd.DataFrame | None | Precomputed null distribution with a label_name column. Defaults
to None. |
processes | int | 1 | Number of worker processes. Defaults to 1. |
verbose | bool | False | If True, show a progress bar. Defaults to False. |
Returns
Examples
>>> import pandas as pd>>> import networkx as nx>>> from neurostatx.network.metrics import weightedpath>>> G = nx.path_graph(4)>>> df = pd.DataFrame({"group": [1, 1, 0, 0]})>>> avg, dist, p = weightedpath(... G, df, "group", iterations=5, processes=1... )