Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Obtain partial probabilities of random walks on a directed graph
ResourceFunction["DirectedGraphTransferMatrix"][g] returns a matrix whose elements are partial probabilities describing random walks across directed graph g. | |
ResourceFunction["DirectedGraphTransferMatrix"][g,outs,ins] orders the rows and columns of the output matrix according to vertex lists outs and ins. |
Find the transfer matrix for a simple directed graph with one loop:
| In[1]:= | ![]() |
| Out[1]= |
The probability for a random-walk to go from vertex 5 to vertex 3:
| In[2]:= | ![]() |
| Out[2]= |
Determine output probabilities from input probabilities using Dot:
| In[3]:= | ![]() |
| Out[3]= |
Label a binary tree with its output probabilities:
| In[4]:= | ![]() |
| Out[4]= | ![]() |
Adding edge weights to a graph changes the elements of the transfer matrix:
| In[5]:= | ![]() |
| Out[5]= |
Label a binary tree with all of its partial probabilities:
| In[6]:= | ![]() |
| Out[6]= | ![]() |
Columns of the transfer matrix sum to 1:
| In[7]:= | ![]() |
| Out[7]= | ![]() |
The column sum property does not depend on edge weights:
| In[8]:= | ![]() |
| Out[8]= | ![]() |
Check the continuity constraint on each element of the transfer matrix:
| In[9]:= | ![]() |
| Out[9]= | ![]() |
On graphs with cycles, throughput vertices can have partial probabilities greater than one:
| In[10]:= |
| Out[10]= | ![]() |
| In[11]:= |
| Out[11]= |
This means that, on average, the random walk will go through loops to visit the same vertex more than once:
| In[12]:= | ![]() |
| Out[12]= |
Calculations may fail due to trapped cycles:
| In[13]:= | ![]() |
| Out[13]= | ![]() |
Adding an extra edge allows a positive result:
| In[14]:= | ![]() |
| Out[14]= | ![]() |
Find the probability of solving a logic maze through a random walk, without hitting a dead end:
| In[15]:= | ![]() |
| Out[15]= | ![]() |
Compare with brute force enumeration of 100,000 random walks:
| In[16]:= | ![]() |
| Out[16]= |
Use WeightedAdjacencyGraph and DirectedGraphTransferMatrix to answer a Stack Exchange question:
| In[17]:= | ![]() |
| Out[17]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License