7  Markov Decision Processes

Core idea. A Markov decision process is a Markov reward process with choices. At each state the agent selects an action, and the selected action changes both the next-state distribution and the reward distribution. Once a policy is fixed, the MDP reduces to the Markov reward process of Chapter sec-ch03-markov-reward-processes. Optimizing over policies is the beginning of reinforcement learning control.

The central object is

\[ (\mathcal S,\mathcal A,P,r,\gamma), \]

with transition law

\[ P(s'\mid s,a)=P(S_{t+1}=s'\mid S_t=s,A_t=a) \]

and expected reward

\[ r(s,a)=\mathbb E[R_{t+1}\mid S_t=s,A_t=a]. \]

7.1 Learning goals

After reading this chapter, students should be able to:

  1. define a finite discounted Markov decision process precisely;
  2. distinguish states, actions, transition laws, reward models, policies, and trajectories;
  3. explain the Markov property in a controlled stochastic system;
  4. distinguish deterministic, randomized, stationary, nonstationary, Markov, and history-dependent policies;
  5. derive the policy-induced transition matrix \(P_\pi\) and reward vector \(r_\pi\);
  6. show how a fixed policy turns an MDP into an MRP;
  7. define \(V^\pi\), \(Q^\pi\), \(V^*\), and \(Q^*\) for an MDP;
  8. derive finite-horizon dynamic programming recursions;
  9. compute policy values in a small MDP using linear algebra and Python;
  10. connect MDP modeling to AI-assisted problem formulation and modern reinforcement learning.

7.2 4.1 Why MDPs are the mathematical core of reinforcement learning

Chapters sec-markov-chains-review and sec-ch03-markov-reward-processes studied stochastic systems with no decisions. A Markov chain describes random state evolution. A Markov reward process adds numerical rewards. A Markov decision process adds actions.

