Is there an implementation of the resistance distance matrix (or just resistance matrix) for graphs available in Mathematica?
Asked
Active
Viewed 440 times
2 Answers
14
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[Γ]
]
2012rcampion
- 7,851
- 25
- 44
1
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.
Peter Burbery
- 1,695
- 4
- 15
