Foundations to Frontier
Tests

Markov decision processes

A Markov decision process (MDP) is the mathematical model behind reinforcement learning: states, actions, transition probabilities and rewards, with the Markov property that the next state depends only on the current state and action. This page writes MDPs as arrays, shows how fixing a policy turns an MDP into a Markov chain with rewards, and tests on data when an observation is really Markov: position alone is not, position with velocity is, and a hidden surface condition needs a summary of the past.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Everything you need to know is here and now

Imagine a board game where the next move depends only on where the pieces stand now, not on how they got there. That is the Markov property. A Markov decision process is a game like this with choices: in each position you pick a move, chance decides what happens next, and you collect points. If the picture you see is missing something, like the speed of a ball in a single photo, the past starts to matter and the game is no longer Markov.

Reinforcement learning lab
0123456
Fixing the policy (right with probability 0.5) turns the MDP into a Markov chain. Bars: probability of each cell after 10 steps from cell 3; the goal (cell 6) absorbs. Probability of having reached the goal: 0.3447.
Why engineers care

A single photo of a ball does not show where it is going; two photos in a row do. Game-playing AIs stack several frames for exactly this reason.

📝 Quick check (Level 0)
0/3 answered
  1. 1. The Markov property says the future depends on…
  2. 2. In an MDP, chance decides…
  3. 3. A single photo of a moving ball misses its…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • MDP: a tuple (S, A, P, R, γ): states, actions, transition probabilities P(s’|s, a), rewards R(s, a), and a discount factor γ.
  • Markov property: P(s_(t+1) | s_t, a_t, s_(t−1), a_(t−1), …) = P(s_(t+1) | s_t, a_t).
  • As arrays: P[s, a, s’] (each P[s, a, :] sums to 1) and R[s, a].
  • Rewards on transitions: R(s, a, s’) can be averaged into R(s, a) = Σ_s’ P(s’|s, a) R(s, a, s’).
  • Policy → Markov chain: P_π[s, s’] = Σ_a π(a|s) P(s’|s, a) and r_π[s] = Σ_a π(a|s) R(s, a).
  • Partially observable MDP (POMDP): the agent sees an observation o_t that may not be Markov; it can use stacked observations or a belief state, a summary of the past.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Each P[s, a, :] must…
  2. 2. Fixing a policy turns an MDP into…
  3. 3. When the observation is not Markov the problem is a…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

MDPs as arrays

Exercise 1.

  • A machine that is working or broken, with actions run and repair.
  • Running a working machine earns 10 and breaks it with probability 0.1; repairing a broken one costs 5 and fixes it with probability 0.8.
  • The policy ‘run when working, repair when broken’ as a Markov chain, and its long-run state distribution and reward per step.

Practice.

  • Store small MDPs as arrays P[s, a, s’] and R[s, a]; check that every row of P sums to 1.
  • Choose the state carefully: include everything that affects what happens next (velocity, battery level, time of day).
  • When you cannot observe it, stack recent observations, add a recurrent network, or keep a belief state.
  • Test the Markov property on data: if adding history improves predictions of the next state, the state is missing something.
  • But mind the data: larger contexts need more data, and with little data they predict worse.
  • Tools: NumPy for tabular MDPs, Gymnasium spaces for observations and actions, frame-stacking wrappers.
import numpy as np

# P[s, a, s'] and R[s, a]
P_pi = np.einsum("sa,sat->st", pi, P)      # policy -> Markov chain
r_pi = (pi * R).sum(1)                      # expected reward per state
🐍 Exercise 1: an MDP and the Markov chain of a policy
Represent a small MDP as arrays, check it is valid, build the transition matrix and reward vector of a policy, and compute the long-run state distribution and average reward.
📝 Quick check (Level 2)
0/3 answered
  1. 1. A state should include…
  2. 2. If adding history improves next-state predictions, the state is…
  3. 3. With little data, a larger context tends to…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Why the Markov property matters. It lets the value of a state depend on the state alone, which gives the Bellman equations of a later topic. Without it, the best action can depend on the whole history, and the problem becomes far harder.

