Following Probability Through a Network
A random walker chooses among outgoing links. Follow the probability mass to see how graph structure changes where it accumulates.
13 sections · 4 questions · 2 coding challenges
The arrow keys move between sections too.
Ranking Through Linked Structure
BOTIE
Our pipe-network walk first studies ordinary transitions. It is a structural probability calculation, not a physical fluid simulation; actual flow depends on pressures and capacities as well as connectivity.
Sources for this history
Where Does a Walker Go From Here?
Imagine Botie inspecting a network by choosing an outgoing connection at each step. A junction with several links gives several possible next positions.
Rather than following only one sampled route, we can keep a probability for each node. The transition matrix describes the next move from every current node. Combining the two gives us the distribution of possible locations after one step, so we can follow how probability moves through the network.
The transition rows are supplied probability distributions on a small network.
Step 1 of 3
Begin at one node
The vector describes probabilities, not measured flow.
Nodes and properties (3)
- 0: intake · Probability: 1
- 1: pump · Probability: 0
- 2: outlet · Probability: 0
- 0: intake connected to 1: pump
- 1: pump connected to 2: outlet
Step 2 of 3
Choose among outgoing edges
The middle node of a three-node chain has two equally likely choices.
Nodes and properties (3)
- 0: intake · Next: 0.5
- 1: pump · Starting here
- 2: outlet · Next: 0.5
- 0: intake connected to 1: pump
- 1: pump connected to 2: outlet
Step 3 of 3
Advance the distribution
Probability spreads through allowed transitions.
| Node | After one step | After two steps |
|---|---|---|
| 0: intake | 0 | 0.5 |
| 1: pump | 1 | 0 |
| 2: outlet | 0 | 0.5 |
0: intake
- After one step
- 0
- After two steps
- 0.5
1: pump
- After one step
- 1
- After two steps
- 0
2: outlet
- After one step
- 0
- After two steps
- 0.5
Every destination collects contributions from possible starting nodes
Each destination receives probability from all possible starting nodes.
Where can the probability move in one step?
Start with probability concentrated at one node. Follow that node's outgoing row, then try a mixture of starting nodes and see their contributions combine at each destination.
BOTIE
Node probabilities after one step
- 00
- 11
Follow the operations
1. Transition matrix
0 1 1 0 2. Check transition rows
0 1 1 0 3. Swap rows and columns
0 1 1 0 4. Current probabilities
- 01
- 10
5. Check a probability distribution
- 01
- 10
6. Matrix times vector
- 00
- 11
7. Result
- 00
- 11
The supplied matrix must already embody a declared dangling-node policy.
1. Normalise Outgoing Weights
For non-negative adjacency weights, divide each row by its outgoing total to form transition probabilities. A positive weight is a relative choice weight, not a probability until normalised.
A node with no outgoing edges has a zero row. Choose a dangling-node policy explicitly. Our exercises make such a node stay at itself; PageRank often redistributes that probability instead.
Every resulting transition row must sum to one.
2. Move Mass With the Correct Orientation
When rows are current nodes and columns next nodes, multiply a row probability vector by the transition matrix. Each destination collects contributions from all sources.
Initial p = [1,0,0]
P = [[0,1,0], [0.5,0,0.5], [0,1,0]]
p after one step = [0,1,0]
p after two steps = [0.5,0,0.5]Total probability remains one when the transition matrix is valid.
3. Recognise Cycles and Traps
An undirected two-node walk alternates forever rather than settling from every starting point. A disconnected component cannot reach another without an added transition. These are properties of the graph and process.
Teleportation mixes a link-following transition with a chosen restart distribution. It changes the process deliberately rather than fixing an arithmetic error.
Do not assume every repeated matrix multiplication converges to one unique result.
Collect arrivals from two possible starting nodes
Half the probability begins at each node. The first stays put; the second splits equally between staying and moving to the first.
import numpy as np
probability = np.array([0.5, 0.5])
transition = np.array([[1., 0.], [0.5, 0.5]])
contributions = probability[:, None] * transition
print(contributions.tolist())
print(contributions.sum(axis=0).tolist())[[0.5, 0.0], [0.25, 0.25]]
[0.75, 0.25]Each row records one source node's contribution. Adding down the columns collects the probability arriving at each destination.
4. Use the Walk for the Right Question
Random walks can describe reachability patterns, ranking, or sampling of graph neighbourhoods. They do not automatically describe the actual movement of water, disease, or information.
Compare walk results under different edge definitions, and document the dangling-node and restart rules. Otherwise two implementations can disagree while each follows its own valid process.
The workshop takes an already valid transition matrix so the movement of probability is visible.
5. A Node with No Outgoing Edges Needs a Rule
Dividing outgoing edge weights by their row sum fails when that sum is zero. The walker could remain at the node, restart according to a chosen distribution or terminate. These are different processes.
Specify the policy before normalisation. A transition matrix for a continuing walk needs every row to sum to one. Quietly leaving a zero row makes probability mass disappear when the walk reaches that node.
6. Restarting Changes the Process We Are Studying
A two-node walk that always switches nodes alternates forever from a concentrated start. Mixing each step with a restart distribution interrupts that strict cycle. It also changes what long-run visit frequency means.
The restart distribution can be uniform or personalised. Its choice is a modelling decision, not merely a numerical fix.
Follow a walk that would otherwise alternate
At each step, retain half the graph transition and use half a uniform restart.
import numpy as np
P = np.array([[0.,1.],[1.,0.]])
state = np.array([1.,0.])
restart = np.array([.5,.5])
for _ in range(3):
state = .5*(state@P) + .5*restart
print(state.tolist())[0.25, 0.75]
[0.625, 0.375]
[0.4375, 0.5625]The alternating discrepancy shrinks under this modified transition rule. The stationary distribution describes the restart process, not the original deterministic walk.
7. Visit Frequency Is Not Automatically Importance
A node can receive high mass because many paths lead to it, because a small region traps the walker or because the restart favours it. Relate the score to the inspection or retrieval task before naming it importance.
Check disconnected regions, dangling nodes and sensitivity to restart. A random walk uses connectivity; it does not automatically include node features, physical flow conservation or causal influence.
Check yourself
Questions on Parts 1 to 7
Question 1 of 4
Where is the mass after one step?
Use the information below.
p=[1,0], P=[[0,1],[1,0]].Try it with Botie
Build with Botie
Write and run Python