A11 · Lesson 50 · Markov chains
Randomness with a short memory: burst errors and queues
Lesson 4 found that a wireless link losing 1% of packets can lose the next one 40% of the time after a loss. Independent losses can't do that, but a model with two hidden states can: a "good" state where almost nothing is lost and a "bad" state, during a fade, where half the packets vanish. The link hops between them at random, and where it goes next depends only on where it is now. That's a Markov chain, the simplest model of randomness with memory. It describes burst errors, buffers filling and draining, and the state machines inside protocols.
- A two-state channel starts in the good state. Each packet time it moves from good to bad with probability and from bad back to good with probability .
- The curve is the chance of being in the bad state after packets. It climbs to a steady value and stays there.
- Make small: the bad state lasts longer, so losses come in longer bursts. What sets the steady value, and what sets how fast it's reached?
Predict
A channel goes from good to bad with probability 0.01 per packet and from bad to good with probability 0.2. What fraction of the time is it in the bad state, in the long run?
About 4.8%. In steady state, the flow from good to bad must balance the flow back: . With , . Bad spells last packets on average and good spells 100, which gives the same ratio.
Name it
Markov chains
A process moving among states at steps is a Markov chain if the next state depends only on the current one:
The transition matrix collects these probabilities; each row adds to 1. The time spent in a state before leaving is geometric (lesson 10), with mean .
Evolving the distribution
Write the chance of each state at step as a row vector . Then
The entry is the chance of going from to in exactly steps, the sum over every path of the product of its steps (lesson 4's multiplication rule).
Steady state
For a chain that can reach every state from every other and doesn't cycle rigidly, settles to a unique stationary distribution with
is a left eigenvector of with eigenvalue 1 (A7.33). The long-run fraction of time spent in each state is . For two states with and :
The other eigenvalue, , sets how fast the start is forgotten.
The Gilbert–Elliott channel
Give each state its own loss probability, small and large. The long-run loss rate is , but the losses cluster in the bad spells, which is what makes them bursty. That's why interleaving (spreading a code word's bits far apart in time) helps so much on fading links: it turns one burst into scattered single errors a code can fix.
Worked example
A Gilbert–Elliott channel has , , and loses packets with probability 0.001 in the good state and 0.5 in the bad. Find the long-run loss rate and the mean burst length.
Show the solution
- Steady state. and .
- Loss rate.
- Burst length. Bad spells last packets on average, during which about half the packets are lost.
Answer the long-run loss rate is 0.0248, and bad spells last 5 packets on average.
Worked example
Starting in the good state, what is the chance the same channel is bad two packets later?
Show the solution
- Path G→B→B. This is one of the two paths that end in B:
- Path G→G→B.
- Add the paths.
- Check with the formula.
Answer the channel is bad two packets later with chance 0.0179.
Worked example
A two-state channel goes from good to bad with probability 0.01 per packet and recovers with probability 0.2. What fraction of the time is it bad, and how long do bad spells last?
Show the solution
- Balance the flows. In the steady state,
- Fraction of time bad. about 5%.
- Length of a bad spell. Each bad spell lasts a geometric number of packets with mean
- What it means. Errors come in bursts of about five packets, which is why codes for such channels interleave their data.
Answer the channel is bad about 5% of the time, in spells of 5 packets on average.
Check
A two-state channel moves good→bad with probability 0.01 and bad→good with probability 0.1 per step. What fraction of the time is it bad, in the long run?
Check
A channel leaves its bad state with probability 0.25 per packet. How many packets does a bad spell last on average?
Check
With good→bad probability 0.02 and bad→good 0.2, starting in the good state, what is the chance of being bad two steps later?
Check
A Gilbert–Elliott channel has = 0.01, = 0.2, and loses packets with probability 0.002 when good and 0.5 when bad. What is the long-run loss rate?
Check
Starting in the good state, with = 0.05 and = 0.15, what is the chance of being in the bad state after 10 steps?
Check
Which of these makes a process a Markov chain?
Check
A channel goes bad with probability 0.01 per packet and recovers with probability 0.2.
(a)
What fraction of the time is it bad?
(b)
How long does a bad spell last, in packets, on average?
Check
Starting good, the chance of being bad after steps is with .
Step 1
Evaluate it.
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Check
Simulate the two-state channel (bad with probability 0.01 per step from good, good with 0.2 from bad) for 10⁶ steps (np.random.default_rng(7)), starting good. Set frac_bad and mean_spell, the average length of bad spells.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why does a two-state channel produce bursty losses even though its long-run loss rate can be small?
The channel remembers its state from one packet to the next: once in the bad state, it stays there for a geometric number of packets with mean . While it's there, losses are frequent, so they cluster into bursts. Averaged over a long time, the bad state may be rare, so the overall loss rate is low. But given that a loss just happened, the channel is probably in the bad state, so another loss is likely. That's the dependence that independent-loss models miss.
Practice
Keep practicing
9 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.