Skip to content
RL Handbook

Markov Decision Processes

The formal framework for sequential decision-making: Markov chains, policies, value functions, and Bellman equations.

Abstract. A multi-armed bandit has actions and rewards, but no state. A Markov Decision Process adds state back in: actions now change what the agent will see next, so an action is good not only because of its immediate reward but because of the future it leads to. This chapter builds the chain from Markov chains to MDPs, then introduces value functions and the Bellman equations.

The bandit chapter isolated exploration. Each arm had an unknown reward distribution, but pulling one arm did not change the next situation. Reinforcement learning becomes sequential when the current action changes the next state. A robot's step changes its position; a game move changes the board; a recommender action changes what the user may do next.

The Markov Decision Process is the standard mathematical language for that setting. It gives us a compact way to say what the environment can do, what the agent can choose, what reward arrives, and how future rewards are evaluated.

From Markov Chains to MDPs

A Markov chain has states and transition probabilities, but no rewards and no actions. At each step, the process moves from state ss to state ss' according to a transition matrix PP, where Pss=Pr(St+1=sSt=s)P_{ss'} = \Pr(S_{t+1}=s' \mid S_t=s). The defining assumption is the Markov property: once the current state is known, the earlier history adds no extra information about the next state.

A Markov reward process (MRP) adds rewards. Now each transition produces reward, and the process has a value: how much return should we expect from each state? There is still no choice. The dynamics decide where the process goes.

A Markov Decision Process (MDP) adds actions. The agent chooses AtA_t, and the environment samples both the next state and reward. The environment dynamics is written as:

p(s,rs,a)=Pr{St+1=s,Rt+1=rSt=s,At=a}p(s', r \mid s, a) = \Pr\{S_{t+1}=s', R_{t+1}=r \mid S_t=s, A_t=a\}

The distribution is joint over (s,r)(s', r): in many environments the reward depends on which state the agent lands in, not just on the action taken: a robot collects reward because it reached the goal, not just because it moved. That dependency is captured in the joint. Because the Markov property holds, pp completely characterizes the environment: the current (s,a)(s, a) carries all the information, earlier states and actions add nothing.

What the Markov property is about

The Markov property does not say the world has no history. It says the state representation contains all history that matters for predicting the next step. If the state is incomplete, for example a single image frame that omits velocity, the MDP assumption is only approximate.

Returns, Discounting, and Policies

As in the introduction, the agent evaluates a trajectory by its return:

Gt=k=0γkRt+k+1=Rt+1+γRt+2+γ2Rt+3+γ3Rt+4+G_t = \sum_{k=0}^{\infty} \gamma^k R_{t+k+1} = R_{t+1} + \gamma R_{t+2} + \gamma^2 R_{t+3} + \gamma^3 R_{t+4} + \cdots

The discount factor γ[0,1]\gamma \in [0, 1] controls how much future reward matters today. A value near 00 means the agent cares almost exclusively about immediate reward. A value near 11 means distant rewards count almost as much as near ones, so the agent plans far ahead. In episodic tasks a terminal state ends the sum, so γ=1\gamma = 1 is allowed: every step within the episode counts equally, as in the Small GridWorld example from the introduction. In the discounted continuing setting used here, where there is no natural endpoint, we usually take γ<1\gamma < 1 so the infinite sum remains finite.

An MDP defines the environment — the rules of the game. The agent's behavior is a separate object called a policy π\pi. A stochastic policy π(as)\pi(a \mid s) gives a probability distribution over actions in state ss. A deterministic policy chooses a single action, often written as π(s)\pi(s).

Once a policy is fixed, the agent's behavior is fully determined: in each state ss, the action is drawn from π(as)\pi(a \mid s) with no open choice left. The MDP plus a fixed policy together behave like a Markov reward process: the actions are averaged out under the policy, so only states and rewards remain. For example, the policy-induced state-reward dynamics are:

pπ(s,rs)=aπ(as)p(s,rs,a)p_\pi(s', r \mid s) = \sum_a \pi(a \mid s) p(s', r \mid s,a)

This is the same averaging that will appear in the Bellman expectation equation below. The remaining question is how good that behavior is. That is what value functions measure.

State-Value and Action-Value Functions

The state-value function of a policy is the expected return starting from state ss and then following π\pi:

vπ(s)=Eπ[GtSt=s]v_\pi(s) = \mathbb{E}_\pi[G_t \mid S_t = s]

The action-value function conditions on both the current state and the first action:

qπ(s,a)=Eπ[GtSt=s,At=a]q_\pi(s, a) = \mathbb{E}_\pi[G_t \mid S_t = s, A_t = a]

The difference is practical. vπ(s)v_\pi(s) tells us how good it is to be in a state under the policy. qπ(s,a)q_\pi(s,a) tells us how good it is to choose a particular action first, then follow the policy afterward. Value-based control methods eventually rely on qq because choosing greedily only requires comparing actions:

argmaxaq(s,a)\arg\max_a q(s,a)

The two functions measure different things, but one follows from the other. vπ(s)v_\pi(s) asks: how good is it to be in state ss under π\pi? The only random choice at the first step is the action, so we can break the expectation into cases — one for each possible action — weighted by how likely the policy is to choose it:

vπ(s)=Eπ[GtSt=s]=aPr(At=aSt=s)Eπ[GtSt=s,At=a]=aπ(as)qπ(s,a)v_\pi(s) = \mathbb{E}_\pi[G_t \mid S_t = s] = \sum_a \Pr(A_t=a \mid S_t=s)\, \mathbb{E}_\pi[G_t \mid S_t=s, A_t=a] = \sum_a \pi(a \mid s)\, q_\pi(s,a)

In words: if the policy takes action aa with high probability, that action's qπ(s,a)q_\pi(s,a) pulls the state value toward it; if the policy almost never takes aa, it barely contributes.

qπ(s,a)q_\pi(s,a) is more specific: it fixes the first action to aa, then asks the same question. To improve the policy, the agent must compare individual actions in the same state, not only know their average. The dynamics provide the symmetric connection. After taking action aa in state ss, the environment transitions to ss' with reward rr according to pp. The value from ss' onward is vπ(s)v_\pi(s'):

qπ(s,a)=s,rp(s,rs,a)[r+γvπ(s)]q_\pi(s,a) = \sum_{s', r} p(s', r \mid s, a) \left[r + \gamma v_\pi(s')\right]

The policy links vπv_\pi to qπq_\pi; the dynamics link qπq_\pi back to vπv_\pi. Substituting one into the other gives equations where each function is expressed in terms of itself — that is what the Bellman equations do.

Bellman Expectation Equations

The Bellman idea is one-step decomposition. Instead of treating the return as one long object, split it into the next reward plus the discounted return from the next state:

Gt=Rt+1+γGt+1G_t = R_{t+1} + \gamma G_{t+1}

Taking expectation under a fixed policy gives the Bellman expectation equation for vπv_\pi:

vπ(s)=aπ(as)s,rp(s,rs,a)[r+γvπ(s)]v_\pi(s) = \sum_a \pi(a \mid s) \sum_{s', r} p(s', r \mid s, a) \left[r + \gamma v_\pi(s')\right]

Read it from inside out. If we take action aa in state ss, the environment may produce next state ss' and reward rr. The total value of that outcome is immediate reward rr plus discounted future value γvπ(s)\gamma v_\pi(s'). We first average over environment outcomes ss' and rr (the inner summation), then average over the policy's action probabilities (the outer summation).

For qπq_\pi, substitute vπ(s)=aπ(as)qπ(s,a)v_\pi(s') = \sum_{a'} \pi(a' \mid s') q_\pi(s', a') into the qq equation from the previous section:

qπ(s,a)=s,rp(s,rs,a)[r+γaπ(as)qπ(s,a)]q_\pi(s,a) = \sum_{s', r} p(s', r \mid s, a) \left[r + \gamma \sum_{a'} \pi(a' \mid s') q_\pi(s',a')\right]

The inner sum over aa' is vπ(s)v_\pi(s') written out — the policy's weighted average over actions in the next state.

The Bellman equations evaluate a given policy. But the agent does not arrive with a good policy in hand. It needs the best policy — the one that maximises expected return from every state.

Optimal Value Functions

Suppose we could compare every possible policy and pick the one with the highest value in state ss. That best value is the optimal state-value function:

v(s)=maxπvπ(s)v_*(s) = \max_\pi v_\pi(s)

The optimal action-value function is defined the same way, but conditioned on taking action aa first:

q(s,a)=maxπqπ(s,a)q_*(s,a) = \max_\pi q_\pi(s,a)

There is always at least one optimal policy π\pi_* that attains these maxima in every state simultaneously. For finite MDPs, moreover, there exists an optimal deterministic policy: the agent does not need randomness once qq_* is known. It can simply pick the action with the highest qq_* in each state.

How does the Bellman idea change when we move from evaluation to optimisation? In the expectation equation we averaged over actions weighted by the policy π(as)\pi(a \mid s). In the optimality equation we replace that average with a max\max: we ask, "If we could choose the best action right now, which one would it be?"

This gives the Bellman optimality equations:

v(s)=maxas,rp(s,rs,a)[r+γv(s)]v_*(s) = \max_a \sum_{s', r} p(s', r \mid s, a) \left[r + \gamma v_*(s')\right] q(s,a)=s,rp(s,rs,a)[r+γmaxaq(s,a)]q_*(s,a) = \sum_{s', r} p(s', r \mid s, a) \left[r + \gamma \max_{a'} q_*(s',a')\right]

The inner max\max is the core of control: from the next state ss' we act as if we can freely choose the best action aa'. The outer sum averages over environment outcomes, because the agent cannot control where the environment lands, it can only control the action it sends. These two equations are self-consistency conditions: if we knew vv_* or qq_*, we could verify them by checking that every state satisfies its equation. The next chapter turns these conditions into algorithms that actually compute the optimal values when the dynamics pp are known.

What Comes Next

This chapter defines the objects: dynamics, policies, values, and Bellman equations. The next question is how to solve them when the dynamics p(s,rs,a)p(s',r \mid s,a) are known. Dynamic programming answers that with policy evaluation, policy improvement, policy iteration, and value iteration.