Lesson 3
RL 8-10
These are my original lecture notes, kept as they were. They're being rebuilt into the Reinforcement learning course.
Lecture 8: Generalization in Reinforcement Learning
1. The Need for Generalization
Why Generalization Matters
In standard RL, we treat each state independently. For problems with millions of states, this is impractical because:
- We can't visit every state infinitely many times
- Learning is slow—reward information propagates one step at a time
- Memory requirements become prohibitive
Key Insight: Generalization lets us leverage learning from states we've visited to make predictions about states we haven't visited (or visited rarely).
Analogy
Think of fitting a curve through data points: you have 5 observations (states you've visited), but the curve lets you predict values at any point on the line (states you haven't visited).
2. Features and State Representation
From States to Features
Instead of treating states as opaque identifiers (state 1, state 2, ...), we describe them using features—measurable properties that capture what's important.
Example: Taxi Domain
- State space: ~500 states
- Possible features:
- X-coordinate of taxi
- Y-coordinate of taxi
- Is taxi near a wall?
- Distance to passenger
- Distance to destination
Inductive Bias
Different feature representations create different inductive biases—they make some states appear more similar than others.
Example: If we use "distance to passenger" as a feature:
- A taxi 2 steps from a passenger looks the same regardless of absolute position
- Moving both taxi and passenger together preserves similarity
Critical Point: The choice of features determines what can be learned efficiently. Good features are:
- Computationally efficient to extract from states
- Value informative — correlated with actual state values
3. What Can We Approximate?
Three main functions in RL that could benefit from function approximation:
| Function | Mapping | Notes |
|---|---|---|
| Policy | Direct but hard to learn | |
| Value Function | or | Most studied approach |
| Model | , | Natural supervised learning setting |
Focus: Most research has focused on value function approximation.
4. Value Function Approximation Framework
General Form
Represent the Q-function using parameters :
Where:
- = feature vector for state
- = weight parameters for action
- = function combining features and weights
General Update Rule
Given experience tuple :
Interpretation:
- TD Error: How wrong was our prediction? (target - prediction)
- Gradient: How much does this weight influence the Q-value?
- We move weights to reduce prediction error
Bootstrapping Warning ⚠️
Unlike supervised learning where targets () are "ground truth," here we're using our own predictions to generate targets. This can cause instability.
5. Linear Value Function Approximation
The Linear Form
The Q-function is a weighted sum of features:
Where:
- = value of feature for state
- = weight for feature and action
- This is simply a dot product between feature and weight vectors
Gradient for Linear Case
For linear function approximation, the gradient is trivially:
Quiz Answer: The derivative of with respect to is just (the coefficient of ).
Complete Linear Update Rule
6. Successes and Failures
Notable Successes
| System | Domain | Approach |
|---|---|---|
| TD-Gammon (Tesauro) | Backgammon | 3-layer neural network |
| DQN (DeepMind) | Atari games | Deep convolutional networks |
| CMAC (Sutton) | Various control | Tile coding |
Why Backgammon Worked: The game's inherent randomness (dice) forces exploration and creates smooth value functions where similar states have similar values.
The Danger of Bootstrapping
Problem: We're using our own predictions as training targets. If predictions start drifting, they can spiral out of control.
Observed Pattern: Systems often learn well initially, then enter "death spirals" where errors compound.
7. Baird's Counterexample (Why Things Can Go Wrong)
The Setup
A deceptively simple MDP designed to break linear function approximation:
States: 7 states (1-6 plus state 7) Actions: One action per state Transitions: States 1-6 all go to state 7; state 7 loops to itself Rewards: Zero everywhere
Optimal Value Function: for all states (trivial!)
Feature Representation
| State | ||||||||
|---|---|---|---|---|---|---|---|---|
| 1 | 1 | 2 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2 | 1 | 0 | 2 | 0 | 0 | 0 | 0 | 0 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 7 | 7 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
Key Properties:
- Near-tabular (almost one feature per state)
- The optimal value function ( everywhere) is representable
- In fact, infinitely many weight settings give the correct answer
What Goes Wrong
With round-robin updates (, ):
- Updates from states 1-6 → 7 pump up weights (value of 7 is larger)
- Update from 7 → 7 brings weights down, but not enough
- Weights diverge to infinity!
The Lesson: Even with linear function approximation, convergence is NOT guaranteed. The combination of:
- Function approximation
- Bootstrapping
- Off-policy learning
...creates the "deadly triad" that can cause divergence.
8. Averagers: A Well-Behaved Alternative
Definition
An averager is a function approximator where the value at any state is a convex combination of values at anchor points (basis states).
Where:
- for all
- for all
Intuition
Like linear interpolation: values at intermediate points are weighted averages of nearby anchor points.
Example: K-Nearest Neighbors (KNN)
- Basis = all data points
- if is one of nearest neighbors, else 0
Why Averagers Work
Brilliant Insight (Gordon): An averager can be folded into the MDP itself!
Define a new transition function:
This is:
- Non-negative (since and )
- Sums to 1 over (since both and sum to 1)
- Therefore, it's a valid transition function!
Result: The value function under the averager IS the optimal value function of an equivalent MDP defined over just the basis states.
Properties
| Property | Implication |
|---|---|
| Unique fixed point | Bellman iteration converges |
| Contraction mapping | Convergence is guaranteed |
| More anchor points | Better approximation |
9. Summary: Generalization
| Concept | Key Point |
|---|---|
| Features | Describe states; choice determines what's learnable |
| Linear VFA | ; simple gradient |
| Bootstrapping | Using predictions as targets—can be unstable |
| Baird's Example | Shows divergence is possible even with linear |
| Averagers | Convex combinations; guaranteed convergence |
| Practical Methods | TD-Gammon, DQN work with careful engineering |
Lecture 9: Partially Observable MDPs (POMDPs)
1. The Core Problem: You Can't Always See the State
Intuition First
In standard MDPs, we assumed you always know exactly which state you're in. But real life isn't like that:
Example: You're a robot navigating a building. You see "a hallway with blue walls." But there are 3 different hallways with blue walls in this building. Which one are you actually in?
You can't know for certain. But you can maintain a belief—a probability distribution over where you might be.
What Changes from MDPs?
In an MDP, you observe the state directly. In a POMDP, there's an extra layer:
True State (hidden) → generates → Observation (what you see)Concrete Example - Tiger Problem:
- Two doors. Behind one is a tiger (bad), behind the other is treasure (good).
- You can't see which is which.
- You can "listen" and hear a growl from the left or right, but listening is noisy (85% accurate).
- What do you do?
Formal POMDP Definition
A POMDP adds one thing to an MDP: observations.
| Component | What it is | Example (Tiger) |
|---|---|---|
| Hidden states | {tiger-left, tiger-right} | |
| Actions | {listen, open-left, open-right} | |
| Observations | {growl-left, growl-right} | |
| Transitions | After opening, reset randomly | |
| Rewards | +10 treasure, -100 tiger, -1 listen | |
| P(observation | state) | P(growl-left | tiger-left) = 0.85 |
Key insight: The agent never sees directly. It only sees , which is a noisy hint about .
2. Belief States: Tracking Where You Might Be
The Core Idea
Since you don't know the true state, you track a probability distribution over all possible states.
Belief state is a vector: probability you're in state
Tiger Example:
- Initially: — 50% tiger-left, 50% tiger-right
- After hearing growl-left: — probably tiger-left
- After hearing growl-left twice: — almost certainly tiger-left
Belief Update Formula
After taking action and seeing observation :
In plain English:
- Start with your old belief
- For each possible new state , compute: (how likely to transition there) × (how likely to see from there)
- Normalize so probabilities sum to 1
This is just Bayes' rule: You're updating your belief about hidden states given new evidence.
Worked Example
Tiger problem, starting with , action = listen, observation = growl-left:
New belief (before normalizing):
After normalizing:
3. The Belief MDP: Converting POMDP to Something Solvable
The Key Insight
Here's the clever trick: A POMDP over hidden states can be converted to a regular MDP over belief states.
Why this works: Even though you don't know the true state, your belief state is something you do know perfectly. And beliefs update deterministically given (action, observation) pairs.
The Belief MDP:
- States = all possible belief distributions (continuous!)
- Actions = same as original
- Transitions = belief updates
- Rewards = (expected reward under belief)
The Problem: Continuous State Space
With 2 hidden states, your belief is a point in (1D continuous). With hidden states, your belief is a point in an -dimensional simplex.
This is infinite—how do we do value iteration over infinitely many states?
4. Value Iteration for POMDPs: The PWLC Representation
The Problem We Need to Solve
We want to compute = value of being in belief state .
But is continuous! We can't just make a table.
The Beautiful Result: V(b) Has Special Structure
Theorem: For any finite-horizon POMDP, the value function is:
- Piecewise Linear — made up of flat surfaces
- Convex — bowl-shaped (curving upward)
This means we can represent exactly using a finite set of vectors.
What Does PWLC Actually Mean?
Intuition with 2 states (so belief is just one number, = P(state 1)):
Imagine plotting for from 0 to 1. The theorem says this curve is made of straight line segments joined together, forming a shape like this:
V(b)
^
| /\
| / \ /
| / \ /
| / \/
+----------------> p (belief in state 1)
0 1Each line segment comes from a different "plan" (sequence of actions). The value function takes the best plan at each belief point.
Alpha-Vectors: How We Store V(b)
Each line segment is defined by an α-vector (alpha-vector).
Definition: An α-vector is a vector with one entry per hidden state. It represents the value of a particular policy if you knew the true state.
To get the value at belief : Take the dot product
This is the expected value of that plan, averaging over your uncertainty.
The value function is:
where is your set of α-vectors (different plans).
Visual: 2-State Example
With 2 states, each α-vector defines a line:
V(b)
^
| α₁ (plan: open left)
| \
| \ ← V(b) = max over these lines
| \/
| /\
| / \
| / α₂ (plan: open right)
+----------------> pDifferent plans are best for different beliefs. The value function is the upper envelope.
How Value Iteration Works
Base case (horizon 0): everywhere. One α-vector: .
Induction: To compute from :
- For each action and observation , we create new α-vectors
- These come from combining the old α-vectors with the immediate rewards and transitions
- Take the max at each belief point
The key operations:
- Taking max over actions → take union of α-vector sets
- Different observations → combine α-vectors from different "branches"
The Computational Blow-up
Problem: The number of α-vectors can grow exponentially at each step.
With 2 actions and 3 observations: , , ...
Doubly exponential in horizon!
Pruning: Making It Tractable
Many α-vectors become dominated—they're never the best at any belief point.
Dominated: α is dominated if there's always some other α' with for all .
We can safely throw these away. In practice, pruning makes small POMDPs solvable.
5. Approaches When the POMDP is Unknown (RL for POMDPs)
Now we tackle a harder problem: what if you don't know the transition probabilities, observation probabilities, or rewards? This is RL in partially observable environments.
Approach 1: Model-Based Learning with EM
Idea: Learn the POMDP model, then solve it.
EM Algorithm (same as for Hidden Markov Models):
- E-step: Given your current model guess, estimate the hidden states from your observed data
- M-step: Given those estimated states, update your model parameters
Repeat until convergence.
Problem: No guarantees—works well for some POMDPs, fails on others.
Approach 2: Memoryless Policies
Simplification: What if we just ignore history and pick actions based only on the current observation?
"When I see blue hallway, go left. When I see green hallway, go right."
The Problem: Same observation, different states, need different actions.
Example: You're in a hallway. Blue walls = states 1, 2, or 4. State 1 needs "go left", states 2,4 need "go right". But you just see "blue"—what do you do?
Surprising Result: A stochastic memoryless policy can be better than any deterministic one!
If you randomize (go left 30%, right 70%), you'll do the right thing more often on average than always choosing one direction.
Approach 3: Bayesian RL (Elegant but Expensive)
Key insight: "Not knowing which MDP you're in" is itself a form of partial observability!
Setup:
- You have a prior distribution over possible MDPs
- The "true MDP" is a hidden state
- Your observations (states, rewards) give you evidence about which MDP it is
Result: This is just a POMDP where the hidden state includes "which MDP is real."
Magic: Solving this POMDP gives you optimal exploration automatically—no need for separate exploration bonuses. Uncertainty is built into the belief state.
Catch: The belief space is now over MDPs, which is huge. Only practical for tiny problems.
6. Alternative View: Predictive State Representations (PSRs)
Philosophical Question
What is a "state" really? In POMDPs, we postulate hidden states that we can never observe. Is there another way?
PSR Idea
Define state in terms of predictions about the future, not hidden variables.
A test = sequence of actions and expected observations: (do , see , do , see , ...)
Predictive state = probabilities of all possible tests from current situation.
Why this is cool: Everything is grounded in observables. No metaphysical hidden states.
Theorem: PSRs and POMDPs are equivalent—any POMDP can be expressed as a PSR and vice versa.
7. Summary: POMDPs
| Concept | Plain English |
|---|---|
| POMDP | MDP where you can't see the true state, only noisy observations |
| Belief state | Your probability distribution over where you might be |
| Belief update | Bayes' rule—update probabilities given new evidence |
| PWLC | Value function is max of linear functions, one per "plan" |
| α-vector | Represents value of a plan as function of belief |
| Complexity | Grows doubly exponentially with horizon (hard!) |
| Memoryless | Ignore history; may need randomization |
| Bayesian RL | Treat unknown MDP as hidden state; auto-explores |
| PSRs | Alternative: define state by predictions, not hidden vars |
Lecture 10: Options and Temporal Abstraction
1. The Problem: Actions Are Too Small
Why RL Struggles with Scale
Consider teaching a robot to make coffee. With primitive actions like "move arm 1cm left," you're looking at:
- Hundreds of steps to complete the task
- Reward only at the very end
- Credit assignment nightmare: which of 500 actions mattered?
Key insight from Lecture 8: We used function approximation to handle large state spaces. Can we do something similar for actions?
The Solution: Macro-Actions
Instead of primitive actions (up/down/left/right), use high-level actions like:
- "Go to the door"
- "Navigate to room B"
- "Pick up the cup"
These are called "options"—temporally extended actions that run for multiple time steps.
2. Intuition: Why Options Help
Concrete Example: Room Navigation
Imagine a 4-room gridworld where you need to get from the top-left room to the bottom-right room:
With primitive actions (up/down/left/right):
- ~60 individual decisions
- Reward signal travels back 60 steps
- Planning: consider possible paths
With options ("go to hallway 1", "go to hallway 2", etc.):
- ~4 high-level decisions
- Reward signal only needs to travel 4 steps back
- Planning: consider possible paths
The savings are exponential: vs
What Makes a Good Option?
Options work best when they:
- Accomplish meaningful subgoals (reach a doorway, pick up an object)
- Are reusable across different tasks
- Have clear start and end conditions
3. Options: The Formal Definition
An option bundles three things together:
The Three Components
| Component | What it answers | Type |
|---|---|---|
| Initiation set | "Where can I start this option?" | Set of states |
| Policy | "What do I do while executing?" | State → Action mapping |
| Termination | "When do I stop?" | State → Probability of stopping |
Example: "Go to South Doorway" Option
Initiation set I: Any state in the northeast room
Policy π: Navigate toward the south door (e.g., learned via Q-learning)
Termination β: β(s) = 1 if s is the doorway, else β(s) = 0
(Always stop when you reach the door, never stop otherwise)Primitive Actions Are Just Simple Options
Every regular action can be written as an option:
- = everywhere is valid
- = "just do "
- for all (always stop after one step)
So options generalize actions—they don't replace them.
Stochastic Termination
The termination function gives the probability of stopping in state . This allows:
- : definitely stop here
- : never stop here
- : 10% chance of stopping here (useful for exploration or random duration)
4. The Time Problem: Why We Need SMDPs
The Issue with Regular Bellman Equations
Standard Bellman equation assumes each action takes exactly one time step:
That single assumes one time step of discounting.
But options take variable time:
- "Go to doorway" from nearby: 3 steps
- "Go to doorway" from far away: 15 steps
If we just used once, we'd be treating 15-step options the same as 3-step options for discounting. That's wrong!
Semi-Markov Decision Processes (SMDPs)
Key idea: Fold the variable time directly into the reward and transition functions.
SMDP Bellman Equation:
This looks like regular Bellman, but and are defined differently.
What Means: Time-Adjusted Reward
= expected discounted total reward while executing option from state
If the option takes steps and collects rewards :
The discounting happens inside , not outside.
What Means: Time-Adjusted Transition
= expected discounted probability of ending in
Why the ? If an option takes 10 steps to reach , the future value from should be discounted by . This handles that.
Concrete Example
Option: "Go to doorway" from state
- Takes 5 steps on average
- Collects rewards: 0, 0, -1 (hit wall), 0, +1 (reached door)
- Ends in doorway state
Then:
- (discounted by time taken)
Why "Semi-Markov"?
- Markov property still holds at the base level: given current state, future is independent of past
- But at the option level: transitions depend on how long the option took (non-Markovian in time)
The "semi" captures this: Markovian in state, non-Markovian in time.
The Payoff
Once you define and , everything else works normally:
- Value iteration works
- Q-learning works
- All convergence guarantees apply
You've just changed the "actions" from primitives to options.
5. Bonus: State Abstraction from Options
Different Options Need Different Information
Consider Pac-Man with three options:
- "Eat nearest dot": Needs to know where Pac-Man is and where dots are. Doesn't care about ghosts.
- "Avoid ghost": Needs to know where Pac-Man is and where ghosts are. Doesn't care about dots.
- "Eat ghost" (after power pellet): Needs Pac-Man and ghost positions.
| Option | Pac-Man pos? | Ghost pos? | Dot pos? |
|---|---|---|---|
| Eat dot | ✓ | ✗ | ✓ |
| Avoid ghost | ✓ | ✓ | ✗ |
| Eat ghost | ✓ | ✓ | ✗ |
Implication: Each option effectively operates on a smaller state space. This is "state abstraction"—ignoring irrelevant features.
6. Goal Abstraction and Modular RL
Alternative View: Competing Goals
Instead of thinking "first do option A, then option B," think of options as parallel goals competing for control:
- "Eat dots" module: always wants you to chase dots
- "Avoid ghost" module: always wants you to flee
- "Eat ghost" module: wants you to chase ghosts (when powered up)
At each moment, one module "wins" and picks the action.
Arbitration: How Do Modules Vote?
Method 1: Greatest Mass (Sum the Q-values) Pick action with highest total vote.
- Pro: Every module gets a say
- Con: Might pick an action that's no module's first choice (a "compromise" action)
Method 2: Top Q (Max of Q-values) The module that cares most gets to decide.
- Pro: At least one module is happy
- Con: Ignores modules with moderate but consistent preferences
Method 3: W-learning (Who loses most?)
For each module, compute how much it "loses" if we don't take its preferred action:
Give priority to modules with high —they have the most at stake.
7. Monte Carlo Tree Search (MCTS): Planning with Options
Why We Need Something Beyond Value Iteration
Value iteration requires iterating over all states. With large state spaces, this is impossible.
MCTS is different: it builds a search tree by sampling, focusing computation on promising paths.
The Four Phases of MCTS
Repeat many times:
1. SELECTION → Walk down tree using current best guesses
2. EXPANSION → Add a new node when you reach the frontier
3. SIMULATION → Random rollout to estimate value
4. BACKPROP → Update Q-values back up the treePhase-by-Phase
Selection: Starting from root (current state), repeatedly pick the action that looks best: Continue until you reach a state not yet in the tree.
Expansion: Add this new state to the tree. Try one action to see what happens.
Simulation (Rollout): From the new state, play randomly (or with a simple policy) for many steps. Add up discounted rewards to estimate the value.
Backpropagation: Update Q-values for every (state, action) pair you visited on the way down:
Why MCTS is Powerful
| Property | Benefit |
|---|---|
| Anytime: More iterations → better answer | Can stop whenever time runs out |
| Sample-based: Doesn't need full state space | Works with huge/continuous spaces |
| Simulator-only: Just need to simulate, not enumerate | Easier than building full model |
Options + MCTS = Huge Win
Using options as actions in MCTS:
- Each "action" in the tree is an option (multi-step)
- Effective depth of tree is much shallower
- Same computation explores much farther into the future
Example:
- Primitive actions, horizon 100: tree depth 100
- Options (avg 20 steps each), horizon 100: tree depth ~5
- Branching factor : vs — exponential speedup
8. Summary: Options and Temporal Abstraction
| Concept | Plain English |
|---|---|
| Options | Multi-step "macro-actions" defined by (where to start, what to do, when to stop) |
| Why options help | Reduce effective horizon exponentially; faster learning and planning |
| SMDPs | Bellman equations that account for variable-time options |
| Total discounted reward during option execution | |
| Time-discounted probability of ending in state | |
| State abstraction | Different options can ignore different features |
| Modular RL | Multiple goal-modules compete for control |
| MCTS | Sample-based planning that builds a search tree |
| Options + MCTS | Shallow tree explores deep into future |
Key Equations Summary
Generalization
POMDPs
Belief Update:
PWLC Value Function:
Where each is a vector with = value of that plan if in state .
SMDPs (Options)
Time-adjusted reward:
Time-adjusted transition:
Practice Questions
Generalization
- Why does linear function approximation sometimes diverge? What is the "deadly triad"?
- What makes averagers "safe" for convergence? (Hint: think about how they relate to equivalent MDPs)
- Design features for the taxi problem that would help with generalization.
POMDPs
- Tiger Problem: You have belief . You listen and hear growl-left (85% accurate). Compute the new belief.
- What is an α-vector, intuitively? Why is the POMDP value function the max of dot products with α-vectors?
- Why might a stochastic memoryless policy outperform a deterministic one in a POMDP?
- Explain how Bayesian RL automatically handles the exploration/exploitation tradeoff.
Options
- Define the three components of an option. Give an example option for "navigate to nearest power pellet" in Pac-Man.
- Why do we need SMDPs for options? What goes wrong if we use the regular Bellman equation?
- In the SMDP Bellman equation, explain intuitively what represents and why it includes .
- In Greatest Mass Q-learning, construct an example where the chosen action is no module's first choice.
- How does using options with MCTS provide exponential speedup compared to primitive actions?