Skip to content

neurostatx.network.metrics

Classes

NameDescription
PathLengthsMethodsShortest-path algorithms accepted by NetworkX path-length helpers.

Functions

NameDescription
betweennesscentralityCompute betweenness centrality for every node.
closenesscentralityCompute closeness centrality for every node.
closenessvitalityCompute closeness vitality for a single node.
clusteringCompute the clustering coefficient for every node.
constraintCompute Burt's constraint for the requested nodes.
currentflowbcCompute current-flow betweenness centrality for every node.
degreeReturn the degree of every node.
eccentricityCompute eccentricity for every node.
effectivesizeCompute effective size for the requested nodes.
eigencentralityCompute eigenvector centrality for every node.
get_metrics_opsReturn the mapping of metric names to callable implementations.
harmoniccentralityCompute harmonic centrality for every node.
informationcentralityCompute information centrality for every node.
loadcentralityCompute load centrality for every node.
weightedpathAverage weighted path length for a group, with a permutation p-value.

PathLengthsMethodsclass#

class PathLengthsMethods(str, Enum)

Bases: 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

NameTypeDefaultDescription
graphnetworkx.GraphrequiredInput graph.
weightstrNoneEdge attribute used as weight. Defaults to None.

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

NameTypeDefaultDescription
graphnetworkx.GraphrequiredInput graph.
weightstrNoneEdge attribute used as distance. Defaults to None.

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

NameTypeDefaultDescription
graphnetworkx.GraphrequiredInput graph.
nodesstrrequiredNode identifier passed to NetworkX as node.
weightstrNoneEdge attribute used as weight. Defaults to None.

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

NameTypeDefaultDescription
graphnetworkx.GraphrequiredInput graph.
weightstrNoneEdge attribute used as weight. Defaults to None.

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

NameTypeDefaultDescription
graphnetworkx.GraphrequiredInput graph.
nodesstrrequiredSpace-separated node identifiers.
weightstrNoneEdge attribute used as weight. Defaults to None.

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

NameTypeDefaultDescription
graphnetworkx.GraphrequiredInput graph.
weightstrNoneEdge attribute used as weight. Defaults to None.

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

NameTypeDefaultDescription
graphnetworkx.GraphrequiredInput graph.
weightstrNoneEdge attribute used as weight. Defaults to None.

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

NameTypeDefaultDescription
graphnetworkx.GraphrequiredInput graph.
weightstrNoneEdge attribute used as weight. Defaults to None.

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

NameTypeDefaultDescription
graphnetworkx.GraphrequiredInput graph.
nodesstrrequiredSpace-separated node identifiers.
weightstrNoneEdge attribute used as weight. Defaults to None.

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

NameTypeDefaultDescription
graphnetworkx.GraphrequiredInput graph.
weightstrNoneEdge attribute used as weight. Defaults to None.

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()
True

harmoniccentralityfunction#

def harmoniccentrality(graph, weight=None)

Compute harmonic centrality for every node.

Parameters

NameTypeDefaultDescription
graphnetworkx.GraphrequiredInput graph.
weightstrNoneEdge attribute used as distance. Defaults to None.

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

NameTypeDefaultDescription
graphnetworkx.GraphrequiredInput graph.
weightstrNoneEdge attribute used as weight. Defaults to None.

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

NameTypeDefaultDescription
graphnetworkx.GraphrequiredInput graph.
weightstrNoneEdge attribute used as weight. Defaults to None.

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

NameTypeDefaultDescription
graphnetworkx.GraphrequiredInput graph.
dfpandas.DataFramerequiredTable of nodes. The index must match graph node labels.
label_namestrrequiredColumn containing the group label. Nodes with value 0 are excluded.
cohortstrNoneIf set, restrict df to this cohort value. Defaults to None.
iterationsint1000Number of null-distribution draws. Defaults to 1000.
weightstrNoneEdge attribute used as weight. Defaults to None.
methodstr'dijkstra'Shortest-path algorithm. Defaults to "dijkstra".
distributionpd.DataFrameNonePrecomputed null distribution with a label_name column. Defaults to None.
processesint1Number of worker processes. Defaults to 1.
verboseboolFalseIf True, show a progress bar. Defaults to False.

Returns

avg_path_lengthfloat
Average shortest-path length of the selected subgraph.
distlist
Null distribution of path lengths.
pvaluefloat
One-sided permutation p-value.

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
... )