In a Markov reward process, the transition probability from \(s\) to \(s'\) is simply

\[ P(s'\mid s). \]

In a Markov decision process, the transition probability depends on the action:

\[ P(s'\mid s,a). \]

This apparently small change is fundamental. It turns evaluation into optimization. The agent is no longer only asking:

What is the expected future reward of this stochastic process?

It is now asking:

Which decision rule creates the stochastic process with the largest expected future reward?

A policy chooses actions. The environment responds stochastically. The resulting state sequence is a Markov chain only after the policy has been specified. This separation is one of the cleanest ways to understand the whole book:

\[ \text{MDP} + \text{policy} \quad \Longrightarrow \quad \text{MRP}. \]

Dynamic programming assumes the MDP model is known and optimizes exactly or approximately. Reinforcement learning uses data generated by interaction to estimate values, improve policies, or learn a model.

An MDP separates modeling from decision making. The model says what can happen after each state-action pair. The policy says what the agent chooses to do.

7.3 4.2 Finite discounted Markov decision processes

A finite discounted Markov decision process consists of

\[ \mathcal M=(\mathcal S,\mathcal A,P,r,\gamma), \]

where:

Object Meaning
\(\mathcal S=\{1,\ldots,m\}\) finite state space
\(\mathcal A(s)\) finite set of feasible actions at state \(s\)
\(P(s'\mid s,a)\) transition probability from \(s\) to \(s'\) after action \(a\)
\(r(s,a)\) expected one-step reward for state-action pair \((s,a)\)
\(\gamma\in[0,1)\) discount factor

The transition probabilities satisfy

\[ P(s'\mid s,a)\geq 0, \qquad \sum_{s'\in\mathcal S}P(s'\mid s,a)=1. \]

The expected reward is commonly defined by

\[ r(s,a)=\mathbb E[R_{t+1}\mid S_t=s,A_t=a]. \]

Some models use transition-based rewards

\[ r(s,a,s')=\mathbb E[R_{t+1}\mid S_t=s,A_t=a,S_{t+1}=s']. \]

Then the state-action reward is

\[ r(s,a)=\sum_{s'\in\mathcal S}P(s'\mid s,a)r(s,a,s'). \]

Both descriptions are equivalent for value calculations when only expected discounted return is optimized. Transition-based rewards can be more natural when the reward depends on the realized next state, such as receiving a penalty only when the system fails.

7.3.1 Controlled Markov property

The controlled Markov property says that, conditional on the current state and current action, the distribution of the next state and reward does not depend on the earlier history:

\[ P(S_{t+1}=s',R_{t+1}\in B \mid S_0,A_0,R_1,\ldots,S_t=s,A_t=a) = P(S_{t+1}=s',R_{t+1}\in B\mid S_t=s,A_t=a). \]

The current state \(S_t\) must therefore contain all information from the past that is needed for predicting the next transition, once the action is known. This is a modeling assumption. In practice, building a useful state representation is often as important as choosing an algorithm.

Modeling principle. If the future depends on a feature of the past that is not included in \(S_t\), then the process may not be Markov in the chosen state variable. A common fix is to enlarge the state so that it includes enough history or sufficient statistics.

7.4 4.3 Running example: study-planning MDP

We use a small study-planning example throughout this chapter. The state space is

\[ \mathcal S=\{\text{Review},\text{Practice},\text{Mastery}\}. \]

At each state, the student can choose one of two actions:

\[ \mathcal A=\{\text{Consolidate},\text{Challenge}\}. \]

The action Consolidate emphasizes review, repetition, and stability. The action Challenge emphasizes harder problems, faster movement toward mastery, but also higher risk of confusion.

For a fixed ordering of states \([\text{Review},\text{Practice},\text{Mastery}]\), define the transition matrices

\[ P^{C}= \begin{pmatrix} 0.70 & 0.25 & 0.05\\ 0.15 & 0.70 & 0.15\\ 0.05 & 0.10 & 0.85 \end{pmatrix}, \]

and

\[ P^{H}= \begin{pmatrix} 0.45 & 0.45 & 0.10\\ 0.20 & 0.40 & 0.40\\ 0.10 & 0.20 & 0.70 \end{pmatrix}. \]

Here \(C\) stands for Consolidate and \(H\) stands for Challenge. The reward vectors are

\[ r^C= \begin{pmatrix} 1\\2\\5 \end{pmatrix}, \qquad r^H= \begin{pmatrix} 0\\4\\6 \end{pmatrix}. \]

The challenge action has lower reward in Review because it may be frustrating before the foundations are secure, but it has higher reward in Practice and Mastery because it can accelerate progress.

The interactive network shows the two transition kernels side by side. An MDP is not one transition matrix; it is a collection of transition matrices indexed by actions.

7.5 4.4 Policies

A policy is a rule for choosing actions. Policies may be classified by how much information they use and whether they randomize.

7.5.1 Deterministic stationary policies

A deterministic stationary policy is a function

\[ \pi:\mathcal S\to\mathcal A. \]

It chooses one action in each state. For example,

\[ \pi(\text{Review})=C, \qquad \pi(\text{Practice})=H, \qquad \pi(\text{Mastery})=H. \]

This policy consolidates at Review but chooses challenge later.

If every state has two actions and there are \(m\) states, then there are \(2^m\) deterministic stationary policies. More generally, if state \(s\) has \(|\mathcal A(s)|\) feasible actions, the number of deterministic stationary policies is

\[ \prod_{s\in\mathcal S}|\mathcal A(s)|. \]

For small MDPs, enumeration may be possible. For large state spaces, direct enumeration is impossible.

7.5.2 Randomized stationary policies

A randomized stationary policy assigns a probability distribution over actions at each state:

\[ \pi(a\mid s)=P(A_t=a\mid S_t=s). \]

For each fixed \(s\),

\[ \pi(a\mid s)\geq 0, \qquad \sum_{a\in\mathcal A(s)}\pi(a\mid s)=1. \]

If there are two actions, a randomized policy can be described by one number per state. For example, let

\[ p_s=P(A_t=H\mid S_t=s). \]

Then

\[ \pi(H\mid s)=p_s, \qquad \pi(C\mid s)=1-p_s. \]

The display above shows how changing the probability of choosing Challenge at each state changes the policy. Randomization is not merely a technicality. It is the mathematical form of exploration, mixed strategies, entropy-regularized control, and differentiable policy optimization.

7.5.3 Nonstationary and history-dependent policies

A nonstationary Markov policy may depend on time:

\[ \pi_t(a\mid s)=P(A_t=a\mid S_t=s). \]

A history-dependent policy may depend on the whole past:

\[ \pi_t(a\mid h_t), \]

where

\[ h_t=(S_0,A_0,R_1,S_1,A_1,R_2,\ldots,S_t). \]

History-dependent policies are mathematically general, but for many finite discounted MDPs one can restrict attention to stationary deterministic policies when optimizing expected discounted reward. This is a deep and useful fact from MDP theory (puterman1994markov?).

For discounted finite MDPs with known model, optimal stationary deterministic policies exist. Modern reinforcement learning often still uses randomized policies because they support exploration, regularization, and gradient-based optimization.

7.6 4.5 A fixed policy induces an MRP

The most important calculation in this chapter is the reduction from an MDP to an MRP. Fix a randomized stationary policy \(\pi\). The policy-induced transition matrix is

\[ P_\pi(s,s') = \sum_{a\in\mathcal A(s)}\pi(a\mid s)P(s'\mid s,a). \]

The policy-induced reward vector is

\[ r_\pi(s) = \sum_{a\in\mathcal A(s)}\pi(a\mid s)r(s,a). \]

Therefore the fixed policy creates the Markov reward process

\[ (\mathcal S,P_\pi,r_\pi,\gamma). \]

Then Chapter sec-ch03-markov-reward-processes applies directly:

\[ V^\pi=r_\pi+\gamma P_\pi V^\pi, \]

and hence

\[ V^\pi=(I-\gamma P_\pi)^{-1}r_\pi. \]

This formula is the foundation of policy evaluation.

7.6.1 Example: policy-induced model

Suppose the policy chooses Challenge with probabilities

\[ p=(p_R,p_P,p_M)=(0.20,0.70,0.90), \]

where \(R\), \(P\), and \(M\) stand for Review, Practice, and Mastery. Then

\[ P_\pi(s,\cdot)=(1-p_s)P^C(s,\cdot)+p_sP^H(s,\cdot), \]

and

\[ r_\pi(s)=(1-p_s)r^C(s)+p_s r^H(s). \]

The mixture happens row by row because the action is chosen after observing the current state.

The interactive visualization shows how values change as the probability of choosing Challenge changes. This is a small example of a central RL idea: changing the policy changes both immediate rewards and future state distributions.

7.7 4.6 State-value and action-value functions

For a policy \(\pi\), the discounted return is

\[ G_t=\sum_{k=0}^{\infty}\gamma^k R_{t+k+1}. \]

The state-value function is

\[ V^\pi(s)=\mathbb E_\pi[G_t\mid S_t=s]. \]

The action-value function is

\[ Q^\pi(s,a)=\mathbb E_\pi[G_t\mid S_t=s,A_t=a]. \]

The action-value function separates the first action from the future policy. If the agent takes action \(a\) now and follows \(\pi\) afterward, then

\[ Q^\pi(s,a) = r(s,a)+\gamma\sum_{s'\in\mathcal S}P(s'\mid s,a)V^\pi(s'). \]

The state-value function is the policy average of the action-value function:

\[ V^\pi(s)=\sum_{a\in\mathcal A(s)}\pi(a\mid s)Q^\pi(s,a). \]

This pair of equations is conceptually important:

\[ \boxed{ Q^\pi(s,a)=r(s,a)+\gamma\mathbb E[V^\pi(S_{t+1})\mid S_t=s,A_t=a] } \]

and

\[ \boxed{ V^\pi(s)=\mathbb E_{A\sim\pi(\cdot\mid s)}[Q^\pi(s,A)]. } \]

The optimal value functions are

\[ V^*(s)=\sup_\pi V^\pi(s), \qquad Q^*(s,a)=\sup_\pi Q^\pi(s,a). \]

Later chapters show that they satisfy Bellman optimality equations. For now, the key point is that \(Q^\pi\) tells us how good a one-step deviation is before returning to policy \(\pi\).

7.8 4.7 Bellman equations for a fixed policy

The Bellman expectation equation for \(V^\pi\) is

\[ V^\pi(s) = \sum_{a\in\mathcal A(s)}\pi(a\mid s) \left[ r(s,a)+\gamma\sum_{s'\in\mathcal S}P(s'\mid s,a)V^\pi(s') \right]. \]

In matrix form this is

\[ V^\pi=r_\pi+\gamma P_\pi V^\pi. \]

Because \(0\leq\gamma<1\), the Bellman operator

\[ (T^\pi V)(s) = \sum_a\pi(a\mid s) \left[ r(s,a)+\gamma\sum_{s'}P(s'\mid s,a)V(s') \right] \]

is a contraction in the sup norm:

\[ \|T^\pi V-T^\pi W\|_\infty\leq \gamma\|V-W\|_\infty. \]

Therefore \(V^\pi\) is the unique fixed point of \(T^\pi\).

Policy evaluation theorem for finite discounted MDPs. Fix a stationary randomized policy \(\pi\) in a finite MDP with \(0\leq\gamma<1\). Then \(V^\pi\) exists, is unique, and satisfies

\[ V^\pi=(I-\gamma P_\pi)^{-1}r_\pi. \]

Proof. Since \(P_\pi\) is a stochastic matrix, its induced sup-norm operator norm satisfies \(\|P_\pi\|_\infty=1\). Thus

\[ \|\gamma P_\pi V-\gamma P_\pi W\|_\infty \leq \gamma\|V-W\|_\infty. \]

Because \(\gamma<1\), \(T^\pi V=r_\pi+\gamma P_\pi V\) is a contraction. By the Banach fixed point theorem, it has a unique fixed point. Rearranging

\[ V=r_\pi+\gamma P_\pi V \]

gives

\[ (I-\gamma P_\pi)V=r_\pi. \]

The inverse exists because the Neumann series converges:

\[ (I-\gamma P_\pi)^{-1}=\sum_{k=0}^{\infty}\gamma^kP_\pi^k. \]

Therefore

\[ V^\pi=(I-\gamma P_\pi)^{-1}r_\pi. \]

This proves the claim. \(\square\)

7.9 4.8 Python example: evaluating a policy

The following code evaluates a randomized policy in the study-planning MDP.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

states = ["Review", "Practice", "Mastery"]
actions = ["Consolidate", "Challenge"]

gamma = 0.90

P_C = np.array([
    [0.70, 0.25, 0.05],
    [0.15, 0.70, 0.15],
    [0.05, 0.10, 0.85]
])

P_H = np.array([
    [0.45, 0.45, 0.10],
    [0.20, 0.40, 0.40],
    [0.10, 0.20, 0.70]
])

r_C = np.array([1.0, 2.0, 5.0])
r_H = np.array([0.0, 4.0, 6.0])

# Probability of choosing Challenge in each state.
p_challenge = np.array([0.20, 0.70, 0.90])

P_pi = np.zeros_like(P_C)
r_pi = np.zeros(3)

for i in range(3):
    p = p_challenge[i]
    P_pi[i, :] = (1 - p) * P_C[i, :] + p * P_H[i, :]
    r_pi[i] = (1 - p) * r_C[i] + p * r_H[i]

V_pi = np.linalg.solve(np.eye(3) - gamma * P_pi, r_pi)

value_table = pd.DataFrame({
    "state": states,
    "P(Challenge | state)": p_challenge,
    "expected immediate reward": r_pi,
    "value V_pi": V_pi
})

value_table
state P(Challenge | state) expected immediate reward value V_pi
0 Review 0.2 0.8 30.599306
1 Practice 0.7 3.4 36.976881
2 Mastery 0.9 5.9 41.624929

Policy values for a small Markov decision process.

The computation is short because the mathematical reduction is powerful. After fixing \(\pi\), we only need to solve a linear system.

plt.figure(figsize=(7, 4))
plt.bar(states, V_pi)
plt.ylabel("value")
plt.title("Policy value function")
plt.show()

Value function under a randomized stationary policy.

7.9.1 Computing \(Q^\pi\)

Once \(V^\pi\) is known, the action-value function is easy to compute:

\[ Q^\pi(s,a)=r(s,a)+\gamma P^a(s,\cdot)V^\pi. \]

Q = pd.DataFrame(index=states, columns=actions, dtype=float)

for i, s in enumerate(states):
    Q.loc[s, "Consolidate"] = r_C[i] + gamma * P_C[i, :] @ V_pi
    Q.loc[s, "Challenge"] = r_H[i] + gamma * P_H[i, :] @ V_pi

Q
Consolidate Challenge
Review 30.470483 31.114599
Practice 35.045706 37.804527
Mastery 41.547959 41.633481

The difference

\[ Q^\pi(s,H)-Q^\pi(s,C) \]

measures whether Challenge is a better one-step action than Consolidate when future behavior follows \(\pi\). This quantity is the first appearance of the policy improvement idea developed in Chapter 7.

advantage_challenge = Q["Challenge"] - Q["Consolidate"]

pd.DataFrame({
    "state": states,
    "Q(Challenge) - Q(Consolidate)": advantage_challenge.values
})
state Q(Challenge) - Q(Consolidate)
0 Review 0.644116
1 Practice 2.758820
2 Mastery 0.085523

7.10 4.9 Finite-horizon MDPs

Not every decision problem is naturally infinite horizon. A course lasts a semester, a clinical trial has a planned endpoint, and an inventory problem may have a finite planning period. In a finite-horizon MDP, the objective is

\[ \mathbb E\left[\sum_{t=0}^{T-1}R_{t+1}\right], \]

or sometimes

\[ \mathbb E\left[\sum_{t=0}^{T-1}R_{t+1}+g(S_T)\right], \]

where \(g\) is a terminal reward.

Finite-horizon value functions depend on time. Let \(V_t(s)\) be the optimal expected reward from time \(t\) to the horizon \(T\), given \(S_t=s\). The terminal condition is

\[ V_T(s)=g(s). \]

The backward dynamic programming recursion is

\[ V_t(s)= \max_{a\in\mathcal A(s)} \left[ r_t(s,a)+\sum_{s'}P_t(s'\mid s,a)V_{t+1}(s') \right], \qquad t=T-1,T-2,\ldots,0. \]

For a fixed policy \(\pi_t\), the expectation recursion is

\[ V_t^\pi(s)= \sum_a\pi_t(a\mid s) \left[ r_t(s,a)+\sum_{s'}P_t(s'\mid s,a)V_{t+1}^\pi(s') \right]. \]

Finite-horizon problems naturally produce nonstationary policies. The best action near the end of the horizon may differ from the best action early in the horizon.

The plot shows how optimal values change as the remaining horizon increases. Short horizons emphasize immediate reward. Longer horizons give the transition dynamics more time to matter.

7.10.1 Python example: backward induction

T = 8
terminal = np.array([0.0, 0.0, 8.0])

V = np.zeros((T + 1, 3))
policy = np.empty((T, 3), dtype=object)
V[T, :] = terminal

for t in range(T - 1, -1, -1):
    q_C = r_C + P_C @ V[t + 1, :]
    q_H = r_H + P_H @ V[t + 1, :]
    choose_H = q_H > q_C
    V[t, :] = np.maximum(q_C, q_H)
    policy[t, :] = np.where(choose_H, "Challenge", "Consolidate")

pd.DataFrame(V, columns=states).assign(time=range(T + 1)).set_index("time")
Review Practice Mastery
time
0 30.046975 36.916390 40.755259
1 25.884362 32.754665 36.594128
2 21.720535 28.592804 32.433591
3 17.554056 24.430605 28.274377
4 13.382125 20.267300 24.118150
5 9.202500 16.098000 19.969000
6 5.050000 11.880000 15.840000
7 1.400000 7.200000 11.800000
8 0.000000 0.000000 8.000000
pd.DataFrame(policy, columns=states).assign(time=range(T)).set_index("time")
Review Practice Mastery
time
0 Challenge Challenge Challenge
1 Challenge Challenge Challenge
2 Challenge Challenge Challenge
3 Challenge Challenge Challenge
4 Challenge Challenge Challenge
5 Challenge Challenge Challenge
6 Challenge Challenge Challenge
7 Consolidate Challenge Consolidate

This computation is the finite-horizon version of dynamic programming. Infinite-horizon value iteration in Chapter 8 can be understood as repeatedly applying a time-homogeneous version of this recursion.

7.11 4.10 Occupancy measures

Value functions are one way to describe an MDP under a policy. Occupancy measures are another. They are especially useful in statistical learning theory, offline RL, and policy gradient methods.

For an initial distribution \(\mu\), define the discounted state occupancy measure of policy \(\pi\) by

\[ d_\mu^\pi(s) = (1-\gamma)\sum_{t=0}^{\infty}\gamma^tP_\pi(S_t=s\mid S_0\sim\mu). \]

The factor \(1-\gamma\) normalizes the measure so that

\[ \sum_s d_\mu^\pi(s)=1. \]

The corresponding state-action occupancy measure is

\[ d_\mu^\pi(s,a)=d_\mu^\pi(s)\pi(a\mid s). \]

The normalized expected discounted reward can be written as

\[ (1-\gamma)J_\mu(\pi) = \sum_s d_\mu^\pi(s)r_\pi(s) = \sum_s\sum_a d_\mu^\pi(s,a)r(s,a). \]

This identity is important because it converts a sequential objective into an expectation with respect to a policy-dependent distribution.

Occupancy measures explain why data distribution matters in reinforcement learning. A policy only generates data from the states and actions it visits often. If an offline dataset has poor coverage of important actions, value estimates can be unreliable.

mu = np.array([1.0, 0.0, 0.0])
occupancy = (1 - gamma) * mu @ np.linalg.inv(np.eye(3) - gamma * P_pi)

pd.DataFrame({
    "state": states,
    "discounted occupancy": occupancy
})
state discounted occupancy
0 Review 0.416857
1 Practice 0.285640
2 Mastery 0.297503

7.12 4.11 Model-based and model-free viewpoints

An MDP model contains \(P\) and \(r\). If these are known, the agent can plan. If they are unknown, the agent must learn from samples.

7.12.1 Model-based viewpoint

The model-based approach estimates or assumes

\[ \widehat P(s'\mid s,a), \qquad \widehat r(s,a), \]

and then uses dynamic programming or planning on the estimated model. This approach makes the probabilistic structure explicit and is natural for students trained in statistics.

7.12.2 Model-free viewpoint

The model-free approach estimates values or policies directly, without explicitly estimating \(P\). For example, Q-learning estimates \(Q^*\) from sampled transitions

\[ (S_t,A_t,R_{t+1},S_{t+1}). \]

The distinction is not absolute. Many modern algorithms combine model learning, value learning, policy learning, and simulation.

The MDP is the mathematical object, not necessarily the algorithm. Algorithms differ in whether they use the model explicitly, estimate it, or avoid representing it directly.

7.13 4.12 Statistical modeling issues

For MA Applied Math and MS Statistics students, the MDP definition should raise several modeling questions.

7.13.1 What is the state?

The state should contain enough information to make the future conditionally independent of the past, given the current action. In practice, this may require feature engineering, filtering, embeddings, or belief states.

For example, in a tutoring system, the current quiz score alone may not be Markov. The student’s history of misconceptions, time since last review, and previous activities may be needed.

7.13.2 What is the reward?

Reward design is a modeling decision. A poorly chosen reward can produce undesirable behavior. For example, a tutoring system rewarded only for short-term engagement might avoid difficult but important material.

Mathematically, reward design specifies the objective function. A change in reward is a change in the optimization problem.

7.13.3 What is the action space?

The action space determines what the agent is allowed to choose. Too small an action space may exclude useful decisions. Too large an action space may make learning statistically and computationally difficult.

7.13.4 Is the Markov assumption reasonable?

The Markov assumption is not automatically true. It is a statement about the chosen representation. When it fails, one may consider:

  • enlarging the state with lagged variables;
  • using recurrent models or sequence models;
  • estimating a belief state;
  • formulating a partially observable MDP;
  • accepting an approximate Markov model for tractability.

These modeling choices connect reinforcement learning to statistics, stochastic processes, causal inference, and AI systems.

7.14 4.13 AI-assisted learning component

Generative AI tools can help students learn MDP modeling, but the mathematical specification must remain explicit. A useful workflow is:

  1. describe the real decision problem in words;
  2. ask the AI tool to identify possible states, actions, rewards, and transition uncertainties;
  3. translate the suggestions into a precise MDP definition;
  4. check whether the proposed state is plausibly Markov;
  5. write down \(P(s'\mid s,a)\) and \(r(s,a)\) for a small finite version;
  6. compute \(P_\pi\), \(r_\pi\), and \(V^\pi\) by hand or in Python;
  7. critique the reward and state representation.

7.14.1 Prompt template

A useful prompt is:

I am modeling a finite Markov decision process for [application]. Propose a small state space, action space, transition model, and reward function. Then explain which parts of the state are needed for the Markov property. Keep the example small enough that I can compute policy evaluation by hand.

7.14.2 Verification questions

After receiving an AI-generated model, students should ask:

  • Are the transition probabilities nonnegative and do they sum to one for each state-action pair?
  • Is the reward function aligned with the real objective?
  • Does the state contain enough information for the Markov property?
  • Are any actions infeasible in some states?
  • Does the model confuse correlation with causation?
  • Can I compute \(P_\pi\) and \(r_\pi\) from the proposed policy?

7.14.3 AI debugging exercise

Ask an AI tool to write Python code for policy evaluation in the study-planning MDP. Then check whether it:

  1. mixes rows of \(P^C\) and \(P^H\) using the state-specific action probabilities;
  2. computes \(r_\pi\) consistently with the policy;
  3. solves \((I-\gamma P_\pi)V=r_\pi\) rather than using elementwise division;
  4. distinguishes \(V^\pi\) from \(Q^\pi\).

The goal is not to trust the AI output. The goal is to use mathematical structure to audit it.

7.15 4.14 Summary

This chapter introduced the finite discounted Markov decision process. The key ideas are:

  • an MDP adds actions to a Markov reward process;
  • the transition law is \(P(s'\mid s,a)\), not merely \(P(s'\mid s)\);
  • a policy specifies how actions are chosen;
  • a fixed policy induces a Markov reward process with

\[ P_\pi(s,s')=\sum_a\pi(a\mid s)P(s'\mid s,a) \]

and

\[ r_\pi(s)=\sum_a\pi(a\mid s)r(s,a); \]

  • the value of a fixed policy satisfies

\[ V^\pi=(I-\gamma P_\pi)^{-1}r_\pi; \]

  • the action-value function is

\[ Q^\pi(s,a)=r(s,a)+\gamma\sum_{s'}P(s'\mid s,a)V^\pi(s'); \]

  • finite-horizon MDPs are solved by backward induction;
  • occupancy measures describe the distribution of states and actions generated by a policy;
  • MDP modeling requires careful choices of state, action, reward, and transition structure.

The next chapter studies Bellman equations in greater depth and introduces optimality equations.

7.16 Exercises

7.16.1 Conceptual exercises

  1. Explain why a Markov decision process is not the same thing as a Markov chain.
  2. Give an example of a state representation that is not Markov. Then enlarge it to make it closer to Markov.
  3. Explain why randomized policies are useful even though deterministic optimal policies exist for many finite discounted MDPs.
  4. In your own words, explain the statement: an MDP plus a policy equals an MRP.
  5. Describe a real decision problem in education, finance, health, or operations. Identify possible states, actions, rewards, and transition uncertainties.

7.16.2 Mathematical exercises

  1. Let \(\pi\) be a randomized stationary policy. Prove that \(P_\pi\) is a row-stochastic matrix.
  2. Derive the Bellman expectation equation for \(V^\pi\) from the recursive identity \(G_t=R_{t+1}+\gamma G_{t+1}\).
  3. Show that

\[ V^\pi(s)=\sum_a\pi(a\mid s)Q^\pi(s,a). \]

  1. For the study-planning MDP, compute \(P_\pi\) and \(r_\pi\) by hand for the policy that always chooses Challenge.
  2. For the same MDP, compute \(P_\pi\) and \(r_\pi\) for the deterministic policy that chooses Consolidate in Review and Challenge otherwise.
  3. Prove that \(T^\pi\) is a contraction in the sup norm.
  4. Show that

\[ (I-\gamma P_\pi)^{-1}=\sum_{k=0}^{\infty}\gamma^kP_\pi^k. \]

  1. Let \(\mu\) be an initial distribution. Prove that the normalized discounted occupancy measure satisfies \(\sum_s d_\mu^\pi(s)=1\).

7.16.3 Computational exercises

  1. Modify the Python example so that \(\gamma=0.50\), \(0.90\), and \(0.99\). Compare the value functions.
  2. Enumerate all deterministic stationary policies in the three-state, two-action study MDP. Which policy has the largest value from Review?
  3. Estimate \(P_\pi\) by simulating 10,000 transitions under the randomized policy. Compare the empirical transition matrix with the exact one.
  4. Compute the state-action occupancy measure \(d_\mu^\pi(s,a)\) for the study MDP.
  5. Implement finite-horizon backward induction with a different terminal reward. How does the optimal policy change?
  6. Construct your own three-state, two-action MDP and compute \(V^\pi\) and \(Q^\pi\) for two different policies.

7.16.4 AI-assisted exercises

  1. Ask an AI tool to propose a small MDP for course advising. Convert the response into a precise tuple \((\mathcal S,\mathcal A,P,r,\gamma)\).
  2. Ask the AI tool to explain why the proposed state is Markov. Critique the explanation.
  3. Ask the AI tool to generate Python code for computing \(P_\pi\). Check whether each row sums to one.
  4. Ask the AI tool to propose a reward function for the same MDP. Identify at least two possible unintended incentives.
  5. Ask the AI tool to produce a deterministic policy and a randomized policy. Compute and compare their values.

7.17 Instructor notes

This chapter should be taught as the bridge from stochastic processes to decision making. Students who understand Chapters 2 and 3 should see Chapter 4 as a minimal but powerful extension: actions index transition matrices and reward vectors. The most important algebraic formula is

\[ P_\pi(s,s')=\sum_a\pi(a\mid s)P(s'\mid s,a), \]

because it explains why policy evaluation is an MRP problem. Emphasize that MDP modeling is not automatic: the state representation, reward function, and action space are scientific modeling choices.