6
$\begingroup$

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

$\endgroup$

2 Answers 2

14
$\begingroup$

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[Γ]
]
$\endgroup$
1
$\begingroup$

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"]

enter image description here

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.