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$

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 that you have read and understand our privacy policy and code of conduct.

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