Lesson 7
RL Intro Papers
These are my original lecture notes, kept as they were. They're being rebuilt into the Reinforcement learning course.
Part 1: Learning to Predict by the Methods of Temporal Differences
Paper: Learning to Predict by the Methods of Temporal Differences (Sutton, 1988)
1. Core Concept: TD vs. Supervised Learning
This paper introduces Temporal Difference (TD) learning as a distinct method for prediction problems, contrasted against conventional Supervised Learning (Widrow-Hoff/LMS).
- Single-step prediction: Information is revealed all at once (ideal for supervised learning).
- Multi-step prediction: Information is revealed over time (e.g., weather, chess, stock market). TD is specialized for this.
The core insight is that supervised learning updates weights based on the difference between the prediction and the actual outcome (), whereas TD updates based on the difference between the prediction and the next prediction ().
2. The Mathematical Derivation
We assume a sequence of observations and a final outcome . The prediction at time is , dependent on weights .
A. The Supervised (Widrow-Hoff) Update: Weights are updated only after the sequence ends and is known. where is the learning rate and is the gradient of the prediction with respect to weights.
B. The Temporal Difference Transformation: Sutton represents the total error as a sum of temporal differences: where .
C. The TD(1) Update: By substituting the sum of differences into the supervised update, Sutton derives the rule, which is algebraically equivalent to Widrow-Hoff but can be computed incrementally: Here, the term acts as an eligibility trace, accumulating past gradients.
3. The TD() Family
Sutton generalizes the update by introducing a decay factor (). This weights recent predictions more heavily than distant ones.
.
- Eligibility Trace (): The summation term can be computed recursively: .
- TD(1): Equivalent to supervised learning (Widrow-Hoff). Updates based on the final outcome.
- TD(0): The "extreme" TD method. Updates based solely on the immediate next prediction: .
4. Convergence and Optimality
- Speed: In the Random Walk experiments, with consistently converged faster than Supervised Learning ().
- Optimality Limit:
- Supervised (Widrow-Hoff): Minimizes the RMS error on the training set.
- TD(0): Converges to the Maximum Likelihood Estimate (MLE) of the underlying Markov process. It finds the parameters that are most likely to have generated the observed data, assuming the data comes from a Markov chain.
Part 2: Policy Invariance Under Reward Transformations
Paper: Policy Invariance Under Reward Transformations: Theory and Application to Reward Shaping (Ng et al., 1999)
1. The Problem: Reward Bugs
Reward shaping involves adding extra rewards () to the base environment rewards () to speed up learning: . If designed poorly, creates "bugs."
- Example: A bicycle agent rewarded for moving toward a goal learned to ride in tiny circles to repeatedly collect "moving towards" reward.
2. The Solution: Potential-Based Reward Shaping (PBRS)
To prevent the optimal policy from changing when adding shaping rewards, must be potential-based.
The Definition: Let be a potential function over states. The shaping reward for a transition from to is: where is the discount factor.
3. Theorem of Policy Invariance
Ng et al. prove that being potential-based is both Necessary and Sufficient for policy invariance.
A. Sufficiency (Proof Sketch via Bellman Equation): The optimal Q-function in the original MDP is . In the transformed MDP (), the Q-function becomes: . Because the Q-values are simply shifted by (which does not depend on action ), the optimal policy (choosing the max ) remains unchanged: .
B. Necessity: If is not potential-based, there exists some transition function and reward structure where the optimal policy in is different from .
4. Optimal Shaping
The ideal potential function is the true optimal value function of the original MDP: If , the value function in the transformed MDP becomes zero everywhere (), turning the difficult learning problem into an easier one of strictly maintaining the immediate rewards.
Part 3: Reward (Mis)Design for Autonomous Driving
Paper: Reward (Mis)Design for Autonomous Driving (Knox et al.)
1. Motivation
This paper critiques the "trial-and-error" approach to reward design in Autonomous Driving (AD). It argues that most RL-for-AD papers use flawed reward functions that optimize for wrong behaviors, often hidden by the algorithms failing to fully converge.
2. The 8 Sanity Checks
The authors propose 8 tests to validate a reward function. The most critical, math-based checks are:
I. Unsafe Reward Shaping
- Issue: Using "hints" (e.g., stay in lane center) as part of the primary reward rather than strictly defining the goal (arrive safely).
- Check: Is the shaping separate from the true objective? Does it violate the potential-based rule (from Ng et al.)?
- Failure: 13 of 19 papers reviewed failed this, encouraging behaviors like "never change lanes" regardless of safety.
II. Comparing Preference Orderings
- The Logic: If human consensus says Trajectory A is better than Trajectory B (), the Return must satisfy .
- The Test: Compare (driving well then crashing) vs. (sitting still/not driving).
- Formula: Ideally, .
- Failure: 7 of 9 evaluated papers preferred crashing to sitting still (i.e., they penalized the crash less than the accumulated reward of moving forward before the crash).
III. Comparing Indifference Points (Risk Tolerance)
- The Logic: At what probability of crashing is the agent indifferent between "driving and risking a crash" vs. "not driving"?
- Formula: Solving for gives the acceptable risk threshold.
- Failure: Most papers were implicitly willing to accept crash rates orders of magnitude higher than a drunk teenage driver.
IV. Learnable Loopholes
- Issue: Reward hacking (e.g., moving in circles).
- Example: An agent learned to drift sideways on a racetrack because it minimized penalties while keeping speed.
3. Trial-and-Error Design
The authors note that researchers often tweak rewards until the specific RL algorithm behaves well. This is "overfitting" the reward to the algorithm's deficiencies, rather than specifying the actual task.
Part 4: Reinforcement Learning Improves Behaviour from Evaluative Feedback
Paper: Reinforcement learning improves behaviour from evaluative feedback (Littman, 2015)
1. Taxonomy of Feedback
Littman categorizes learning problems based on three axes of feedback:
- One-shot vs. Sequential: Do decisions affect future state? (Bandits vs. MDPs).
- Sampled vs. Exhaustive: Do we see all data or just what we uncover? (RL is sampled).
- Evaluative vs. Supervised: Do we get a "grade" (reward) or the "correct answer"?
2. Key Algorithms & Math
A. Bandits (One-shot, Evaluative): Used for web optimization (ads, headlines).
- UCB (Upper Confidence Bound): Select actions based on estimated value + uncertainty. This balances exploration (high uncertainty) and exploitation (high value).
- Thompson Sampling: Probability matching using posterior distributions.
B. Tabular RL (Sequential, Evaluative):
- Q-Learning Update: This aligns with the Bellman equation to maximize cumulative discounted reward.
C. Planning (Sequential, Exhaustive/Model-based):
- MCTS (Monte Carlo Tree Search): Uses UCT (Upper Confidence Intervals in Trees) to selectively search deep into promising game paths (used in Go).
D. Actor-Critic / Deep RL:
- Mentions the usage of Deep Learning (DQN) to handle high-dimensional state spaces (Atari), moving beyond tabular methods.
Synthesis and Analysis: How the Papers Relate
1. The Mechanic vs. The Specification
- Sutton (1988) provides the mechanic. It explains how to learn predictions ( or ) efficiently using the difference between temporal states (). It proves that bootstrapping (learning from guesses) is valid and often more efficient than waiting for final outcomes.
- Knox et al. and Ng et al. focus on the specification (). Sutton assumes the reward/outcome is given. Ng and Knox argue that defining (or ) is the hardest part of the problem.
2. The Evolution of Reward Shaping
- Problem: Sutton’s TD learning can be slow in sparse reward environments (random walk example).
- Solution (Ng et al.): We can inject knowledge via Reward Shaping (). However, Ng proves mathematically that unless , we risk changing the optimal policy.
- Practical Failure (Knox et al.): Knox applies Ng’s theory to modern Autonomous Driving papers and finds that practitioners ignore Ng’s condition. They use heuristic shaping (e.g., "stay in lane") that is not potential-based, leading to "Unsafe Reward Shaping" (Knox Sanity Check #1).
3. Convergence and Objectives
- Sutton: Shows TD(0) converges to the Maximum Likelihood Estimate of the process.
- Knox: Warns that if the reward function is flawed (e.g., preferring crashing to idling), the algorithm will "converge" to catastrophic behavior. The math works, but the objective is wrong.
- Littman: Provides the broader context, showing how these components (TD learning, Exploration via UCB) combine into modern systems (DQN, AlphaGo).
4. Summary of Mathematical Progression
- Sutton: .
- Ng: If we modify the reward , we must ensure to keep consistent.
- Knox: If we define risk preferences, we must solve for in to ensure the agent isn't suicidal.
- Littman: To handle exploration in these systems, we add confidence bounds: .