resistance_distance#

resistance_distance(G, nodeA, nodeB, weight=None, invert_weight=True)[source]#

Returns the resistance distance between node A and node B on graph G.

The resistance distance between two nodes of a graph is akin to treating the graph as a grid of resistorses with a resistance equal to the provided weight.

If weight is not provided, then a weight of 1 is used for all edges.

Parameters:
GNetworkX graph

A graph

nodeAnode

A node within graph G.

nodeBnode

A node within graph G, exclusive of Node A.

weightstring or None, optional (default=None)

The edge data key used to compute the resistance distance. If None, then each edge has weight 1.

invert_weightboolean (default=True)

Proper calculation of resistance distance requires building the Laplacian matrix with the reciprocal of the weight. Not required if the weight is already inverted. Weight cannot be zero.

Returns:
rdfloat

Value of effective resistance distance

Notes

Overviews are provided in [1] and [2]. Additional details on computational methods, proofs of properties, and corresponding MATLAB codes are provided in [3].

References

[1]

Wikipedia “Resistance distance.” https://en.wikipedia.org/wiki/Resistance_distance

[2]

E. W. Weisstein “Resistance Distance.” MathWorld–A Wolfram Web Resource https://mathworld.wolfram.com/ResistanceDistance.html

[3]

V. S. S. Vos, “Methods for determining the effective resistance.” Mestrado, Mathematisch Instituut Universiteit Leiden, 2016 https://www.universiteitleiden.nl/binaries/content/assets/science/mi/scripties/master/vos_vaya_master.pdf

Examples

>>> G = nx.Graph([(1, 2), (1, 3), (1, 4), (3, 4), (3, 5), (4, 5)])
>>> nx.resistance_distance(G, 1, 3)
0.625