# Efficient Implementation of resistance distance for graphs?

Is there an implementation of the resistance distance matrix (or just resistance matrix) for graphs available in Mathematica?

Based on the definition from the Wikipedia article, this should give you the resistance distance matrix of the graph g:

With[{Γ = PseudoInverse[KirchhoffMatrix[g]]},
Outer[Plus, Diagonal[Γ], Diagonal[Γ]] - Γ - Transpose[Γ]
]


Jan Mangaldan created a resource function named ResistanceMatrix in 2023-12. This is based on 2012rcampion's answer.

GraphResistanceMatrix[g_?GraphQ] :=
Module[{kirchhoffMatrix, pseudoInverse, diagonal},
kirchhoffMatrix = KirchhoffMatrix[g];
pseudoInverse = PseudoInverse[kirchhoffMatrix];
diagonal = Diagonal[pseudoInverse];
SparseArray[
Outer[Plus, diagonal, diagonal] - pseudoInverse -
Transpose[pseudoInverse]]]


To test this I did

data = EntityValue[
FilteredEntityClass["Graph",
EntityFunction[graph, graph["VertexCount"] === 21]],
"ResistanceMatrix", "NonMissingEntityAssociation"]


Then I did

CheckResistanceMatrix = GraphResistanceMatrix[Graph[#1]] === #2 &;


Then I did

KeyValueMap[CheckResistanceMatrix][data]


and all the values from GraphResistanceMatrix matched GraphData's precomputed "ResistanceMatrix" value.