RL @ ECE-UofT - Lecture 03: Policy and Value Iteration
Overview
Ali Bereyhi derives the Bellman optimality equation for a known Markov decision process, showing how optimal state values can be computed without first knowing the optimal policy, then used to recover optimal actions. He compares policy iteration, which alternates policy evaluation and improvement, with value iteration, which repeatedly applies the optimality backup, and connects both through generalized policy iteration with truncated evaluation.
Key takeaways
- For a known MDP, the Bellman optimality equation computes V* by maximizing expected reward plus next-state value, so finding the optimal policy is not required to solve for the optimal values.
- Once V* is available, compute Q*(s,a) from the transition and reward model, then choose a maximizing action; at least one deterministic optimal policy exists, and tied maximizing actions may also be randomized.
- Policy iteration alternates evaluation and greedy improvement, whereas value iteration applies the maximum over actions at every value update.
- In a finite 4×4 grid example with terminal states 0 and 15 and reward −1 per move, greedy policy improvement directs cells toward a nearest terminal.
- The number of update steps alone does not determine which method is cheaper: policy iteration may warm-start evaluation from previous values, while value iteration repeatedly uses a nonlinear maximum backup.
- Generalized policy iteration unifies the methods: stopping policy evaluation after one update approaches value iteration, while evaluating each policy to convergence approaches policy iteration.
Chapters
- A policy π specifies a probability distribution over actions conditioned on the current state.
- A known MDP supplies transition probabilities and expected rewards for state-action pairs.
- The value function Vπ(s) measures expected return from state s; Qπ(s,a) fixes the first action before following π.
- The Bellman equation replaces an infinite-return sum with a recursive relationship between current and future values.
- The backup diagram represents state values, action values, policy probabilities, and environment transition probabilities as nodes and edges.
- Time progresses from the root toward future states, while value calculations combine information from downstream states.
- The diagram assumes a discount factor of 1 for this recap, simplifying the displayed backups.
- At state s, policy probabilities π(a|s) connect the state to possible action-value nodes.
- After action a, the MDP transition distribution determines which next state is reached.
- An action produces an expected immediate reward, followed by the value associated with the next state.
- A transition can return to the same state, as when a grid-world move hits a wall, even though time continues forward.
- For a state-action pair, Qπ(s,a) equals expected immediate reward plus expected next-state value, with discounting omitted in the simplified diagram.
- Vπ(s) averages action values using π(a|s), so it depends on both the environment and the chosen policy.
- For a finite MDP, these relationships produce a system of equations that can be solved for state or action values.
- Because Vπ(s) is an average of action values, it cannot exceed the largest available action value at s.
- A policy that assigns probability 1 to a maximizing action attains that maximum, motivating a deterministic optimal choice.
- The optimal policy is characterized by selecting actions that maximize Q*(s,a), which includes rewards and future returns rather than only immediate reward.
- Applying the ordinary Bellman equation to an optimal policy expresses Q*(s,a) using the optimal value of each possible next state.
- Substituting V*(s) = maxₐ Q*(s,a) yields an equation for V* that no longer requires the optimal policy as an input.
- For each state, the resulting optimality backup maximizes expected reward plus discounted next-state value over available actions.
- Once V* is known, compute Q*(s,a) from the transition model and reward function.
- Choose an action maximizing Q*(s,a) at each state to obtain an optimal policy.
- The optimality equation is nonlinear because of its max operator, unlike policy evaluation for a fixed policy, which forms a linear system.
- Fixed-policy Bellman equations are linear in the unknown values, while the Bellman optimality equations include a maximum over actions.
- Directly solving the optimality system can require checking which action attains each maximum before solving the resulting equations.
- Bereyhi introduces a four-cell grid world to illustrate those case checks and the optimality backups.
- The example has terminal state 0, where every action yields zero reward and the state value is zero.
- In nonterminal cells, moves toward adjacent cells receive reward −1, while hitting a wall receives reward −0.5.
- The four actions are represented as left, down, right, and up; transitions are deterministic in this example.
- For state 1, each candidate action contributes its immediate reward plus the value of the resulting state.
- A wall collision makes the next state the current cell, so the equation can contain the value being solved for.
- The equations for states 1, 2, and 3 jointly determine the nonterminal optimal values.
- The example’s optimal values are −1 for states one and two, and −2 for state three, matching the shortest routes to terminal state zero.
- After finding V*, the standard Bellman equation gives optimal action values, and maximizing them identifies the policy.
- A state’s value is defined independently of the time at which the process entered that state, assuming the MDP’s state captures the relevant information.
- At state 1, moving left has action value −1, greater than the alternatives in the four-cell example.
- At state 3, moving left and moving up can tie for the maximum action value, so either action is optimal.
- A deterministic optimal policy always exists for the finite known MDP discussed; when actions tie, randomized mixtures over maximizing actions are also optimal.
- Directly solving large Bellman systems may be impractical, even when the MDP model is known.
- Dynamic programming can solve recursive value equations by repeatedly applying their update rule.
- Bereyhi illustrates fixed-point iteration with x = f(x), where each new estimate is computed as xₖ₊₁ = f(xₖ).
- For x = 1/(2+x), starting at zero produces estimates that approach the solution x = −1.
- Algebraically equivalent rearrangements can behave differently under iteration; the lecture’s x = −1 − x² form can diverge from some starting points.
- The Bellman updates used here have properties that support convergence under the assumptions of the MDP setting.
- Policy iteration repeatedly evaluates a current policy, then improves it using action values.
- Value iteration applies the Bellman optimality update directly until the optimal values stabilize, then extracts a policy.
- Both methods use recursive backups, but one alternates evaluation and improvement while the other maximizes during every value update.
- For a fixed policy π, initialize one value estimate per state; for a finite MDP, these estimates form a vector or table.
- The Bellman expectation equation computes each updated value from the expected reward and next-state values under π.
- With a known model, the transition probabilities and expected rewards are used directly rather than estimated from sampled experience.
- Replace each state’s current estimate with the right-hand side of its Bellman evaluation equation.
- Repeat the update until values change by less than a chosen tolerance.
- Initializing terminal-state values to zero supplies a useful boundary condition; all-zero initialization is a convenient starting point in the examples.
- The evaluation algorithm tracks the largest absolute value change across states, often denoted Δ.
- Stop when Δ falls below a threshold ε; a smaller ε gives a more accurate estimate but generally requires more updates.
- The value function is stored as a state-indexed table for a finite MDP, not as an unspecified abstract object.
- For the supplied policy, state 0 is terminal and has value zero, while the other cells receive immediate reward −1 in the described moves.
- Under the example policy, states 1 and 2 transition to state 0, while state 3 transitions to state 2.
- Starting with zero estimates, a small number of Bellman updates propagates the terminal values backward through this simple grid.
- After evaluating π, use its value function to compute Qπ(s,a) for every state-action pair.
- If π chooses an action that does not maximize Qπ at a state, replace it with a maximizing action to form an improved policy.
- The policy-improvement result guarantees that this greedy change is at least as good as the previous policy, given exact evaluation.
- A policy that sends state 1 downward produces a return of −3, while moving left reaches the terminal state for −1.
- Comparing Qπ values reveals that the current state-1 action is not greedy, so policy improvement changes it to the left action.
- Other states whose actions already maximize Qπ remain unchanged; repeated evaluation and improvement can reach an optimal policy.
- Policy iteration starts with an initial policy π₀, evaluates it, and then constructs a greedy improved policy.
- The process repeats with the new policy until improvement makes no changes.
- Exact policy iteration uses a nested procedure: the inner loop evaluates one policy, while the outer loop changes policies.
- The inner policy-evaluation loop updates values until the selected stopping condition is met.
- The outer loop computes action values and improves the policy across all states, not just one state.
- Evaluation of a new policy can start from the previous policy’s value vector, which may reduce the number of updates needed.
- Value iteration initializes a value estimate for each state and applies the Bellman optimality backup repeatedly.
- Each update uses the current values to calculate every action’s expected return, then takes the maximum.
- After values converge, compute action values and select maximizing actions to construct the optimal policy.
- For each state s, update V(s) using maxₐ of expected reward plus discounted next-state value.
- Continue until the largest difference between successive value vectors is below a tolerance.
- The lecture’s displayed pseudocode mistakenly labels some value-iteration quantities with π; Bereyhi clarifies that value iteration does not maintain a policy during its value updates.
- Both methods compute expected reward and next-state value for each available action.
- Policy evaluation averages those action returns using π(a|s), while value iteration takes their maximum.
- Value iteration effectively performs an optimality improvement at every backup instead of waiting for a policy’s values to converge first.
- Policy iteration fully evaluates a policy before using its action values to improve it.
- Value iteration uses interim value estimates to make maximizing updates at every step, so it does not require a sequence of fully evaluated intermediate policies.
- The approaches can differ in iteration count and approximation quality, so value iteration is not automatically cheaper in every setting.
- Initialize V₀, repeatedly apply the optimality backup, and monitor the maximum statewise update magnitude.
- Once values stabilize, calculate Q*(s,a) from the MDP model and choose a maximizing action for each state.
- Bereyhi distinguishes this single final policy extraction from policy iteration’s repeated policy updates.
- The worked example uses a 4×4 grid with terminal states 0 and 15, and a reward of −1 for every move, including moves into walls.
- A random policy chooses up, down, left, or right with probability 1/4 at each nonterminal cell.
- Starting from zero values, the first evaluation update assigns −1 to nonterminal cells because the immediate reward is −1 and the assumed next-state values are zero.
- Repeated evaluation updates propagate more accurate values across the 4×4 grid under the random policy.
- Policy improvement compares each direction’s action value and selects moves with the largest return, steering states toward a terminal.
- Cells near terminal states can become optimal after an early improvement, while larger grids may require additional policy-improvement rounds.
- Value iteration starts with zero estimates for the grid’s optimal values and repeatedly applies the maximum-action backup.
- Once the values stabilize, action values identify shortest routes to terminal states 0 or 15 under the −1-per-step reward.
- The final greedy policy can match the policy-iteration result even though value iteration does not evaluate a sequence of explicit policies.
- Policy iteration’s total work depends on the updates used to evaluate each policy, such as K₁ for π₀ and K₂ for π₁.
- Value iteration’s cost depends on the number of optimality backups required for convergence, which can exceed the combined policy-evaluation work.
- Policy evaluation applies a fixed-policy expectation update, while value iteration’s maximization makes its backup nonlinear.
- Large MDPs may require many updates to evaluate a policy exactly, so practical algorithms often stop evaluation after a fixed number of iterations.
- Policy iteration can then alternate approximate evaluation and improvement, while value iteration continues updating values without separate policy-evaluation phases.
- If both algorithms fully converge under the applicable assumptions, they produce optimal values and policies; stopping early makes approximation quality relevant.
- Generalized policy iteration alternates between estimating values and improving behavior, without requiring exact policy evaluation at every stage.
- With only one evaluation update before improvement, the procedure resembles value iteration; with evaluation continued to convergence, it becomes policy iteration.
- The evaluation-improvement balance controls a practical tradeoff between faster updates and more reliable policy estimates.
Transcript excerpt
0:00 Okay, so we talked about uh Bilman equation last time. Do you remember what that was? So just a quick recap, what are we doing right now? So we started with the idea of reinforcement learning. There is an agent environment. The agent wants to learn how to interact with the environment, right? So we pretty much took the whole first lecture to model everything. So essentially you have the the agent. This agent is interacting with this environment and then the agent was essentially just a policy, right? What was the policy mathematically? What is policy? >> It's a distribution. Exactly. A conditional distribution. The probability of every action that you do given the state that you are in. Now, how did we model the environment?
0:52 A mark of chain, right? So it was a mark of chain of states. So we said there is the one guy which calls states. So this state is like how the universe is labeled at every single time upon doing an action this changes to another state. Right? And this is a mark of chain. Every single time you just need to know what is the last state you can describe the next state of course probabilistically. Right now uh that was say that was environment. Then we said okay let's start with the ideal case and the ideal case was essentially modelbased reinforcement learning. What is ideal case? You do know exactly what that mark of chain is right. So you do know at every single state that you are if you do action what is the chance of transiting to any other state. Right?
1:41 And you also know what is the chance of any reward to get right? Make sense? You remember that? Now when we have this property then
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Ali Bereyhi.