COMP 3200 - Intro to Artificial Intelligence - Lecture 19 - Temporal Difference Learning + A5
Overview
Dave Churchill explains on-policy and off-policy reinforcement learning, then derives temporal-difference learning and compares the on-policy SARSA algorithm with off-policy Q-learning. He illustrates how exploration changes their behavior in the cliff example and walks through Assignment 5, where one tabular learning implementation supports grid-world pathfinding, blackjack, and several other environments.
Key takeaways
- On-policy learning updates the same policy that generates experience; off-policy learning separates the behavior policy from the target policy.
- TD(0) updates after each transition using reward plus gamma times the estimated value of the next state, combining experience-based learning with bootstrapping.
- SARSA uses the next action selected by its exploratory policy, so its learned values account for the risks of epsilon-greedy behavior.
- Q-learning uses the maximum next-state action value, so it targets a greedy policy even when its training episodes include random actions.
- In the cliff example, SARSA can earn better rewards during training by learning a safer route, while Q-learning can produce a better final greedy route once exploration stops.
- Assignment 5 uses integer-indexed state-action tables and supports both fixed-alpha updates and sample averaging across grid-world, blackjack, and other environments.
Chapters
- Dave Churchill introduces on-policy versus off-policy learning, temporal-difference learning, SARSA, and Q-learning.
- He postpones the Assignment 5 walkthrough until later in the recording.
- In Monte Carlo exploring starts, the same policy generates episodes and is improved using the resulting value estimates.
- That loop, generating data with a policy and then updating that policy, is the defining feature of on-policy learning.
- Off-policy learning uses a behavior policy to generate episodes and learns a separate target policy.
- Churchill illustrates the distinction with chess: a learner can update its policy by observing games played by someone else.
- A soft policy assigns nonzero probability to every action, allowing continued exploration.
- With epsilon-greedy selection, probability epsilon is reserved for random exploration and probability 1 minus epsilon for greedy selection.
- A simple implementation uses an if statement: explore when a random draw is below epsilon, otherwise choose a greedy action.
- A probability-table implementation assigns each nongreedy action epsilon divided by the number of actions, and adds the exploitation probability to greedy actions.
- For epsilon 0.2 and four actions, each nongreedy action receives 0.05 and the unique greedy action receives 0.85.
- First-visit Monte Carlo estimates action values from episode returns, then updates the policy toward actions with the highest Q values.
- Epsilon-soft action probabilities ensure state-action exploration, but the resulting policy remains stochastic.
- With epsilon 0.1 and five actions, each action receives 0.02 exploration probability; a unique greedy action receives 0.92.
- When multiple actions tie for the maximum, divide the exploitation mass, 1 minus epsilon, equally among them.
- The resulting action probabilities must sum to one.
- Exploration requires trying nonoptimal actions, while exploitation selects actions currently believed to be best.
- An epsilon-soft policy may retain unwanted randomness after training, such as recommending a random movie 10 percent of the time.
- Off-policy control separates the exploratory behavior policy from the target policy intended for deployment.
- Like Monte Carlo, temporal-difference methods learn from experience without requiring a model of the environment.
- Like dynamic programming, TD methods bootstrap from estimates of neighboring states instead of waiting for an episode's final outcome.
- Monte Carlo uses the full episode return as its update target; TD(0) uses the immediate reward plus gamma times the next state's estimated value.
- The update is incremental, so it can be applied after each transition rather than after an episode ends.
- For action-value estimation, replace the state value V with the corresponding Q value.
- A commute estimate changes as new information arrives, such as rain, highway progress, or a slow truck.
- Monte Carlo would wait until the trip ends and update estimates from the total 43-minute journey; TD updates each estimate using the observed time for that leg and the next estimate.
- Dynamic programming requires an environment model, whereas Monte Carlo and TD can learn directly from experience.
- TD updates online and incrementally, which is useful for long episodes and continuing tasks that cannot be divided into finite episodes.
- Churchill notes that TD often converges faster than fixed-step-size Monte Carlo methods.
- Control combines value estimation with policy improvement, retaining the exploration-versus-exploitation challenge.
- SARSA estimates action values for the current policy and updates that policy toward actions with high Q values.
- SARSA updates Q for the current state-action pair using the reward and the value of the next state-action pair.
- Its update sequence is state, action, reward, next state, next action, which gives the algorithm its name.
- If the next state is terminal, the next-state action value is treated as zero.
- SARSA selects actions using epsilon-greedy behavior at both the current and next states.
- Because it is on-policy, its Q estimates reflect the exploratory actions that the behavior policy may take.
- Q-learning updates from the maximum Q value available at the next state rather than the value of the action actually selected there.
- This targets a greedy policy even when exploratory behavior generates the training data, making Q-learning off-policy.
- In the cliff world, each ordinary move earns -1, while stepping off the cliff incurs a large penalty and returns the agent to the start.
- SARSA learns a safer route because its values account for epsilon-greedy mistakes near the cliff.
- Q-learning targets the shorter route beside the cliff, so exploration can make its training returns worse even though its final greedy policy performs better without exploration.
- The assignment's main environment is a grid world with up, down, left, and right actions and rewards of -1 for ordinary moves.
- Walls block movement; reaching a goal tile gives its configured reward, and terminal locations send the agent to a start state or a random state.
- The same reinforcement-learning code is intended to work across several environments.
- The interface supports editing walls, rewards, and agent position, and displays Q values and policy probabilities for selected states.
- A grid coordinate is converted to an integer state index; for a width-10 grid, coordinate (3, 9) maps to state 93.
- The default policy assigns probability 0.25 to each of the four actions.
- A single iteration samples an action, observes its reward and next state, updates Q, and improves the policy.
- With alpha 0.1, an initial Q value of 0 updated toward reward -1 becomes -0.1 when the next-state contribution is zero.
- The interface supports Q-learning or SARSA, fixed alpha or averaging, and configurable epsilon and gamma.
- Automatic iterations train the grid-world policy, and average reward per terminal state indicates the typical path cost.
- The demo scales to larger maps by increasing the number of iterations per frame.
- After adding walls, a fixed learning rate adapts faster than a running average, which remains influenced by millions of earlier updates.
- The cliff-world demo shows Q-learning finding the route along the cliff while SARSA learns a more cautious route; increasing epsilon strengthens the contrast.
- The same learner can train on blackjack, where a deployment run evaluates the learned policy over 10 million hands without exploration.
- Additional demos include a pole cart, soccer, mountain car, and lunar lander; the default grid world is the primary grading environment.
- Each environment provides functions for the number of states, number of actions, reset, action execution, and terminal-state checks.
- For the default 10 by 10 grid, state indices range from 0 to 99, and four action indices represent the available moves.
- The action function returns the next state, reward, and terminal flag; terminal locations in this assignment teleport the agent because the task continues.
- The learner reads configuration values for algorithm, alpha, update method, gamma, epsilon, and exploring starts.
- It initializes Q values to zero, action probabilities uniformly, and visit counts to zero.
- Visit counts support the averaging update, while fixed-alpha updates use the configured learning rate.
- The iteration checks whether the current state is terminal and resets to the configured start or a random state when needed.
- Action selection uses epsilon-greedy exploration or samples among actions with the highest policy probability.
- The environment's action function supplies the transition result used in the value update.
- SARSA's target uses the Q value for the next state and the next action selected by the policy.
- Q-learning's target uses the maximum Q value over actions at the next state.
- Terminal transitions use a zero next-state target, and the update rate is either configured alpha or 1 divided by the state-action visit count.
- Policy improvement finds the maximum Q value and assigns equal probability to every action tied for that maximum.
- Floating-point values that differ only slightly can be treated as ties using a small tolerance, such as 0.0001.
- The final assignment check focuses on solving the default grid world and producing the expected contrast between SARSA and Q-learning in the cliff environment.
Transcript excerpt
0:00 So, lecture number 19. Um, quickly before I talk about what we're going to be talking about on the schedule, it said that today we're going to be talking about temporal difference learning, which is one of the topics, but also assignment 5. Um, but I've added a few slides and I'm not sure exactly how long the lecture is going to take. So, I'm not actually going to be talking about assignment five in the lecture. I'm going to do the whole assignment thing later and then put it at the end of the video. So, assignment 5 is still today's lecture, but I'll get that video up later this evening. I'm sure everyone is dying to start assignment 5 on the day that it's released, but it'll be there when you get up tomorrow morning. And also, uh, since the assignment is due today, I I'll have the normal office hours probably see a couple of you
0:47 there. So, lecture number 19, we're going to be talking about on policy versus off policy learning. Uh, something called temp temporal difference learning. And then two of probably the most famous um early temporal difference learning algorithms which are SARSA and Q-learning. And um this is a great lecture for the exam because it's just algorithms and definitions and that's what we we like to see on the exam. And uh as always, please [clears throat] follow along in the textbook because it explains things better than I ever could. Um I would probably get up here and just read the textbook, but that wouldn't be a very exciting lecture. So follow along with that. It's a great book. It explains it really really well. So what is on policy versus off policy learning. So we talked last time about
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, Dave Churchill.