Markov Decision Processes and Dynamic Programming
Prerequisite Knowledge
This lecture extends ideas introduced in earlier sessions. The following prior coverage is treated as review rather than new material:
- Lecture 4 — Markov Decision Processes: the MDP elements (state, action, dynamics, reward), the reward hypothesis and return, episodic versus continuing tasks, policies, and the state and action value functions. Sections 5.1–5.6 of this lecture are direct continuations.
- Lecture 2 — Elements of RL and Multi-Armed Bandits: the state value function V(s) and action value function Q(s,a), the 4×4 grid world worked example, and why Q is often preferred when action outcomes are stochastic. These underpin Sections 5.5 and 5.6.
Markov Decision Processes and Dynamic Programming
5.1 MDP Review and Agent-Environment Interface
Hook: How do you teach a machine to make good decisions — not just now, but for the rest of its "life"? Reinforcement learning answers this with a formal math framework called a Markov Decision Process. Every RL algorithm you will ever see builds on this foundation.
5.1.1 Definition and Explanation
Intuition + Analogy: Think of an ice cream shop. You (the agent) walk in and pick a flavor (the action). The shop (the environment) hands you a cone and charges you (the reward). The shop's menu and your hunger level together form the state. An MDP is just a clean way to write down this loop: state → action → reward → new state.
Where the analogy breaks: in an MDP, the environment can be random. The same action in the same state might lead to different outcomes. Also, the agent cares about the total reward over time, not just today's cone.
A Markov Decision Process (MDP) is the mathematical framework for formulating reinforcement learning problems. It gives RL algorithms a formal structure to work within.
An MDP is defined by the tuple , where:
- — the state set — all possible situations the agent can face
- — the action set — all choices available to the agent (we sometimes write when the available actions depend on the state)
- — the dynamics function — the probability of landing in state with reward given you were in state and took action . This function fully defines how the environment behaves.
- — the reward — a scalar signal the agent receives after each action
- — the discount factor — a number in that controls how much the agent values future rewards
The agent-environment boundary is a key concept. Everything the agent can control (its choices) sits on one side. Everything it cannot change sits on the other side — that is the environment. This includes the rules of the world, the reward function, and even the agent's own sensors and actuators (the agent cannot arbitrarily change its camera; it can only choose actions). The textbook puts it well: "anything that cannot be changed arbitrarily by the agent is considered to be outside of it."
At each time step , the agent and environment produce a trajectory:
The agent sees state , picks action , and the environment returns reward and next state . This loop repeats.
The dynamics function satisfies:
From , we can derive:
- State transition probabilities:
- Expected reward for state-action pairs:
5.1.2 Symbol Registry
- — state set — finite set of all possible states
- or — action set — finite set of available actions (may depend on state)
- — dynamics function — probability of next state and reward given state and action
- — reward at time — scalar
- — discount factor — scalar in
- — state at time — element of
- — action at time — element of
The Markov property means the future depends only on the current state, not on how you got there. Formally:
If the state captures all relevant history, the Markov property holds. This is a restriction on what counts as a state, not on the problem itself.
Core Definition: A finite MDP has finite sets , , and . The dynamics function gives a complete probability distribution over next states and rewards for every state-action pair. The Markov property ensures that captures everything the environment needs to know.
5.1.3 Worked Examples
Example 1 — Traffic Control
- State: Current traffic conditions at each intersection (queue lengths, signal phase)
- Action: Which signal phase to activate (green for north-south, green for east-west, etc.)
- Reward: A measure of traffic flow efficiency — higher throughput means higher reward
- Dynamics: How traffic queues change based on signal choices and arrival rates
The Markov property holds if the state captures all current queue lengths and phases — we do not need to know what happened five minutes ago.
Example 2 — Atari Game (e.g., Pong)
- State: The raw game frame (pixel values on screen)
- Action: Controller inputs (up, down, or nothing)
- Reward: Score change from the previous frame (+1 when you win a point, −1 when you lose)
- Dynamics: The game engine determines how the ball and paddles move
The full pixel frame is Markov — it tells you everything about the current game situation.
Example 3 — Recycling Robot
A mobile robot collects empty soda cans in an office. Its battery has two distinguishable levels: high and low.
- State: Battery level —
- Actions: ;
- Reward: +1 per can collected, −3 if the battery depletes and the robot needs rescue
Transition dynamics (from the textbook):
| State | Action | Next State | Probability | Expected Reward |
|---|---|---|---|---|
| high | search | high | ||
| high | search | low | ||
| low | search | high | ||
| low | search | low | ||
| high | wait | high | 1 | |
| low | wait | low | 1 | |
| low | recharge | high | 1 | 0 |
Here is the probability that searching keeps the battery high, and is the probability that searching while low keeps it low (rather than depleting it). Note that — searching is more rewarding but riskier.
This table is the complete dynamics function for the recycling robot. Every row sums to 1 across next states for each state-action pair.
Assumptions & Scope:
- Markov property: The state must capture everything relevant. If the robot's battery degrades over time and the state only tracks "high" vs "low", the Markov property is violated — you need to track battery age too.
- Finite sets: The theory here assumes finite , , and . Continuous problems (like controlling a robot arm with real-valued angles) need extra machinery.
- Known dynamics: DP methods assume you know exactly. Most real-world problems do not give you this, which is why model-free RL methods exist.
The agent-environment interface diagram works like this: the agent picks action , the environment responds with reward and next state . This loop repeats at every time step.
Pitfalls:
- Misplacing the agent-environment boundary. The robot's motors and sensors are part of the environment, not the agent. The agent only makes high-level decisions.
- Confusing state with observation. The state is what the agent should know; the observation is what it actually sees. They differ in partially observable problems.
- Forgetting the Markov property is about the state, not the problem. You can always make a state Markov by including enough history — the question is whether your chosen state representation is rich enough.
- Thinking reward = "good behavior score." The reward defines the goal. If you reward the wrong thing, the agent optimizes the wrong thing.
Recap + Bridge: An MDP is a tuple that formally describes any sequential decision-making problem. The agent acts, the environment responds, and the Markov property keeps things clean. Next, we need to talk about what "maximizing reward" actually means — that is the reward hypothesis.
An MDP is not just a toy model. Traffic engineers use it to optimize signal timing. Game AI researchers use it to train agents that play Atari games at superhuman level. Robotics teams use it to plan actions for warehouse robots. The framework is abstract enough to cover all of these, yet concrete enough to be computationally useful. It sits at the core of every RL algorithm — model-free methods just learn the dynamics instead of being given them.
5.2 Reward Hypothesis
Hook: What does a robot actually want? We cannot write down every rule for good behavior. Instead, we give it a single number — a reward signal — and let it figure out the rest. This idea, called the reward hypothesis, is the foundation of all RL goal-setting.
5.2.1 Definition and Explanation
Intuition + Analogy: Think of the reward signal as a report card. A student does not get told exactly how to study. They just see grades (rewards) after each test. Over time, the student figures out which study habits lead to good grades. The reward signal works the same way — it tells the agent what we want (high grade), not how to get it.
Where the analogy breaks: a report card comes infrequently. In RL, the reward arrives at every time step. And the agent must balance short-term and long-term rewards — like choosing to study now (boring, low immediate reward) for a better exam score later (high future reward).
The reward hypothesis states that all goals of an RL agent can be framed as the maximization of the expected value of the cumulative sum of a received scalar signal.
Formally, the agent's objective is to maximize the expected return:
where:
- — the reward received steps after time — scalar
- — the discount factor — a scalar in that controls how much future rewards matter relative to immediate ones
- — the return from time — the total discounted reward the agent receives from that point onward
The agent chooses actions to maximize , the expected return.
Core Definition: The reward hypothesis says any goal we want an RL agent to achieve can be expressed as maximizing the expected cumulative discounted reward . The reward signal is how we communicate what we want — not how to achieve it.
5.2.2 Symbol Registry
- — reward signal at time — scalar
- — discount factor — scalar in
- — return (cumulative discounted reward from time ) — scalar
5.2.3 Key Concepts
Simple (undiscounted) sum: — adds every reward equally. This diverges to infinity if rewards are positive and the task never ends. Only works for tasks that end in finite time.
Discounted sum: — weights future rewards less. If , the agent only cares about the immediate reward. If is close to 1, the agent cares about rewards far into the future.
The discount factor has two roles:
- Mathematical: It keeps the infinite sum finite. If rewards are bounded and , the sum always converges.
- Behavioral: It encodes how much the agent values the future vs the present. A high makes the agent "far-sighted"; a low makes it "myopic."
The return at successive time steps satisfies a useful recursive relation:
This means: today's return equals today's reward plus discounted tomorrow's return. You will use this relation constantly in RL derivations.
Worked Example: Discount Factor Effect
Suppose the agent receives reward at every time step.
- With : (only the first reward counts)
- With :
- With :
- With : — the sum diverges
The geometric series formula: for constant reward and :
If reward is +2 per step instead: . You can scale the reward to control the magnitude of the return.
Assumptions & Scope:
- The reward must be a scalar. You cannot give the agent a vector of objectives directly. Multi-objective problems must be collapsed into a single number (e.g., weighted sum).
- Reward defines the goal, not the behavior. If you reward a chess agent for capturing pieces, it might capture pieces and still lose the game. The reward must reflect the real goal (winning).
- Discounting is not always needed. Episodic tasks (that always end) can use because the sum is finite. Discounting is essential for continuing tasks to prevent infinite returns.
Pitfalls:
- Reward hacking. The agent finds a loophole to get high reward without doing what you intended. Example: a cleaning robot that hides mess instead of cleaning it.
- Confusing reward with information. The reward tells the agent what is good. Do not use it to tell the agent how to act — that goes in the policy or the state representation.
- Forgetting that discounting changes the problem. A task with and the same task with are different optimization problems. The optimal policy can change.
Recap + Bridge: The reward hypothesis says: give the agent a scalar reward signal, and let it maximize the cumulative discounted return . The discount factor controls how far ahead the agent looks. But the return formula assumes the agent runs forever. What if the task naturally ends? That brings us to episodic vs continuing tasks.
This idea — compressing all goals into a single scalar signal — powers every RL system from game-playing AIs to robotic control. It is the reason RL can solve problems we do not know how to specify with explicit rules.
Q: Is the balancing of the pole continuous or episodic?
A: It can be modeled either way. If modeled as an episodic task, the episode ends when the pole falls. If modeled as a continuing task, it works irrespective of when the balance is lost. The continuing formulation is slightly more general.
Q: Is it possible that the agent continues to hold the pole infinitely?
A: If you give reward +1 for every time unit the pole is balanced, the undiscounted sum would be infinite (). That is exactly why we use discounting. With , even an infinite stream of +1 rewards gives a finite return of . Alternatively, you can model it as a continuing task with reward 0 while balanced and when balance is lost — then the return is where is when the pole falls.
5.3 Episodic vs Continuing Tasks
Hook: Some games end — you win or lose, then start over. Other processes run forever — like managing a power grid. Reinforcement learning handles both, but the math changes depending on which type you are dealing with.
5.3.1 Definition and Explanation
Intuition + Analogy: An episodic task is like playing a board game. Each game is a self-contained episode. When it ends (you reach the finish), you reset and play again. A continuing task is like managing your household budget. There is no "end" — you just keep making financial decisions month after month, indefinitely.
Where the analogy breaks: in RL, even continuing tasks have a notion of "doing well." The agent still wants to maximize cumulative reward. The challenge is that the cumulative sum can grow without bound.
An episodic task has natural terminal states. The agent's experience breaks into episodes, each ending at a terminal state, followed by a reset. The return is a finite sum:
where is the final time step of the episode.
A continuing task has no natural endpoint. The agent interacts indefinitely. Here, the undiscounted return would diverge, so we must use discounting:
with to keep the sum finite.
5.3.2 Symbol Registry
- — return from time — scalar (cumulative discounted reward)
- — terminal time step of an episode — positive integer
- — discount factor — scalar in
- — reward at time — scalar
Core Definition: Episodic tasks end in a terminal state and restart; the return is a finite sum over one episode. Continuing tasks never end; the return must use discounting () to stay finite. The textbook unifies both cases by treating episode termination as entering a special absorbing state that transitions to itself with reward 0.
5.3.3 Worked Example: Cart-Pole Balancing
Episodic Formulation
The cart-pole problem: a cart moves left and right on a track, with a pole balanced on top. The goal is to keep the pole upright.
- Episode start: Pole is balanced upright
- Episode end: Pole falls past a critical angle, or cart runs off the track
- Reward: for each time step the pole stays up
- Return: — the total number of steps before failure
The agent's goal is to maximize , the survival time.
If the pole is balanced forever (ideal case), and the return is infinite. This is fine for an episodic task — the agent simply never sees a terminal state.
Continuing Formulation
Same problem, but we treat it as a continuing task with discounting:
- Reward: while the pole is balanced, when it falls
- Return: If balance is lost at step , then
As increases (longer balance), approaches 0 (which is better — less negative). If the pole never falls, and (the best possible outcome).
Key insight: With a constant reward of +1 per step and discounting, the return converges:
With : . You can engineer the reward scale — doubling the reward doubles the return to .
Q: Can the cart-pole task be modeled as both episodic and continuing?
A: Yes. In the episodic version, the episode ends when the pole falls; reward is +1 per step; the return is the total steps before failure. In the continuing version, there is no endpoint; reward is 0 while balanced and −1 on failure; the return is where is the step when balance is lost. Both formulations lead the agent to balance the pole as long as possible. The continuing formulation handles the infinite-horizon case without the sum diverging.
Pitfalls:
- Using in a continuing task. The return becomes infinite and the math breaks. Always use for continuing tasks.
- Confusing the two formulations. An episodic task with per step and a continuing task with on failure are different problems with different optimal policies. Do not mix them up.
- Thinking episodes must be independent. In practice, the starting state of each episode may depend on how the previous one ended. The theory handles this, but be aware of it.
Recap + Bridge: Episodic tasks have natural endpoints; continuing tasks do not. Episodic tasks use undiscounted finite returns; continuing tasks need discounting to keep returns finite. The return formula works for both. Next, we define what a policy is — the rule that tells the agent what action to take in each state.
The choice between episodic and continuing formulation affects everything downstream: the return, the value functions, and the algorithms. The textbook notes that the pole-balancing task can be modeled either way, and both are valid. The continuing formulation is slightly more general.
5.4 Policy
Hook: If an MDP is the world, a policy is the agent's playbook. Given any situation, the policy says what to do. It is the core object that RL algorithms try to learn.
5.4.1 Definition and Explanation
Intuition + Analogy: Think of a policy like your personal chess strategy. You have a rulebook: "If the opponent plays e4, I play e5. If they play d4, I play d5." The rulebook covers every possible board position. A deterministic policy is a fixed rulebook — one move per position. A stochastic policy adds probabilities — "70% of the time I play e5, 30% of the time I play c5." The stochastic version is useful for exploration and for games where unpredictability helps.
Where the analogy breaks: in chess, the "state" is the board position. In general RL, the state can be anything — sensor readings, game frames, battery levels.
A policy defines the agent's behavior. It maps states to actions.
5.4.2 Symbol Registry
- — policy — function mapping states to actions (or action probabilities)
- — deterministic policy — the single action chosen in state
- — stochastic policy — probability of taking action in state , with
- — state — element of state set
- — action — element of action set
Core Definition:
- A deterministic policy assigns one action to each state:
- A stochastic policy assigns a probability distribution over actions for each state: , where for all
The notation reads "the probability of action given state under policy ."
5.4.3 Example
Consider a grid where from state :
- Going right leads to a high-value state
- Going down leads to a low-value state
Stochastic policy:
- — the agent mostly goes right
- — but occasionally explores going down
Deterministic policy:
- — always go right
- — never go down
In diagrams, arrows show the dominant action under the policy. If multiple arrows appear from a state, the policy assigns positive probability to each.
Pitfalls:
- Confusing policy with value function. The policy says what to do. The value function says how good it is to be somewhere. They are different objects.
- Thinking a policy must be deterministic. Stochastic policies are essential for exploration and are the norm in many RL algorithms.
- Forgetting that is a function, not a single decision. The policy covers every state, not just the current one.
Recap + Bridge: A policy maps states to actions — either deterministically () or stochastically (). It is the object RL algorithms try to optimize. To know how good a policy is, we need value functions. That comes next.
The policy is the central object in RL. Every algorithm — value-based, policy-based, or actor-critic — ultimately produces or improves a policy. Value-based methods compute values first and extract a policy from them. Policy-based methods optimize the policy directly. Both are different paths to the same goal: finding a good .
5.5 State Value Function (Vπ)
Hook: You are standing at a crossroads. One road leads to a busy city; the other leads to a desert. How do you know which road is better? You need a way to score each location. That is what a value function does — it assigns a number to every state that says "how good is it to be here?"
5.5.1 Definition and Explanation
Intuition + Analogy: Think of each state as a city on a map, and the value function as a "prosperity score" for each city. If you follow policy (your travel plan), the score tells you the expected total reward you will collect starting from that city. A city near a gold mine (high-reward state) has a high score. A city in the middle of nowhere has a low score. The score depends on the policy — if your travel plan is bad, even a city near a gold mine might have a low score because you never reach it.
Where the analogy breaks: the value is not about the state alone. It depends on what you do after arriving. A state with two great next moves is better than the same state with two bad next moves, even though the immediate reward might be the same.
The state value function quantifies how good it is to be in state when following policy . It is the expected return starting from and following thereafter.
Core Definition:
The subscript means the expectation is taken over all actions chosen according to and all environment transitions. The value of a state depends on how the agent behaves — change the policy, and the values change.
The value of a terminal state is always zero: .
5.5.2 Mathematical Formulation
The verbal description: "The value of state under policy is the expected cumulative discounted reward if you start in and follow from then on."
Expanding the return :
This sums over all possible future trajectories, each weighted by its probability under and the environment dynamics .
5.5.3 Symbol Registry
- — state value function under policy — scalar
- — return from time (cumulative discounted reward) — scalar
- — discount factor — scalar in
- — policy — function mapping states to action probabilities
5.5.4 Example with Numerical Values
Consider a grid where states have values under policy :
- A state with is better than one with
- The agent should prefer moving toward higher-valued states
What does a value of 70 mean? "If I am in this state and follow policy from now on, the expected total discounted reward I will collect is 70."
The value depends on everything that happens after — not just the next step. If a state leads to a long chain of small rewards, it might have a higher value than a state that gives one big reward and then nothing.
In a grid world under an equiprobable random policy (each action equally likely), states near the edges have low or negative values (the agent often bumps into walls and gets −1 reward). States near special high-reward locations have high values.
Pitfalls:
- Thinking V depends only on the state. It depends on the policy too. The same state can have different values under different policies.
- Confusing V with immediate reward. is about all future rewards, not just the next one. A state with immediate reward 0 might have high value if it leads to great future rewards.
- Forgetting that V is an expectation. The actual return from a state will vary due to randomness in actions and transitions. is the average over many runs.
Recap + Bridge: The state value function tells you the expected return from state under policy . It depends on the policy — change and changes. But only tells you how good the state is. What if you want to know how good a specific action is from that state? That is the action value function .
State values are the first building block for RL algorithms. Policy evaluation (covered later) computes for a given policy. Policy improvement uses to find a better policy. This cycle — evaluate, improve, repeat — drives all dynamic programming methods.
5.6 Action Value Function (Qπ)
Hook: You know the value of being in a city (state value). But you are at a fork in the road — one path goes north, another goes south. Which path is better? You need the value of each action, not just each state. That is what gives you.
5.6.1 Definition and Explanation
Intuition + Analogy: Think of GPS navigation. You type in your destination. The GPS does not just tell you "you are in a good location." It tells you the expected travel time for each possible route from where you are. The Q-function is that GPS — it tells you the expected return for each action you could take from your current state, assuming you follow policy afterwards.
Where the analogy breaks: GPS gives you a deterministic answer (take this route). The Q-function accounts for randomness — the same action can lead to different outcomes, and averages over them.
The action value function quantifies how good it is to take action in state and then follow policy thereafter.
Core Definition:
The key difference from : the expectation is conditioned on taking a specific action at time . After that, the agent follows .
5.6.2 Symbol Registry
- — action value function under policy — scalar
- — return from time — scalar
- — discount factor — scalar in
- — policy probability — scalar in
- — state value function — scalar, related by
The relationship between and :
The state value is the expected Q-value, weighted by the policy probabilities.
5.6.3 Mathematical Formulation
This conditions on a specific action being taken at time , then follows for all later steps.
5.6.4 Why Q is Preferred Over V
Key advantage: When action outcomes are uncertain, knowing only state values () makes action selection hard. You would need to compute:
for every action — which requires knowing the transition probabilities . With Q-values, you skip that step. Just look up for each action and pick the highest.
The textbook puts it well: Q-values "effectively cache the results of all one-step-ahead searches."
Recycling Robot Example
From state "high":
- Search: may lead to "high" (probability ) or "low" (probability )
- Wait: stays in "high" (deterministic)
If you only know and , computing which action is better requires knowing , the transition probability. But if you know and , you just compare them:
- Pick search if
- Pick wait otherwise
No transition probabilities needed at decision time. Q-values are "ready-made" decision tools.
When action outcomes are deterministic (pressing a brake always stops the car), suffices because there is only one outcome per action. But when outcomes are stochastic, is far more practical.
Pitfalls:
- Confusing Q and V. is the value of being in state . is the value of doing action in state , then following . They are related but different.
- Forgetting that Q conditions on one action. After taking action , the agent follows . It does not keep picking the same action .
- Thinking Q requires no model. Computing Q from scratch still needs transition probabilities. The advantage is that once Q is known (computed or learned), using it for decisions requires no model.
Recap + Bridge: The action value function tells you the expected return for taking action in state and then following . It is more useful than for action selection because it directly compares actions without needing the environment model. Both and satisfy recursive relationships called Bellman equations — that is what we tackle next.
Q: Why are we more interested in Q than V?
A: In problems where action outcomes are uncertain, computing the value of an action from requires summing over all possible outcomes weighted by their transition probabilities — that needs a model. If you have pre-computed Q-values, action selection is trivial: just pick the action with the highest Q-value. The Q-values are "ready-made" decision tools. This is why Q-learning (a model-free method based on Q) became so popular.
The Q-function is central to many RL algorithms. Q-learning (Chapter 6 in the textbook) learns directly from experience without knowing the transition probabilities. Deep Q-Networks (DQN) approximate with neural networks to play Atari games. The concept extends from this simple definition to state-of-the-art methods.
5.7 Bellman Expectation Equation
Hook: You want to know the value of your current apartment. You could live there for years and track all the rewards. Or you could just ask: "What are the neighboring apartments worth, and how much do I enjoy the move?" That one-step lookahead gives you the answer. The Bellman equation makes this precise — it connects the value of a state to the values of its successor states.
5.7.1 Definition and Explanation
Intuition + Analogy: Think of planning dinner. Tonight's meal value depends on two things: how much you enjoy tonight's dinner (immediate reward), and how good tomorrow's meal options will be (discounted future value). The Bellman equation says: the value of being in state equals the expected immediate reward plus the expected discounted value of wherever you end up next.
This is recursive — the value of is expressed in terms of values of successor states . Those successor values are in turn expressed in terms of their successors, and so on. The Bellman equation is the starting point for computing value functions.
The Bellman expectation equation defines recursively:
Core Definition:
Reading this step by step:
- Outer sum over actions : For each action, weight by — how likely the agent is to pick that action under the policy.
- Inner sum over next states and rewards : For each possible outcome, weight by — how likely the environment is to produce that outcome.
- Bracket : The immediate reward plus the discounted value of the next state.
The equation has two sources of probability:
- — the policy (agent's behavior)
- — the dynamics (environment's behavior)
5.7.2 Mathematical Formulation
The full Bellman equation for :
This is a system of linear equations in unknowns (one equation per state). For a finite MDP, this system has a unique solution as long as or eventual termination is guaranteed.
The textbook derives this from the return's recursive structure:
Using (the recursive return relation), the expectation separates into the immediate reward and the discounted expected future value.
5.7.3 Symbol Registry
- — probability of taking action in state under policy — scalar in
- — dynamics function — probability of transitioning to state with reward given state and action
- — next (successor) state — element of
- — immediate reward — scalar
5.7.4 Understanding the Two Levels of Probability
The equation involves two distinct probability sources:
- Policy probability : How likely the agent is to choose action in state . This is under the agent's control — it defines the behavior.
- Model dynamics : How likely the environment is to transition to state with reward . This is outside the agent's control — it defines the world.
If action outcomes are deterministic (action always leads to exactly one state with reward ), the inner sum collapses to a single term — the dynamics probability is 1 for that outcome, and 0 for all others.
5.7.5 Backup Diagram
The backup diagram shows the recursive structure visually:
- Open circles represent states (where you are)
- Solid circles represent action choices (decision points)
- From a state node, lines fan out to action nodes (one per possible action, weighted by )
- From each
Figure 5.7: Bellman Expectation Backup Diagram for State-Value Function . Starting at root state node , the agent selects action with probability . The environment transitions to next state with reward according to dynamics . The state value is computed by backing up the discounted expected return across all branches. 5.7.6 Worked Example: Expressing V in Terms of Q
The state value can be written using Q-values:
Numerical example: Suppose policy gives:
Action up 0.7 10 right 0.1 20 down 0.1 15 left 0.1 20 Sense-check: The policy heavily favors "up" (Q = 10), so the state value is close to 10. The other actions have higher Q-values but are chosen rarely, so they pull the average up slightly to 12.5. This makes sense.
5.7.7 Worked Example: Computing Q-Value
From state , take action "up". The Q-value depends on all possible outcomes:
Deterministic case: "up" always leads to one state with reward 20 and that state has value 70. With :
Stochastic case: "up" leads to four possible outcomes:
Outcome Probability Reward Next state value Contribution Go up 20 70 Go down 10 100 Go right 30 80 Go left 20 100 where .
Assumptions & Scope:
- Requires known dynamics. To compute from the Bellman equation, you need . In model-free RL, you do not have this — so you sample transitions instead.
- Requires a defined policy. The Bellman equation is for a given . It evaluates that policy. Finding the best policy is a separate problem (Bellman optimality equation, Section 5.9).
- Linear system. For states, you have equations in unknowns. For small state spaces, you can solve directly. For large spaces, you use iterative methods (policy evaluation, covered in DP chapter).
Pitfalls:
- Confusing the Bellman expectation equation with the Bellman optimality equation. The expectation equation uses — a weighted average over actions. The optimality equation uses — the best action. They look similar but solve different problems.
- Forgetting the two probability layers. The outer sum is over actions (policy probability). The inner sum is over outcomes (environment dynamics). Mixing them up leads to wrong formulas.
- Thinking V and Q are independent. They are tightly linked: and . You can express one in terms of the other.
Recap + Bridge: The Bellman expectation equation connects the value of a state to the values of its successors through a one-step lookahead. It involves two probability layers: the policy and the dynamics. Solving this equation gives you for a given policy. Next, we verify this equation by hand on a grid world example.
Q: We have two probabilities here — policy and model dynamics. What if each action leads to only one state?
A: Then the model dynamics probability is 1 for that single outcome. The branch collapses to a single path. You just multiply: probability of taking that action (from policy) times (reward + gamma times next state value). No inner sum needed.
Q: What does "expectation with respect to " mean exactly?
A: It means the average is computed using 's probability distribution over actions. If , then 70% of the weight goes to the "up" outcome. It is like computing your expected commute time using your historical driving habits — the expectation depends on your behavior pattern.
5.8 Policy Evaluation & 1D Grid Example
Hook: Before we can find the best policy, we must answer a simpler question: how good is a given policy? Policy evaluation computes the state-value function for a fixed policy . It turns the Bellman expectation equation into an iterative update rule that sweeps across all states until values stabilize.
5.8.1 Iterative Policy Evaluation Algorithm
Policy evaluation answers the prediction problem: if an agent follows policy indefinitely, what is the expected return from each state? Iterative policy evaluation starts with arbitrary initial values (with ) and repeatedly applies the Bellman expectation backup:
Pseudocode (Iterative Policy Evaluation):
Input: policy pi to be evaluated
Parameter: small threshold theta > 0
Initialize V(s) arbitrarily for all s in S+, with V(terminal) = 0
Loop:
Delta <- 0
For each s in S:
v <- V(s) # store old value
V(s) <- Sum_a pi(a|s) Sum_{s',r} p(s',r|s,a) [r + gamma * V(s')] # expectation backup
Delta <- max(Delta, |v - V(s)|) # track largest change
Until Delta < theta
Output: approximation V approx v_pi
Each complete pass through all states is called a sweep. In a sweep, the algorithm replaces the old value of each state by the expected one-step return under policy . When , the values have stabilized within the specified precision.
5.8.2 Worked Example: One-Dimensional 5-Cell Grid Line
Environment Setup:
Consider a 5-cell line with states 1, 2, 3, 4, 5:
- State 1: Bad terminal state (entering gives reward )
- State 5: Good terminal state (entering gives reward )
- State 3: Start state
- Nonterminal states: 2, 3, 4
- Actions: Left (L) or Right (R), deterministic movement
- Discount factor: (undiscounted episodic task)
- Initialization: ,
We evaluate three different fixed policies across four iterative sweeps:
| Policy | Action Probabilities | Sweep 1 | Sweep 2 | Sweep 3 | Sweep 4 |
|---|---|---|---|---|---|
| Policy A (Mostly Left) | |||||
| Policy B (Equal Probability) | |||||
| Policy C (Mostly Right) |
Step-by-Step Sample Trace (Policy A, Sweep 1 & 2):
- Sweep 1:
- Sweep 2 (Not-in-place using ):
Interpretation: Under Policy A (mostly left), state values become increasingly negative because the agent is far more likely to end up in the bad terminal state. Under Policy C (mostly right), values turn positive as information from the good terminal propagates backward. Policy evaluation does not change the policy — it measures how good the fixed policy is.
5.8.3 4x4 Grid World Setup & Converged State Values
Now consider a 4×4 grid world with two special teleport states:
- State A (row 1, col 2): Any action yields reward and teleports to (row 3, col 1, value )
- State B (row 1, col 4): Any action yields reward and teleports to (row 3, col 4)
- Normal moves: Reward 0, move one cell in chosen direction
- Off-grid moves: Moving off the grid keeps agent in place with reward
- Policy: Equiprobable random for all 4 actions,
| Col 1 | Col 2 (A) | Col 3 | Col 4 (B) | |
|---|---|---|---|---|
| Row 1 | 3.3 | 8.8 | 4.4 | 5.3 |
| Row 2 | 1.5 | 3.0 | 2.3 | 1.9 |
| Row 3 | 0.1 | −0.4 | −0.4 | −0.6 |
| Row 4 | −1.0 | −1.2 | −1.4 | −1.6 |
5.8.4 Worked Verification: Cell (3,3) and State A
Cell (3,3) Verification:
- Up → cell (2,3),
- Right → cell (3,4),
- Down → cell (4,3),
- Left → cell (3,2),
State A Verification: From A, all actions give and transition to ():
5.9 Policy Improvement & Policy Improvement Theorem
Hook: Once we evaluate a policy , we can use it to form a better policy. By looking one step ahead from state and picking the action that maximizes expected return, we construct a greedy policy . Is guaranteed to be better than ? Yes — and the Policy Improvement Theorem proves it.
5.9.1 Constructing a Greedy Policy
Given the value function for a policy , the expected return for taking action in state and then following is:
A new greedy policy selects the action that achieves the maximum one-step lookahead return:
5.9.2 Policy Improvement Theorem
Theorem Statement: Let and be any pair of deterministic policies such that, for all :
Then the policy is at least as good as ; that is, for all :
If at any state, then is strictly better than in at least one state.
Proof of Policy Improvement Theorem:
Starting from state , we expand by repeatedly substituting :
Thus, by replacing old policy choices with greedy action choices step by step, the expected overall return can only increase or remain equal. If no longer yields higher value, then and the policy satisfies the Bellman optimality equation — making it optimal!
5.10 Policy Iteration Algorithm & Race-Car Demonstration
Hook: Policy iteration is the systematic DP algorithm that alternates between two steps: (1) full policy evaluation (computing ), and (2) policy improvement (making greedy w.r.t. ). Because finite MDPs have a finite number of policies, policy iteration converges to an exact optimal policy in a finite number of iterations.
5.10.1 Policy Iteration Pseudocode
Pseudocode (Policy Iteration):
1. Initialization
V(s) in R and pi(s) in A(s) arbitrarily for all s in S
2. Policy Evaluation
Repeat:
Delta <- 0
For each s in S:
v <- V(s)
V(s) <- Sum_{s',r} p(s',r | s, pi(s)) [r + gamma * V(s')]
Delta <- max(Delta, |v - V(s)|)
Until Delta < theta (a small positive number)
3. Policy Improvement
policy_stable <- true
For each s in S:
old_action <- pi(s)
pi(s) <- argmax_a Sum_{s',r} p(s',r | s, a) [r + gamma * V(s')]
If old_action != pi(s), then policy_stable <- false
If policy_stable is true, then stop and return V approx v* and pi approx pi*
Else go back to Step 2 (Policy Evaluation)
5.10.2 Race-Car Demonstration for Policy Iteration
Problem Setup:
Three states: Cool, Warm, Overheated (Terminal). Actions: Slow, Fast. Discount factor .
- Cool + Slow: stay Cool (),
- Cool + Fast: move Cool (), ; Warm (),
- Warm + Slow: move Cool (), ; Warm (),
- Warm + Fast: move Overheated (),
Step 1: Initial Policy :
Evaluating by solving the linear system of Bellman expectation equations:
Step 2: Policy Improvement Step:
Compute one-step action-value lookaheads :
- Cool State:
- Warm State:
Outcome: The policy updates to . Since , we proceed to the next iteration of policy evaluation. Policy iteration clearly separates understanding the policy from improving it.
5.11 Optimal Policies & Optimal Value Functions
Hook: An optimal policy squeezes the maximum possible expected return out of every state. The optimal value functions and satisfy the Bellman optimality equation — replacing the policy-weighted average with a over actions.
5.11.1 Mathematical Formulation
5.12 Value Iteration Algorithm & Grid Demonstrations
Hook: While policy iteration evaluates to completion before improving, value iteration fuses policy evaluation and policy improvement into a single update sweep. It directly applies the Bellman optimality backup to converge directly to .
5.12.1 Value Iteration Algorithm Pseudocode
Pseudocode (Value Iteration):
Parameter: small threshold theta > 0
Initialize V(s) arbitrarily for all s in S+, with V(terminal) = 0
Loop:
Delta <- 0
For each s in S:
v <- V(s)
V(s) <- max_a Sum_{s',r} p(s',r | s, a) [r + gamma * V(s')] # optimality backup
Delta <- max(Delta, |v - V(s)|)
Until Delta < theta
Output: deterministic policy pi approx pi* such that
pi(s) = argmax_a Sum_{s',r} p(s',r | s, a) [r + gamma * V(s')]
5.12.2 In-Place vs Not-In-Place Updates
Critical Exam Distinction:
- Not-in-place (Two-Array): Uses two separate arrays and . Every state update in sweep reads strictly from the old array .
- In-place (Single Array): Updates state values directly in a single array. If state is updated first in a sweep, state immediately uses 's updated value in the same sweep.
In-place updates propagate new value information significantly faster through the state graph, reducing the number of sweeps required for convergence.
5.12.3 Worked Example: 3x3 Grid Value Iteration Propagation
Environment: 3×3 grid with Good terminal at (1,3) giving reward and Bad terminal at (3,1) giving reward . All other rewards are 0. Illegal moves leave the agent in place. , .
Not-in-place Value Sweeps ( to ):
Highlighted Verification Computations:
- Green Entries at : Cells (1,2) and (2,3) are adjacent to Good terminal (1,3). Moving into (1,3) gives reward , so .
- Blue Entry at , Cell (2,2): Best successor cell is (1,2) or (2,3) with previous value 5:
- Purple Entry at , Cell (2,1): Best successor cell is (2,2) with previous value 4.5:
This demonstrates how positive terminal rewards propagate backward across the state space with each iteration sweep.
5.13 Asynchronous Dynamic Programming
Hook: Full-sweep DP algorithms update every state in every iteration. In large MDPs, full sweeps are computationally prohibitive. Asynchronous DP algorithms break this rigidity by updating selected states in arbitrary orders using whatever values are currently available.
5.13.1 Backup Formula and Scheduling
The basic asynchronous value-iteration backup for a selected state is:
5.13.2 Practical Advantages and Convergence
- Large Tabular MDPs: Avoids spending computational effort on irrelevant or unvisited states.
- Real-Time Planning: Interleaves DP updates with real interaction, focusing updates on states near the agent's current trajectory.
- Prioritized Sweeping: Updates states with large Bellman errors earlier to accelerate convergence.
- Convergence Guarantee: Asynchronous DP converges to provided no state is systematically ignored forever (i.e., every state is updated infinitely often).
5.14 Generalized Policy Iteration (GPI)
Hook: Generalized Policy Iteration (GPI) is the overarching paradigm of RL. It describes the competing yet cooperative interaction between policy evaluation (making consistent with ) and policy improvement (making greedy w.r.t. ).
5.14.1 The GPI Spectrum
Almost all RL algorithms can be viewed as different granularities of GPI:
- Policy Iteration: Coarse-grained GPI. Complete policy evaluation runs to full numerical convergence before a single greedy policy improvement step is taken.
- Value Iteration: Fine-grained GPI. Policy evaluation is truncated to exactly one sweep before taking a greedy improvement step.
- Asynchronous DP: Flexible GPI. Evaluation and improvement backups are applied asynchronously to selected individual states.
- Monte Carlo & TD Control (SARSA/Q-learning): Sample-based GPI. Evaluation is learned from sampled experience transitions, and policy improvement proceeds incrementally.
5.15 Issues in Applying Dynamic Programming Methods
Hook: While DP provides exact solutions to finite MDPs, scaling DP to real-world applications highlights fundamental computational bottlenecks.
5.15.1 Detailed Breakdown of Practical Challenges
- Full Sweeps over State Space: Performing systematic passes over millions of states becomes computationally intractable. Asynchronous and prioritized updates mitigate this burden.
- Extracting Policy from State Values vs Action Values: Extracting from state values requires a one-step lookahead using the model dynamics . Action values eliminate this model requirement at decision time.
- Policy Stabilization before Value Convergence: In many control tasks, the greedy policy stops changing long before value numbers fully converge to decimal precision. Monitoring policy stability prevents unnecessary sweeps.
- Need for a Known Environment Model: DP requires explicit transition probabilities . Model-free RL methods (Monte Carlo, TD) replace expected backups with sampled transitions when dynamics are unknown.
- Finite and Discrete Action Sets: Tabular DP enumerates actions. Continuous action spaces (e.g., steering torque) require discretization or policy-gradient actor-critic methods.
- Curse of Dimensionality / State Space Explosion: Storing tabular values scales exponentially with state variables. High-dimensional state spaces necessitate function approximation (deep neural networks).
- When DP is Appropriate: Tabular DP is best suited for small, fully specified MDPs, offline planning simulators, and as the theoretical backbone for modern RL.
5.16 Practice Review Questions
Practice Problems: Below are 16 exam-style questions covering conceptual, numerical, and modeling exercises from Lecture 5.
Q1: Define DP in finite MDPs. Why is it a planning method and what model information is required?
Solution: Dynamic programming is a class of planning algorithms that compute optimal policies using recursive Bellman equations. It is a planning method because it computes value functions using a known model of environment dynamics without requiring real physical interaction.
Q2: State the Bellman equation for and explain how it separates components.
Solution: . It separates: (1) action choices via policy , (2) transition dynamics , (3) immediate rewards , and (4) discounted successor state values .
Q3: In iterative policy evaluation, why is the policy kept fixed? What is updated and why use ?
Solution: The policy is kept fixed to isolate the prediction problem (evaluating ). During each sweep, state values are updated using the expectation backup. measures the maximum value change in a sweep to determine when values have converged below threshold .
Q4: On the 5-cell line (bad terminal 1 R=-1, good terminal 5 R=+1, γ=1), compute the first 2 sweeps for Policy A () starting from zero values.
Solution: Sweep 1: . Sweep 2: .
Q5: Why does the middle state on the 5-cell line have value 0 under equal-probability policy but negative under mostly-left policy?
Solution: Under equal probability (), symmetric probabilities and opposite terminal rewards ( vs ) cancel out. Under mostly-left (), trajectory pathways favor reaching the bad terminal state 1, driving value negative.
Q6: State the Policy Improvement Theorem and explain why greedy action selection cannot make a policy worse.
Solution: If for all , then . Greedy choice guarantees that taking the new action for one step and following thereafter is no worse than following immediately; unrolling this inequality across all future time steps guarantees .
Q7: In Race-Car with , compute lookahead values for Slow and Fast in Cool and find the greedy action.
Solution: . . Greedy action is Fast (3.35 > 2.8).
Q8: In Race-Car with , compute value iteration backup for Warm and explain why max avoids Fast.
Solution: Slow: . Fast: . . Max avoids Fast because of the catastrophic penalty from overheating.
Q9: Compute the in-place update for Warm if Cool is updated first to 3.35 while Warm is 1 (). Compare with not-in-place 2.35.
Solution: In-place update uses new immediately: . Not-in-place gives 2.35 because it used old . In-place is larger because new information propagates faster.
Q10: Formulate a Hospital MDP: 3 states (Mild, Serious, Recovered), actions (Standard, Aggressive). Identify MDP tuple.
Solution: States ; Actions ; Rewards: Recovered , Serious , side effect penalty ; Transitions: probability of recovery vs side-effect progression under treatment choice.
Q11: Formulate Bellman optimality backup for a Warehouse Robot on a 25-cell grid (+10 packing, -5 collision, -1 move).
Solution: . Value iteration evaluates 4 direction transitions, adds step reward , discounts successor cell values, and selects the maximum.
Q12: In 3x3 Grid, compute and from displayed matrices and state chosen successor cell.
Solution: (chosen successor cell (1,2)). (chosen successor cell (2,2)).
Q13: Explain Asynchronous DP. Under what condition does it converge, and give a situation where it is useful.
Solution: Asynchronous DP updates selected states in place without uniform sweeps. It converges to if every state is updated infinitely often and no state is unvisited indefinitely. Useful in real-time robot planning to focus updates on states near current location.
Q14: Explain GPI and show how Policy Iteration, Value Iteration, and TD control are different granularities.
Solution: GPI is the interaction of policy evaluation and improvement. Policy Iteration evaluates to full convergence before improving. Value Iteration truncates evaluation to 1 sweep per improvement step. TD control uses single sampled transitions to update values and adjust policy greedily.
Q15: Compare Policy Iteration and Value Iteration across 4 dimensions.
Solution: (1) Evaluation effort: Policy Iteration runs to full convergence per step; Value Iteration does 1 sweep. (2) Max operator: Policy Iteration uses only in improvement phase; Value Iteration embeds inside every backup. (3) Stopping criterion: Policy Iteration stops when stabilizes; Value Iteration stops when . (4) Early stabilization: Policy Iteration detects policy stability directly.
Q16: Why is classical DP difficult for a delivery robot with 100,000 states and unknown model? What RL methods apply?
Solution: Classical DP requires explicit transition probabilities and full state sweeps. With unknown dynamics and large state count, model-free TD/Q-learning or Deep Q-Networks (DQN) with function approximation become necessary.
Exam Guidance Summary
Policy evaluation and policy improvement are two primitive steps present in every DP algorithm. Understanding these building blocks is critical — they appear in value iteration, policy iteration, and generalized policy iteration.
In-place vs not-in-place value iteration: Be careful to distinguish which version you are using. The not-in-place version uses old values from the previous sweep. The in-place version uses the most recently computed values. Questions may specify either one. The in-place version converges faster.
Bellman equation application: Expect numerical problems where you verify state values using the Bellman equation. Practice by hand: pick a state, look up neighbor values, apply the equation, check the result. The grid world examples in Sections 5.8 and 5.12 are your templates.
Understanding the algorithm is more important than memorizing it. If you understand how value iteration works (apply Bellman optimality update, track convergence), you can adapt to different scenarios — different state spaces, different dynamics, different reward structures.
- Solve practice problems from the notes to build facility with the computations. The race car problem and grid world verification are the types of questions to expect.
- The notes cover the complete story and should be read with no omissions. Every section builds on the previous one.
- Policy iteration and value iteration are both essential algorithms to know. Focus on understanding their update rules, convergence criteria, and the in-place vs not-in-place distinction.
Key Industry Applications
- Traffic control: The MDP framework models traffic signal optimization. States represent traffic conditions, actions are signal changes, and rewards reflect flow efficiency. City traffic systems use RL to learn signal timing policies that reduce congestion.
- Atari games: The classic RL benchmark. States are raw game frames (pixels), actions are controller inputs, and rewards are score changes. Deep Q-Networks (DQN) use the MDP formulation to learn directly from pixels, achieving superhuman performance on many games.
- Recycling robot: An MDP example for autonomous agents operating under resource constraints. The robot must balance exploration (searching for cans) against conservation (waiting or recharging) — a fundamental trade-off in RL.
- Cart-pole balancing: Demonstrates episodic vs continuing task formulation. The same physical problem can be modeled either way, showing how the MDP framework is flexible. This is a standard testbed for RL algorithms.
- Race car problem: Illustrates policy iteration and value iteration with a simple 3-state MDP (Cool, Warm, Overheated). The agent learns that driving fast is rewarding in the short term but risks overheating — a classic exploration-exploitation and risk-reward trade-off.
- Dynamic programming in operations research: DP methods (policy iteration, value iteration) are used in supply chain management, inventory control, scheduling, and resource allocation — anywhere a known MDP model exists and the state space is tractable.
DRL Lecture 5 Notes · Markov Decision Processes and Dynamic Programming
Sections Breakdown
Exam Revision Notes
Below is the distilled, exam-ready core. Every entry comes from the full explanation above. Use this section for rapid review; return to the main notes when a point needs more context.
5.1 MDP Review and Agent-Environment Interface
Must know: An MDP is the tuple (S, A, p, r, gamma). The agent-environment boundary separates what the agent controls from what it cannot. The Markov property says the future depends only on the current state, not the path taken to reach it.
Pitfall: Placing the agent-environment boundary wrongly: the agent's sensors and actuators belong to the environment, not the agent. The agent only chooses actions.
Self-check: Write the MDP tuple and state in one sentence what each symbol represents.
Connects to: Reward hypothesis (5.2), Policy (5.4), State and action value functions (5.5, 5.6).
5.2 Reward Hypothesis
Must know: Every RL goal is framed as maximizing the expected cumulative discounted return G_t. The reward signal communicates WHAT we want, never HOW to achieve it.
Pitfall: Thinking the reward defines good behaviour. It defines the goal; reward hacking happens when you reward the wrong thing and the agent optimizes that instead.
Self-check: Why must the reward be a single scalar rather than a vector of objectives?
Connects to: Episodic vs continuing tasks (5.3), return appears in every value function (5.5, 5.6).
5.3 Episodic vs Continuing Tasks
Must know: Episodic tasks end at a terminal state and use a finite return. Continuing tasks never end, so discounting with gamma < 1 is required to keep the return finite.
Pitfall: Using gamma = 1 in a continuing task. The return then diverges to infinity and the math breaks.
Self-check: Can cart-pole balancing be modeled both episodically and as a continuing task? Yes — and both lead to balancing.
Connects to: Reward hypothesis (5.2), value functions (5.5).
5.4 Policy
Must know: A policy pi maps states to actions. Deterministic: pi(s) = a. Stochastic: pi(a|s) = P(A_t = a | S_t = s), with sum_a pi(a|s) = 1. It is the object RL algorithms optimize.
Pitfall: Confusing the policy (what to do) with the value function (how good a state is). They are different objects.
Self-check: Give one example of a deterministic policy and one of a stochastic policy.
Connects to: Value functions (5.5, 5.6), Bellman equations (5.7).
5.5 State Value Function V_pi
Must know: V_pi(s) is the expected return starting from state s and following policy pi thereafter. It depends on the policy: change pi and the values change. V_pi(terminal) = 0.
Pitfall: Thinking V depends only on the state. The same state can have very different values under different policies.
Self-check: Why can one state have a high value under a good policy but a low value under a bad one?
Connects to: Action value function Q_pi (5.6), Bellman expectation equation (5.7).
5.6 Action Value Function Q_pi
Must know: Q_pi(s,a) is the expected return for taking action a in state s then following pi. Q is preferred over V for action selection because, once known, it needs no model at decision time.
Pitfall: Confusing Q (value of DOING action a) with V (value of BEING in state s). They are related but distinct.
Self-check: Why is Q more useful than V when action outcomes are stochastic?
Connects to: State value function (5.5), Bellman equations (5.7).
5.7 Bellman Expectation Equation
Must know: V_pi(s) equals the expected immediate reward plus the discounted expected value of successor states, averaging over both the policy and the dynamics. It is a system of |S| linear equations.
Pitfall: Mixing up the two probability layers, or confusing this expectation equation (average over actions) with the optimality equation (max over actions).
Self-check: Name the two distinct probability sources in the Bellman expectation equation.
Connects to: V_pi (5.5), Q_pi (5.6), Bellman optimality (5.11).
5.8 Policy Evaluation & 1D Grid Example
Must know: Policy evaluation computes V_pi for a fixed policy pi using Bellman backups until values converge within threshold theta. Evaluated on a 5-cell line MDP (bad -1, good +1), policies shifting right yield higher values.
Pitfall: Assuming policy evaluation updates the policy. It only measures how good the fixed policy is.
Self-check: What happens to state 3's value when moving from an equiprobable policy to a mostly-right policy on the 5-cell line?
Connects to: Bellman expectation equation (5.7), Policy improvement (5.9).
5.9 Policy Improvement & Policy Improvement Theorem
Must know: Acting greedily with respect to v_pi creates a new policy pi' satisfying q_pi(s, pi'(s)) >= v_pi(s). The Policy Improvement Theorem guarantees v_pi'(s) >= v_pi(s) for all states.
Pitfall: Thinking policy improvement can produce a worse policy. If no change occurs, the policy is optimal.
Self-check: State the condition under which policy improvement guarantees a strictly or equally better policy.
Connects to: Policy evaluation (5.8), Policy iteration (5.10).
5.10 Policy Iteration Algorithm & Race-Car Demonstration
Must know: Policy iteration alternates full policy evaluation and greedy policy improvement until the policy stabilizes (policy-stable = true). Evaluated on 3-state Race-Car (Cool/Warm/Overheated), it upgrades Cool action from Slow to Fast.
Pitfall: Stopping evaluation too early before values stabilize, or continuing iteration after policy choices stop changing.
Self-check: In the Race-Car problem, why does the policy keep Warm as Slow even when Cool switches to Fast?
Connects to: Policy evaluation (5.8), Policy improvement (5.9), Value iteration (5.12).
5.11 Optimal Policies & Optimal Value Functions
Must know: An optimal policy pi* achieves V_{pi*}(s) >= V_pi(s) for all s. The Bellman optimality equation replaces policy-weighted summation with a max over actions.
Pitfall: Confusing max_a (optimality) with the weighted average sum_a pi(a|s) (expectation).
Self-check: Once V* is known, how is the optimal action selected? Take argmax_a of the one-step lookahead.
Connects to: Bellman expectation (5.7), Value iteration (5.12).
5.12 Value Iteration Algorithm & Grid Demonstrations
Must know: Value iteration combines policy evaluation and improvement into a single max update V_{k+1}(s) = max_a [...]. Backups propagate values backward from high-reward terminals across grid cells.
Pitfall: Mixing in-place (uses latest sweep values immediately) with not-in-place (uses old V_k array).
Self-check: Calculate V2(2,2) for a 3x3 grid with γ=0.9 when adjacent cell (2,3) reached V1=5.
Connects to: Bellman optimality (5.11), Policy iteration (5.10).
5.13 Asynchronous Dynamic Programming
Must know: Asynchronous DP updates individual or selected subsets of states in place without full systematic sweeps. Guarantees convergence if no state is unvisited indefinitely.
Pitfall: Assuming states must be updated in a fixed sweep order. Asynchronous DP can update any state at any time.
Self-check: What requirement on state update frequency is necessary for asynchronous DP to converge?
Connects to: Value iteration (5.12), Real-time planning.
5.14 Generalized Policy Iteration (GPI)
Must know: GPI describes the universal interaction between policy evaluation and policy improvement. Algorithms differ by update granularity (Policy Iteration = complete, Value Iteration = single-step, TD/MC = sampled).
Pitfall: Viewing evaluation and improvement as strictly separate steps; in modern RL they frequently interleave continuously.
Self-check: How does Value Iteration represent a fine-grained instance of GPI?
Connects to: Policy iteration (5.10), Value iteration (5.12).
5.15 Issues in Applying Dynamic Programming Methods
Must know: Classical DP requires complete environment dynamics p(s',r|s,a) and finite state/action spaces. It suffers from the curse of dimensionality and requires model-free or function approximation extensions for scale.
Pitfall: Attempting full tabular DP sweeps on high-dimensional or continuous state spaces without discretization or approximation.
Self-check: Why can policy stabilize before value estimates numerically converge?
Connects to: Dynamic programming overview (5.12), Model-free RL.
5.16 Practice Review Questions
Must know: Comprehensive review questions test Bellman backups, policy iteration traces, 1D/3D grid propagation, in-place vs not-in-place updates, hospital/warehouse MDP formulations, and GPI.
Pitfall: Failing to account for transition penalties (-1 off-grid) or wrong discount factor values during manual traces.
Self-check: Trace 2 sweeps of Policy Evaluation on a 5-cell line by hand.
Connects to: All prior sections 5.1 through 5.15.
Was this lecture useful?
BitsNotes AI Assistant
Subject Notes AssistantConfigure AI Chat
Choose how to access the chatbotSigned in as
Powered by BitsNotes — 20 messages per day. No API key needed. Want unlimited access? Use "Bring Your Own Key" mode.
Sign in to use AI Chat
Get 20 free AI messages per day to ask questions about your lecture notes. Sign in with Google or GitHub — it takes 5 seconds.
Sign In to BitsNotesSwitch to "Bring Your Own Key" tab above for unlimited access with any OpenAI-compatible provider.