Basis Lab

Markov Chains

Where You Are, and One Hop

A chain is a list of situations and a table of hopping chances. The assumption that makes it work is that the present situation is the only thing the next hop is allowed to see.

A machine is either running, being repaired, or waiting for a part. Each

morning it is in one of those three situations, and which one it is in tomorrow

depends on which one it is in today. That is the whole of the setup, and almost

everything in this course is a question about it: how much of the year is it

running, how long between breakdowns, how long before the answer to the first

question stops depending on what happened this morning.

The setup is worth being precise about, because the precision is where the

modelling happens. Everything after this lesson is arithmetic.

The situations

The first decision is what counts as a situation. The list has to cover

everything that can happen, and the process has to be in exactly one of them at

any moment. Running, under repair and waiting for a part satisfies that for the

machine, provided those three really are the only possibilities and the machine

is never two of them at once.

The list can be small or enormous and the mathematics does not care. A board

game's situations are its squares. A queue's situations are the numbers of

people in it. A text model's situations are the possible recent histories of

words. What matters is not the size but a property the next section names.

FIG 1Three situations and the hops between them
The whole rule, drawn. Every arrow leaving a situation carries a chance, and the chances leaving any one situation add to one. A reader who can write this picture down from a description of a process has done the part of the work that needs judgement.

What the chain may not remember

Here is the assumption, and it is the only one. Given the situation now, the

chances of the next situation do not depend on anything else. Not on how the

process arrived here, not on how long it has been here, not on the time of

year, not on anything.

There is a practical test. Think of two different histories that both end in

the same situation, and ask whether somebody who knew which history had

occurred would bet differently on tomorrow. If the answer is yes, the

assumption is false as the situations are currently defined.

The machine fails that test in one respect, and it is worth naming because it

is typical. If a repair that has already taken five days is less likely to

finish tomorrow than a repair that started this morning, then under repair is

not a single situation: how long it has been going matters, and the chain does

not know. The repair is to split it, into repair day one, repair day two and so

on, which is more situations but an honest table.

FIG 2The same rule as a table
to runningto under repairto waiting
from running0.90.10.0
from under repair0.50.10.4
from waiting0.00.30.7
Rows are where the process is now and columns are where it goes next, which is a convention worth fixing in the mind because half the literature writes it the other way round. Each row adds to exactly one. The two marked entries are the chances of staying put, and the zero in the top right is the missing arrow: a running machine cannot be waiting for a part tomorrow without breaking down first.

Rows that add to one

The table is the model. Each row is a complete statement of what can happen

from one situation, so each row adds to one: from wherever the process is, it

goes somewhere, and staying counts as going somewhere.

A row that adds to less than one means one of two things, and it is worth

telling them apart. Either the model is wrong and a possibility has been

forgotten, or the process can genuinely leave, as a customer can abandon a

queue. The second case is handled by adding a situation called gone, with a row

that sends it to itself with certainty. It is better to have a situation for

leaving than a table that does not add up.

Now watch the table move a whole distribution of chances around rather than a

single walker. If there is a one in three chance of being in each situation

this morning, applying the table once gives the chances for tomorrow morning,

and the three chances still add to one for the same reason each row does.

FIG 3A whole distribution of chances, moved one hop at a time
runningunder repairwaiting00.20.40.60.810102030405060morningschance

the three chances, added upunder 0.001% of it gone by the end, at every setting of every slider

1

60 of 60 steps

chance the machine is runningchance it is waiting for a part
stepped by
pa → (0.9 - g)*pa + 0.5*pb + 0.0*pc pb → (0.1 + g)*pa + 0.1*pb + 0.3*pc pc → 0.0*pa + 0.4*pb + 0.7*pc
each rule reads
the state as it was when the step began
started at
pa = 1.0, pb = 0.0, pc = 0.0
held steady
the three chances, added up = pa + pb + pc
drift
under 0.001% over the run, against 0.20% allowed
The machine starts certainly running, and the certainty drains away into the other two situations over the first fortnight before settling. The quantity held fixed is the total of the three chances, which stays at one at every step and for every setting of the slider: that is the arithmetic statement of the fact that each row of the table adds to one. Turning the slider up makes breakdowns more likely without ever letting the total escape, because the extra chance is taken out of the running row and put into the repair row of the same column.

Enlarging the situation when the assumption fails

The repair for a failed memoryless test is nearly always the same move: put the

missing information into the situation. If tomorrow depends on today and

yesterday, make a situation out of each ordered pair of consecutive days. If it

depends on how long the process has been where it is, make a situation for each

length of stay. If it depends on the day of the week, pair each situation with

the day.

This always works, and it is worth knowing why it is not a free move. Suppose

there are ten situations and the next hop depends on the last three. The pairs

are a hundred, the triples are a thousand, and the table of a thousand

situations has a million entries. Each thing remembered multiplies the list

rather than lengthening it. That is the trade this whole subject lives inside:

the memoryless assumption can always be bought, and the price is paid in the

size of the table.

FIG 4One walk, and what the walker would have to be told
stepmorningsituationwhat the table says happens next
1Mondayrunningnine in ten it is still running, one in ten it breaks
2Tuesdayrunningthe same two chances again: nothing about Monday changes them
3Wednesdayunder repairhalf fixed, two in five waiting for a part, one in ten still in pieces
4Thursdaywaiting for a partseven in ten still waiting, three in ten the part arrives
5Fridaywaiting for a partexactly the same two chances as Thursday, which is the assumption at its most visible and most questionable
6Saturdayunder repairback to the repair row, with no memory that this is the second visit
6 steps
Follow the last column down. At every morning the chances come from the current situation alone, and the history above is not consulted. Friday is the row to argue with: a part that has not come for two days might reasonably be judged less likely to come today, and the chain does not allow that judgement. If the argument is right, the model needs a situation for each day of waiting.

What to take from this

A chain is a list and a table. The list is a decision and the table is a

measurement, and almost all of the ways this subject goes wrong in practice are

decisions about the list rather than errors in the table.

The question to ask of any proposed list is the one from the second section:

two histories ending in the same place, would anybody bet differently. If not,

the chain is honest and the rest of the course applies to it. If so, enlarge the

situation until the answer is no, and then check whether the table that results

is one anybody can estimate.

Recap

  • A Markov chain is two things: a list of the situations the process can be in, and for each one, the chances of being in each situation next. Those chances are written as a square table whose rows each add up to one, because the process has to be somewhere.
  • The assumption is that the next hop depends on the present situation and on nothing else about the past. That is a restriction on the situations, not on the process: almost anything can be made to satisfy it by putting enough into the description of where you are.
  • Choosing what counts as a situation is therefore the whole modelling decision. Too little in it and the assumption is false and the answers are wrong. Too much and the table is unusably large. Everything else in the course is arithmetic on a table somebody else chose.

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

NextWhere You Are After Many Hops →

The rest of this course

  1. 01Where You Are, and One Hopyou are here
  2. 02Where You Are After Many Hopsopening only
  3. 03What Is Reachable, and What Traps Youopening only
  4. 04The Distribution the Rule Leaves Aloneopening only
  5. 05Why the Chain Forgets Where It Startedopening only
  6. 06How Long Until It Gets Thereopening only
  7. 07Chains That Look the Same Run Backwardsopening only
  8. 08Building a Chain to Reach a Chosen Distributionopening only

Read alongside