Chapter 2: Markov Decision Processes
Formalize sequential decision-making as a Markov decision process: states, actions, transition dynamics, the Markov property, and the Bellman equations that every RL algorithm is ultimately trying to solve.
- Topics
- 5
- Videos
- 5
- Min read
- 20
Chapter Overview
Chapter 1 described reinforcement learning informally — an agent acts, the environment responds, rewards accumulate. That picture is intuitive but too loose to build algorithms on. The Markov decision process (MDP) is the formalism that makes it precise. An MDP says exactly what a state is, what the environment is allowed to do in response to an action, and what quantity the agent is trying to maximize.
The payoff for this formality is the Bellman equations. They express the value of a state in terms of the values of the states that follow it, turning an infinite-horizon optimization over trajectories into a system of equations over states. Almost every algorithm in the rest of this course — dynamic programming, TD learning, Q-learning, actor-critic — is a different strategy for solving or approximating those equations.
Chapter Roadmap
Click any topic to jump in
Markov Property
The future depends only on the current state, not the history that produced it. This is the assumption that makes value functions well defined.
MDP Definition
The tuple of states, actions, transition dynamics, reward function and discount factor that formally specifies an RL problem.
Averaging over a fixed policy gives its value; maximizing over actions gives the best achievable value.
Transition Dynamics
The conditional distribution p(s', r | s, a) that describes how the environment responds to actions — known in planning, unknown in learning.
Bellman Expectation
Recursive equations that relate the value of a state under a fixed policy to the values of its successors.
Bellman Optimality
Replacing the policy average with a maximum yields equations whose unique solution is the optimal value function.
Topics
5 topics in this chapter
A state is Markov if it captures everything from the past that matters for the future. Formally, the probability of the next state and reward depends on the current state and action alone, and adding the entire history changes nothing. The subtlety that trips people up is that this is a property of the state representation, not of the world. The same corridor, the same robot and the same physics can be Markov or not depending on what you decide to call the state — a camera image alone may fail while the same image plus a compass heading succeeds. That matters because the property is what licenses writing the value of a state as a single number. If the future depended on how the agent arrived, two visits to the same nominal state would have different prospects, and a value function indexed by state alone would be ill-defined. Nearly all of the theory ahead assumes this property holds, so knowing when it fails tells you exactly when the guarantees stop applying and why partially observable problems need extra machinery.
Definition
A state is Markov when the distribution of the next state and reward depends only on the current state and action, so that conditioning additionally on the whole history adds no information. Because it depends on what the agent observes, it is a property of the chosen representation rather than of the environment itself.
In this topic
- 1What the Property Actually Says
- 2State Is a Design Decision
What the Property Actually Says
The Markov property is a conditional independence claim: given the present state, the future is independent of the past. It is what licenses writing the value of a state as a single number rather than as a function of history. If the future depended on the route taken, two visits to the same nominal state could have genuinely different prospects, and a value function indexed by state alone would be ill-defined — the same table entry would need to hold two different answers. Almost all of RL theory assumes this, so when it fails the algorithms do not error, they simply converge to something that averages over the ambiguity.
Everything to the left of the conditioning bar on the right-hand side is the entire history. The equality says that history adds no information once and are known — so the agent may discard it.
A robot navigates a corridor using only a forward-facing camera. Two different junctions look identical from that camera. Is the camera image a Markov state?
State Is a Design Decision
Because the property depends on the representation, choosing the state is part of formulating the problem rather than something the environment hands you. Adding information can restore the property but enlarges the state space, and a larger space needs proportionally more experience to fill, so the fix is never free. Much of applied RL is a search for a representation close enough to Markov to be learnable while small enough to be tractable. The failure mode is quiet: an insufficient representation produces an agent that plateaus at mediocre performance rather than one that visibly breaks, which makes it easy to misdiagnose as a learning-rate problem.
Frame stacking defines a new state . If the hidden dynamics depend only on positions and velocities, and velocity is a finite difference of consecutive positions, then is approximately Markov even though no single is. The price is a state space that is the fourth power of the observation space.
In Atari games, a single frame does not reveal whether the ball is moving up or down. What did the original DQN paper do about this?
Related Problems on PixelBank
A finite Markov decision process is a five-tuple: a set of states, a set of actions, the transition and reward dynamics, and a discount factor. Once a problem is written in this form it has a well-defined optimal solution, and a large body of theory becomes available — existence of an optimal policy, convergence guarantees for the algorithms in Chapter 3, and the Bellman equations that everything else is built on. Writing your problem as an MDP is usually the hardest and most consequential modelling step in an RL project, and it is where most real failures originate. The state must be rich enough to be approximately Markov but small enough to learn; the action set must be something the agent can genuinely command; the reward must express the actual goal rather than a convenient proxy. None of these are algorithmic choices, and no amount of tuning recovers from getting them wrong. The formalism is worth the effort precisely because it makes those commitments explicit rather than leaving them implicit in code.
Definition
A Markov decision process is the tuple of states, actions, transition dynamics, reward function and discount factor. It is the formal object that turns an informal control problem into one with a well-defined optimal solution and an accompanying body of convergence theory.
In this topic
- 1The Five-Tuple
- 2Why Discounting
The Five-Tuple
An MDP is written as a tuple of states , actions , dynamics , reward function and discount . The dynamics and reward are often folded together into a single distribution over next-state-and-reward pairs, since the environment produces both at once. The discount factor is part of the problem definition rather than a hyperparameter of the algorithm, and this is worth stating plainly because it is routinely treated as a tuning knob: changing changes which policy is optimal, so an agent tuned at one value is solving a different problem from one tuned at another.
The tuple fixes the objective completely: for any policy , is determined by , and alone. Change any element and the set of optimal policies can change, which is why none of them is a tuning knob.
You want an agent to keep a data centre cool while minimizing electricity use. Sketch the MDP.
Why Discounting
The discount factor weights a reward received steps in the future by , and it serves three purposes at once. It keeps the return finite in problems that never terminate, it encodes a genuine preference for sooner rewards, and it bounds how far the consequences of an action need to be tracked. A useful rule is that the effective horizon is roughly steps, so behaves like planning about a hundred steps ahead. Small produces myopic agents that converge quickly; near one produces far-sighted agents whose estimates carry much higher variance and converge far more slowly.
The bound on the right shows why controls the effective horizon: rewards beyond roughly steps contribute almost nothing, so behaves like planning about 100 steps ahead.
An agent in a non-terminating environment receives a reward of at every step. What is its return under versus ?
The dynamics function is the complete specification of the environment: for every state and action it gives the joint probability of each next state and reward. Everything else about the environment follows from it — the expected reward for a state-action pair by marginalizing out the next state, the state-transition probabilities by marginalizing out the reward. Whether this function is known is the single most important practical distinction in reinforcement learning, and it cleanly divides the course. Knowing it means you can plan: Chapter 3 computes the optimal policy by sweeping over states without ever interacting with the environment. Not knowing it means you must learn from samples, which is Chapters 4 through 8. The second thing to absorb here is that the dynamics are generally stochastic, and that stochasticity is not a nuisance to be averaged away. It changes which policy is optimal, because a route that is shortest in expectation may also be the one where an unlucky transition is catastrophic.
Definition
The transition dynamics give the joint probability of the next state and reward given the current state and action. They constitute a complete model of the environment, and whether they are known separates planning problems from the model-free learning problems that occupy most of this course.
In this topic
- 1The Dynamics Function
- 2Model-Based vs Model-Free
The Dynamics Function
Because is a proper probability distribution, it sums to one over all next-state-and-reward pairs for each state-action pair. Everything else about the environment is derived from it: the expected reward for a state-action pair comes from marginalizing out the next state, and the state-transition probabilities from marginalizing out the reward. The stochasticity is what makes RL an optimization over expectations rather than over fixed trajectories, and that distinction has teeth. A deterministic planner can commit to a single best sequence of actions; an agent facing stochastic dynamics must instead commit to a policy that responds to whatever actually happens.
Two marginals recover the familiar quantities: the expected reward and the transition probability . A deterministic environment is the special case where, for each , one pair carries all the probability.
In a gridworld, moving 'north' succeeds 80% of the time and slips east or west 10% each. Why can't the agent just plan the shortest path?
Model-Based vs Model-Free
If is available the problem is one of planning, and dynamic programming can compute the optimal policy without ever interacting with the environment. If is unknown the agent must estimate values from experience, which is the model-free setting covering Chapters 4 through 8. A third option is to learn an approximate model from data and plan inside it, which buys sample efficiency at the risk of compounding model error: a small inaccuracy in one-step predictions grows rapidly when rolled forward, so plans made in a learned model can be confidently wrong in ways that plans made in real experience are not.
Model error compounds with rollout length. If the learned model's one-step prediction is off by a small amount, a -step imagined rollout can drift by roughly times that amount or worse, because each step starts from an already wrong state. MBPO's analysis makes this precise and motivates its design: branch only short model rollouts from states actually visited.
Board games like chess have perfectly known rules. Does that make them planning problems solvable by dynamic programming?
Related Problems on PixelBank
Given a fixed policy, the value of a state is the expected return from that state onward. Written directly, that is a sum over infinitely long trajectories, which is not something you can compute. The Bellman expectation equation rewrites it as an immediate reward plus the discounted value of wherever the agent lands next, and that single recursive step is what makes value functions computable at all. An infinite-horizon quantity becomes a relationship between neighbouring states — one equation per state, each referring only to its successors. For a finite MDP with a fixed policy the result is a system of linear equations with a unique solution, which can in principle be obtained by matrix inversion. In practice it is solved by iteration, for reasons Chapter 3 makes concrete. Understanding this equation properly is the highest-leverage thing in the course: dynamic programming solves it exactly, temporal-difference learning samples it, and actor-critic methods use its error term as a training signal.
Definition
The Bellman expectation equation expresses the value of a state under a policy as the immediate reward plus the discounted value of the successor state, averaged over the policy's action choice and the environment's response. It converts an infinite sum over trajectories into a finite system of equations relating neighbouring states.
In this topic
- 1State-Value and Action-Value Recursions
- 2A Linear System in Disguise
State-Value and Action-Value Recursions
The state-value function is the expected return starting from and following ; the action-value function is the same but commits to action first. Each satisfies a recursion that averages over two independent sources of randomness — the policy's action choice and the environment's response. The action-value form is the more useful one for control, because choosing the best action from requires no model at all, while doing the same from requires knowing the dynamics. That asymmetry is not a minor convenience; it determines which quantity every model-free algorithm in this course chooses to learn.
Read the two sums as two sources of randomness: the outer one averages over what the agent might do, the inner one over what the environment might do in response. The bracket is 'reward now plus discounted value later', which is the entire idea of the Bellman equation.
You have for every state. Can you improve the policy without knowing the transition dynamics?
A Linear System in Disguise
For a finite MDP with a fixed policy, the Bellman expectation equation is a system of linear equations — one per state, each linear in the unknown values — and can therefore be solved exactly by matrix inversion. This is rarely done in practice because the cost is cubic in the number of states, but it matters theoretically for three reasons: it proves the value function exists, proves it is unique, and identifies it as the fixed point that the iterative methods of Chapter 3 converge to. Knowing a unique fixed point exists is what makes successive approximation a sound strategy rather than a hopeful one.
Expanding the inverse as a Neumann series, , gives : the expected reward steps ahead, discounted and summed. Iterative evaluation computes the same series one term per sweep. On a 4-state chain with , rewards of and a 0.5 chance of advancing each step, the exact values are , and iteration gets within 0.001 in 16 sweeps.
An MDP has 4 states. How would you compute exactly, and why is this hopeless for a real problem?
Every finite MDP has at least one optimal policy — one whose value is greater than or equal to that of every other policy in every state simultaneously. That is a stronger statement than it first appears. It says the partial ordering over policies has a maximum element rather than merely several incomparable maximal ones, so there is no tradeoff where one policy is better in some states and worse in others. The Bellman optimality equations characterize that policy's value function by replacing the average over the policy's actions with a maximum over them. That single change has a large consequence: the system becomes nonlinear, so matrix inversion no longer applies and no closed-form solution exists. What survives is the contraction property, which guarantees that repeatedly applying the optimality operator converges to the unique solution from any starting point. Solving or approximating these equations is what the rest of the course is about, and every algorithm ahead is a different strategy for doing so.
Definition
The Bellman optimality equation replaces the policy average over actions with a maximum, so its unique solution is the value of behaving optimally. The max makes the system nonlinear and rules out a closed-form solution, but the operator remains a contraction, so iteration still converges.
In this topic
- 1The Optimality Equations
- 2Existence of a Deterministic Optimal Policy
The Optimality Equations
The optimal value function satisfies a recursion in which the agent takes the best action rather than an average one. Because of the max operator the equations are nonlinear and cannot be solved by matrix inversion, but they still have a unique solution for . Crucially, once is known the optimal policy is trivial to extract: act greedily, with no search and no model required. All of the difficulty lies in finding rather than in acting on it, which is a useful thing to keep in mind when an algorithm looks complicated — the complexity is nearly always in the estimation, not the decision.
The optimality operator is a -contraction: . In a two-state example with , starting from value functions 10 apart, one application leaves them exactly 9 apart. Banach's fixed-point theorem then gives a unique and geometric convergence from any start.
Why does replacing the policy average with a maximum make the problem harder to solve?
Existence of a Deterministic Optimal Policy
A useful and slightly surprising theorem: every finite MDP admits an optimal policy that is deterministic and stationary, needing no randomness and no dependence on time. Stochastic policies remain essential during learning because they drive exploration, and they become genuinely necessary in partially observable or multi-agent settings where the theorem's assumptions fail. But for the MDPs in this chapter the optimum is always attainable without flipping a coin. The theorem is about what the final answer may look like, not about how you are permitted to search for it — a distinction worth holding onto when Chapter 7 introduces deliberately stochastic policies.
Optimality is defined by a partial order: if for all . The theorem says this order always has a maximum element, not merely maximal ones — the greedy policy with respect to dominates every other policy in every state at once.
If a deterministic optimal policy always exists, why do modern algorithms like PPO output probability distributions over actions?