Any process can be made Markov by putting enough of the past into the state: for a cart, position and velocity; for a hidden condition, the probability distribution over that condition given the history, the belief state. A POMDP over hidden states is an MDP over belief states.

Testing it. If the state is Markov, then log P(s_(t+1) | s_t, a_t, h) = log P(s_(t+1) | s_t, a_t) for any extra history h, so a model given h cannot predict better on fresh data, apart from estimation noise. Exercise 2 measures this with held-out log-loss of count models.

📝 Quick check (Level 3)
0/3 answered
  1. 1. A POMDP over hidden states is an MDP over…
  2. 2. If the state is Markov, extra history…
  3. 3. For a moving cart, a Markov state is…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Which observations of a moving cart are Markov? Measure how well the next position can be predicted from the position alone, from stacked positions, from position and velocity, and with summaries of a hidden surface condition.

History.

  • A. A. Markov (1906) studied chains of dependent events.
  • R. Bellman (1957) introduced Markov decision processes and dynamic programming; R. A. Howard (1960) developed policy iteration.
  • K. J. Åström (1965) and E. J. Sondik (1971) founded the theory of partially observable MDPs; L. P. Kaelbling, M. L. Littman and A. R. Cassandra (1998) brought them to AI.
  • V. Mnih and colleagues (2015) stacked four frames to make Atari observations close to Markov.

Exercise 2.

  • A cart on positions 0–9 with velocity −1, 0 or +1. Each step a random push changes the velocity; the push fails with probability 5% on a dry surface and 60% on an icy one, and the hidden surface switches with probability 1% per step.
  • Count models with add-½ smoothing predict the next position from six contexts; held-out log-loss on 20,000 new steps.

Seed 0, log-loss in nats per step (contexts seen):

context 2,000 training steps 20,000 training steps
position 0.7956 (30) 0.7352 (30)
position + previous position 0.4247 (84) 0.2579 (84)
position + velocity 0.4247 (84) 0.2579 (84)
+ last push failed 0.5309 (158) 0.2627 (162)
+ failures in last 8 pushes (3 or more) 0.5434 (167) 0.2313 (168)
+ hidden surface (oracle) 0.5111 (167) 0.2036 (168)
  • Position alone is far from Markov: adding velocity cut the loss from 0.735 to 0.258.
  • Two stacked positions were exactly as good as the velocity, because their difference is the velocity.
  • With a hidden surface even position and velocity are not Markov: knowing the surface lowered the loss to 0.204. A summary of the last 8 pushes recovered about half of that gain (0.231); a single last push did not help (0.263).
  • With 2,000 steps every larger context did worse than position and velocity: there was too little data to estimate the extra counts.
  • Seeds 1 and 2, 20,000 steps: position and velocity 0.2704 and 0.2731; with the 8-push summary 0.2406 and 0.2439; with the surface 0.2127 and 0.2161.
🐍 Exercise 2 (research): which observations of a moving cart are Markov? Measure how well the next position can be predicted from the position alone, from stacked positions, from position and velocity, and with summaries of a hidden surface condition.
Simulate a cart with a hidden surface condition and measure, with held-out log-loss of count models, how close six different observations are to being Markov.

MDPs in practice

  • Robots need positions, velocities and often contact or load information to be Markov; sensors rarely give all of it, so filters (such as the Kalman filter) estimate a belief state.
  • Recurrent and transformer policies learn their own summary of the history when the state is not observable.
  • Large MDPs are never written as arrays: they are given by a simulator, and the algorithms in the rest of this section only sample from it.
  • Discounting (γ in the tuple) is the subject of the next topic.

References

  1. R. Bellman (1957). “A Markovian decision process.” Journal of Mathematics and Mechanics.
  2. R. A. Howard (1960). Dynamic Programming and Markov Processes. MIT Press.
  3. M. L. Puterman (1994). Markov Decision Processes: Discrete Stochastic Dynamic Programming. Wiley.
  4. L. P. Kaelbling, M. L. Littman and A. R. Cassandra (1998). “Planning and acting in partially observable stochastic domains.” Artificial Intelligence.
  5. V. Mnih et al. (2015). “Human-level control through deep reinforcement learning.” Nature.