RL lecture notes (archive)1 / 7

Lesson 1

RL 0-4

These are my original lecture notes, kept as they were. They're being rebuilt into the Reinforcement learning course.

1. Introduction & Overview

What is Reinforcement Learning?

Reinforcement Learning (RL) is a type of machine learning where an agent learns to make decisions by interacting with an environment. Unlike supervised learning where you're given explicit input-output pairs, in RL you learn from rewards/punishments received after taking actions.

The Three Types of Machine Learning:

TypeInputOutputGoal
Supervised(x, y) pairsFunction fMap x → y
Unsupervisedx values onlyFunction fDescribe/cluster x's
Reinforcement(x, z) pairsFunction f → yLearn optimal actions from rewards

In RL, you receive states (x) and rewards (z), but you must discover the optimal actions (y) yourself.

The Core Problem

The key challenge in RL is the temporal credit assignment problem: you take a sequence of actions, and only later receive feedback about how well you did. Which action was responsible for your success or failure?

Example - Chess: You play 60 moves and then lose. Did you lose because of:

  • A bad move early in the game?
  • A mistake near the end?
  • Consistently mediocre play?

RL algorithms must figure out how to assign "credit" (or "blame") to individual actions in the sequence.


2. Markov Decision Processes (MDPs)

An MDP is the mathematical framework we use to model decision-making problems.

Components of an MDP

An MDP is defined by the tuple: (S, A, T, R, γ)

ComponentSymbolDescription
StatesSSet of all possible states the agent can be in
ActionsASet of all possible actions the agent can take
Transition FunctionT(s, a, s')Probability of reaching state s' when taking action a in state s
Reward FunctionR(s)Immediate reward for being in state s
Discount FactorγHow much to value future rewards (0 ≤ γ < 1)

The Markov Property

"Only the present matters."

The probability of transitioning to the next state depends only on the current state, not on any previous history:

P(st+1∣st,at)=P(st+1∣st,at,st−1,at−1,…)P(s_{t+1} | s_t, a_t) = P(s_{t+1} | s_t, a_t, s_{t-1}, a_{t-1}, \ldots)

Intuition: If you're in state s, it doesn't matter how you got there—only that you're there now.

Practical Note: If history does matter, you can fold the relevant history into your state representation (though this increases state space size).

Stationarity

The transition and reward functions don't change over time. The "physics" of the world remain constant.

Example: Grid World

Consider a 3×4 grid where:

  • Agent starts at (1,1)
  • Goal state at (4,3) gives +1 reward
  • Trap state at (4,2) gives -1 reward
  • Actions: Up, Down, Left, Right
  • Each action succeeds with 80% probability; 10% chance of slipping perpendicular in each direction

With deterministic actions: The shortest path from start to goal is 5 steps (e.g., up, up, right, right, right).

With stochastic actions: The probability of this exact sequence succeeding is: 0.85=0.327680.8^5 = 0.32768

This illustrates why we need policies rather than fixed plans.

Policy vs Plan

ConceptDefinitionWhen to Use
PlanFixed sequence of actionsDeterministic environments
PolicyMapping from states → actionsStochastic environments

Policy (π): A function π: S → A that tells you which action to take in each state.

π(s)=a\pi(s) = a

Optimal Policy (π∗π^*): The policy that maximizes expected long-term reward.


3. Value Functions & The Bellman Equation

Utility vs Reward

ConceptDefinitionTime Horizon
Reward R(s)Immediate feedback for being in state sSingle timestep
Utility U(s)Expected total future reward from state sLong-term

Key insight: A state with low immediate reward might have high utility if it leads to better states.

Example: College costs money (negative immediate reward) but leads to higher earnings (positive utility).

Why We Need Discounting

If we simply sum all future rewards: U(s0,s1,s2,…)=∑t=0∞R(st)U(s_0, s_1, s_2, \ldots) = \sum_{t=0}^{\infty} R(s_t)

This sum can be infinite for infinite time horizons!

The Discounted Reward Solution:

U(s0,s1,s2,…)=∑t=0∞γtR(st)U(s_0, s_1, s_2, \ldots) = \sum_{t=0}^{\infty} \gamma^t R(s_t)

where 0 ≤ γ < 1.

Properties of discounting:

  • γ close to 0: Only care about immediate reward
  • γ close to 1: Care about long-term reward
  • Ensures the sum converges even for infinite sequences

The Geometric Series Bound:

∑t=0∞γtRmax=Rmax1−γ\sum_{t=0}^{\infty} \gamma^t R_{max} = \frac{R_{max}}{1-\gamma}

This gives us a finite upper bound on utility even with infinite time horizons.

The Value Function V(s)

The value function V(s) represents the expected utility of being in state s and following policy π:

Vπ(s)=E[∑t=0∞γtR(st)∣s0=s,π]V^\pi(s) = E\left[\sum_{t=0}^{\infty} \gamma^t R(s_t) \mid s_0 = s, \pi\right]

The Q-Function Q(s, a)

The Q-function represents the expected utility of taking action a in state s, then following policy π:

Qπ(s,a)=E[∑t=0∞γtR(st)∣s0=s,a0=a,π]Q^\pi(s, a) = E\left[\sum_{t=0}^{\infty} \gamma^t R(s_t) \mid s_0 = s, a_0 = a, \pi\right]

Relationship between V and Q:

V∗(s)=max⁡aQ∗(s,a)V^*(s) = \max_a Q^*(s, a)

π∗(s)=arg⁡max⁡aQ∗(s,a)\pi^*(s) = \arg\max_a Q^*(s, a)

The Bellman Equation ⭐

The most important equation in RL!

The Bellman equation expresses the recursive relationship between the value of a state and the values of its successor states.

For the Value Function:

V∗(s)=R(s)+γmax⁡a∑s′T(s,a,s′)V∗(s′)V^*(s) = R(s) + \gamma \max_a \sum_{s'} T(s, a, s') V^*(s')

For the Q-Function:

Q∗(s,a)=R(s)+γ∑s′T(s,a,s′)max⁡a′Q∗(s′,a′)Q^*(s, a) = R(s) + \gamma \sum_{s'} T(s, a, s') \max_{a'} Q^*(s', a')

Intuition: The value of a state equals:

  1. The immediate reward, plus
  2. The discounted value of where you'll end up (in expectation)

The Continuation Function C(s, a)

An alternative representation that separates immediate reward from future value:

C(s,a)=γ∑s′T(s,a,s′)V(s′)C(s, a) = \gamma \sum_{s'} T(s, a, s') V(s')

Relationships:

  • Q(s,a)=R(s)+C(s,a)Q(s, a) = R(s) + C(s, a)
  • V(s)=maxaQ(s,a)=R(s)+maxaC(s,a)V(s) = \text{max}_a Q(s, a) = R(s) + \text{max}_a C(s, a)
  • C(s,a)=γΣs′T(s,a,s′)V(s′)C(s, a) = γ Σ_{s'} T(s,a,s') V(s')

Why C matters: Q-functions encapsulate everything needed to act optimally without knowing R or T. If you have Q, you can derive V easily.


4. Solving MDPs: Value Iteration & Policy Iteration

Given a known MDP (known T and R), how do we find the optimal policy?

Value Iteration

Algorithm:

  1. Initialize V(s) = 0 (or arbitrary values) for all states
  2. Repeat until convergence: Vt+1(s)=R(s)+γmax⁡a∑s′T(s,a,s′)Vt(s′)V_{t+1}(s) = R(s) + \gamma \max_a \sum_{s'} T(s, a, s') V_t(s')
  3. Extract policy: π∗(s)=arg max⁡aΣs′T(s,a,s′)V(s′)π^*(s) = \argmax_a Σ_{s'} T(s,a,s') V(s')

Why it works:

  • n equations (one per state) in n unknowns (the V values)
  • The max makes it nonlinear, so we can't solve directly
  • But iterative updates converge because the Bellman operator is a contraction mapping

The Bellman Operator

Define the Bellman operator B as:

[BQ](s,a)=R(s)+γ∑s′T(s,a,s′)max⁡a′Q(s′,a′)[BQ](s, a) = R(s) + \gamma \sum_{s'} T(s, a, s') \max_{a'} Q(s', a')

Key properties:

  • Q∗=BQ∗Q^* = BQ^* (the optimal Q-function is a fixed point)
  • Value iteration: Qt+1=BQtQ_{t+1} = B Q_t

5. Reinforcement Learning Basics

The Agent-Environment Loop

    ┌─────────────────────────────────────┐
    │                                     │
    ▼                                     │
┌─────────┐     action a     ┌───────────────┐
│  Agent  │ ───────────────► │  Environment  │
│         │ ◄─────────────── │               │
└─────────┘ state,reward s,r └───────────────┘

Sequence: The agent experiences: (s0,a0,r1,s1,a1,r2,s2,…)(s_0, a_0, r_1, s_1, a_1, r_2, s_2, \ldots)

Often written as SARS: (State, Action, Reward, State')

RL vs MDP Solving

AspectMDP SolvingReinforcement Learning
Model T, RKnownUnknown
DataNot neededLearn from experience
ComputationMostly offlineOnline updates

The core RL challenge: Learn a good policy without knowing T or R—only by observing rewards from experience!

Evaluating Policies and Learners

Policy Evaluation: How good is this policy?

  • Expected discounted reward when following it

Learner Evaluation:

  1. Quality: Does it find a good (optimal?) policy?
  2. Computational Complexity: How much compute time?
  3. Sample Complexity: How many experiences/interactions needed?

6. Three Families of RL Algorithms

Overview Diagram

                        EXPERIENCE (SARS tuples)
                                   │
           ┌───────────────────────┼───────────────────────┐
           │                       │                       │
           ▼                       ▼                       ▼
   ┌───────────────┐      ┌───────────────┐      ┌───────────────┐
   │  MODEL-BASED  │      │  VALUE-BASED  │      │ POLICY-BASED  │
   └───────┬───────┘      └───────┬───────┘      └───────┬───────┘
           │                      │                      │
           ▼                      │                      │
   ┌───────────────┐              │                      │
   │  Learn T, R   │              │                      │
   │  (dynamics &  │              │                      │
   │   rewards)    │              │                      │
   └───────┬───────┘              │                      │
           │                      │                      │
           ▼                      │                      │
   ┌───────────────┐              │                      │
   │  Plan/Solve   │              │                      │
   │  (Value Iter) │              │                      │
   └───────┬───────┘              │                      │
           │                      │                      │
           ▼                      ▼                      │
   ┌───────────────┐      ┌───────────────┐              │
   │      Q*       │      │   Learn Q*    │              │
   │               │      │   directly    │              │
   │               │      │ (Q-learning)  │              │
   └───────┬───────┘      └───────┬───────┘              │
           │                      │                      │
           ▼                      ▼                      ▼
   ┌───────────────┐      ┌───────────────┐      ┌───────────────┐
   │  π* = argmax  │      │  π* = argmax  │      │   Learn π*    │
   │               │      │               │      │   directly    │
   └───────┬───────┘      └───────┬───────┘      └───────┬───────┘
           │                      │                      │
           └──────────────────────┴──────────────────────┘
                                  │
                                  ▼
                               POLICY π*

1. Model-Based RL

Approach: Learn T and R from experience, then solve the MDP.

Flow: SARS* → Learn T, R → MDP Solver → Q* → Policy

Pros: Learning T, R is basically supervised learning (easy) Cons: Requires building and storing a model; two-phase process

2. Value-Based (Model-Free) RL

Approach: Learn Q* directly from experience without learning T or R.

Flow: SARS* → Value Update → Q* → Policy

Pros: No model needed; simpler; direct Cons: Harder learning problem (what target to use?)

Examples: TD Learning, Q-Learning, SARSA

3. Policy-Based RL

Approach: Learn π directly, bypassing value functions entirely.

Flow: SARS* → Policy Update → Policy

Pros: Most direct; works with continuous actions Cons: Hardest learning signal; high variance

Examples: REINFORCE, Policy Gradient methods


7. Temporal Difference Learning

The Core Idea

TD learning learns value functions from experience by using bootstrapping: updating estimates based on other estimates.

Learning from Returns (Outcome-Based)

Given episodes of experience, estimate V(s) by averaging observed returns:

V(s)≈1n∑i=1nGi(s)V(s) \approx \frac{1}{n} \sum_{i=1}^{n} G_i(s)

where Gi(s)G_i(s) is the total discounted return observed starting from state s in episode i.

Incremental Update Rule

Rather than storing all returns, update incrementally:

Vt(s)=Vt−1(s)+αt[Gt(s)−Vt−1(s)]V_{t}(s) = V_{t-1}(s) + \alpha_t \left[ G_t(s) - V_{t-1}(s) \right]

This has the form of a perceptron/gradient descent update:

  • Error: Gt(s)−Vt−1(s)G_t(s) - V_{t-1}(s) (what we observed vs what we predicted)
  • Learning rate: αtα_t controls how much to adjust

Learning Rate Requirements ⭐

For the incremental update to converge to the true value:

∑t=1∞αt=∞AND∑t=1∞αt2<∞\sum_{t=1}^{\infty} \alpha_t = \infty \quad \text{AND} \quad \sum_{t=1}^{\infty} \alpha_t^2 < \infty

Intuition:

  • First condition: Learning rates must be "big enough" collectively to move from any starting point to the true value
  • Second condition: Learning rates must decay fast enough to "settle down" and not bounce around forever

Which learning rates work?

Learning Rate αtα_tΣαtα_tΣαt2α_t²Converges?
1/t∞< ∞✅ Yes
1/t²< ∞< ∞❌ No (too small)
1/t^(2/3)∞< ∞✅ Yes
1/√t∞∞❌ No (too big)
constant c∞∞❌ No (never settles)

TD(1): Episode-Based Updates

Wait until the end of each episode, then update all visited states using the full return.

Problem: High variance (one noisy episode affects the estimate a lot)

TD(0): One-Step Bootstrapping

Don't wait for the episode to end! Update after each step using the current estimate of the next state's value:

V(st)←V(st)+α[rt+1+γV(st+1)−V(st)]V(s_t) \leftarrow V(s_t) + \alpha \left[ r_{t+1} + \gamma V(s_{t+1}) - V(s_t) \right]

The TD Error (δ): δt=rt+1+γV(st+1)−V(st)\delta_t = r_{t+1} + \gamma V(s_{t+1}) - V(s_t)

This is the "temporal difference"—the difference between:

  • What we now think: rt+1+γV(st+1)r_{t+1} + γV(s_{t+1})
  • What we thought before: V(st)V(s_t)

Why TD(0) works:

  • Uses actual reward rt+1r_{t+1} (ground truth)
  • Uses estimate V(st+1)V(s_{t+1}) for the rest (bootstrapping)
  • Over time, V(st+1)V(s_{t+1}) improves, making our targets better

TD(0) gives the Maximum Likelihood estimate!

TD(λ): Interpolating Between TD(0) and TD(1)

TD(λ) provides a spectrum between TD(0) and TD(1):

  • λ = 0: TD(0) (one-step lookahead)
  • λ = 1: TD(1) (full episode return)
  • 0 < λ < 1: Weighted combination of k-step returns

First: What are k-step returns?

For a trajectory starting at s0s_0, the k-step return uses k actual rewards then bootstraps:

G0(1)=r1+γV(s1)G_0^{(1)} = r_1 + \gamma V(s_1) G0(2)=r1+γr2+γ2V(s2)G_0^{(2)} = r_1 + \gamma r_2 + \gamma^2 V(s_2) G0(3)=r1+γr2+γ2r3+γ3V(s3)G_0^{(3)} = r_1 + \gamma r_2 + \gamma^2 r_3 + \gamma^3 V(s_3) ⋮\vdots G0(∞)=r1+γr2+γ2r3+…(full Monte Carlo return)G_0^{(\infty)} = r_1 + \gamma r_2 + \gamma^2 r_3 + \ldots \quad \text{(full Monte Carlo return)}

Tradeoff: Small k = more bias (trust estimates), large k = more variance (trust actuals)

The λ-return: a weighted average

TD(λ) computes a weighted average of ALL these k-step returns:

Gλ=(1−λ)⋅G(1)+(1−λ)λ⋅G(2)+(1−λ)λ2⋅G(3)+…G^\lambda = (1-\lambda) \cdot G^{(1)} + (1-\lambda)\lambda \cdot G^{(2)} + (1-\lambda)\lambda^2 \cdot G^{(3)} + \ldots

The weights are:

ReturnWeight
G(1)G^{(1)}(1−λ)(1-\lambda)
G(2)G^{(2)}(1−λ)λ(1-\lambda)\lambda
G(3)G^{(3)}(1−λ)λ2(1-\lambda)\lambda^2
G(k)G^{(k)}(1−λ)λk−1(1-\lambda)\lambda^{k-1}

Why do the weights sum to 1?

(1−λ)+(1−λ)λ+(1−λ)λ2+…=(1−λ)∑k=0∞λk=(1−λ)⋅11−λ=1✓(1-\lambda) + (1-\lambda)\lambda + (1-\lambda)\lambda^2 + \ldots = (1-\lambda) \sum_{k=0}^{\infty} \lambda^k = (1-\lambda) \cdot \frac{1}{1-\lambda} = 1 \checkmark

Visual: Weight distribution

λ = 0 (TD(0))                         λ = 1 (Monte Carlo)
                                      
Weight                                Weight
  │                                     │
1 │ █                                   │                            █
  │ █                                   │                            █
  │ █                                   │                            █
  │ █                                   │                            █
  └─█─────────────► k                   └────────────────────────────█► k
    1  2  3  4  ∞                         1  2  3  4  ...            ∞
    
All weight on 1-step                  All weight on full return
λ = 0.5 (balanced)
                                      
Weight                                
  │                                   
  │ █                                 
  │ █ █                              
  │ █ █ █                            
  │ █ █ █ █ █ █ █ ...                
  └─█─█─█─█─█─█─█─────► k            
    1 2 3 4 5 6 7  ∞                  
    
Exponentially decaying weights

Concrete example

Say λ=0.5\lambda = 0.5 and we have:

  • G(1)=10G^{(1)} = 10
  • G(2)=8G^{(2)} = 8
  • G(3)=12G^{(3)} = 12
  • G(∞)=9G^{(\infty)} = 9

Weights:

  • G(1)G^{(1)}: (1−0.5)=0.5(1-0.5) = 0.5
  • G(2)G^{(2)}: (0.5)(0.5)=0.25(0.5)(0.5) = 0.25
  • G(3)G^{(3)}: (0.5)(0.25)=0.125(0.5)(0.25) = 0.125
  • ... and so on

Gλ≈0.5(10)+0.25(8)+0.125(12)+…=5+2+1.5+…G^\lambda \approx 0.5(10) + 0.25(8) + 0.125(12) + \ldots = 5 + 2 + 1.5 + \ldots

The two extremes

λ = 0:

  • Weight on G(1)G^{(1)} is (1−0)=1(1-0) = 1
  • Weight on everything else is 00
  • Gλ=G(1)=r+γV(s′)G^\lambda = G^{(1)} = r + \gamma V(s') → TD(0)

λ = 1:

  • Weights become (1−1)λk−1=0(1-1)\lambda^{k-1} = 0 for all finite k
  • All weight shifts to G(∞)G^{(\infty)} → Monte Carlo

Why this helps

Instead of choosing a single k (which is arbitrary), TD(λ) hedges by using all of them. The λ parameter controls how much you trust:

  • Short-term estimates (low λ): Lower variance, but biased if V is wrong
  • Long-term actuals (high λ): Unbiased, but high variance

Empirically, λ ∈ [0.3, 0.7] often works better than either extreme.

Eligibility Traces

TD(λ) is implemented efficiently using eligibility traces: Weight past states by λᵏ based on distance; which is the same as applying a forward looking λᵏ discount for the current-state

For each episode:
    Initialize e(s) = 0 for all states
    For each step (s_t → s_{t+1} with reward r_{t+1}):
        e(s_t) ← e(s_t) + 1              # Mark visited state eligible
        δ ← r_{t+1} + γV(s_{t+1}) - V(s_t)  # Compute TD error
        For all states s visited in episode:
            V(s) ← V(s) + α · δ · e(s)   # Update proportional to eligibility
            e(s) ← γλ · e(s)             # Decay eligibility

Intuition: Eligibility traces remember which states were recently visited. When we get a TD error, we assign credit to all recently-visited states, with more recent states getting more credit. The forward view says: "Each future reward contributes to this state's value". The backward view says: "Each reward distributes credit to past states".

Empirical Results

In practice, λ between 0.3 and 0.7 often works best:

  • Combines the low variance of TD(0)
  • With the lower bias of TD(1)

8. Q-Learning and Control

From Prediction to Control

TD learning (as described above) learns to predict values under a fixed policy. For control, we need to learn the optimal policy by learning Q*.

The Q-Learning Update ⭐

Q(st,at)←Q(st,at)+α[rt+1+γmax⁡a′Q(st+1,a′)−Q(st,at)]Q(s_t, a_t) \leftarrow Q(s_t, a_t) + \alpha \left[ r_{t+1} + \gamma \max_{a'} Q(s_{t+1}, a') - Q(s_t, a_t) \right]

Key difference from TD: The max over next actions!

The Q-Learning Algorithm:

Initialize Q(s, a) arbitrarily for all s, a
For each episode:
    Start in state s
    For each step:
        Choose action a (e.g., ε-greedy based on Q)
        Take action a, observe reward r and next state s'
        Q(s, a) ← Q(s, a) + α[r + γ max_a' Q(s', a') - Q(s, a)]
        s ← s'
    Until s is terminal

Off-Policy Learning

Q-learning is off-policy: it learns about the optimal policy π* while following a different behavior policy (e.g., ε-greedy for exploration).

This works because the update uses max⁡a′Q(s′,a′)\max_{a'} Q(s', a'), which corresponds to what the optimal policy would do, regardless of what action we actually took!

Exploration vs Exploitation

The dilemma: Should we:

  • Exploit: Choose the action we currently think is best?
  • Explore: Try other actions to potentially discover something better?

ε-greedy strategy:

  • With probability 1-ε: Choose arg max⁡aQ(s,a)\argmax_a Q(s, a)
  • With probability ε: Choose a random action

Common practice: Start with high ε (explore a lot), decay over time (exploit more as Q improves).


9. Convergence Theory

Why Do These Algorithms Converge?

The Bellman equation can be written using the Bellman operator B:

[BQ](s,a)=R(s,a)+γ∑s′T(s,a,s′)max⁡a′Q(s′,a′)[BQ](s, a) = R(s, a) + \gamma \sum_{s'} T(s, a, s') \max_{a'} Q(s', a')

Fixed point: Q∗=BQ∗Q^* = BQ^* (the optimal Q-function satisfies the Bellman equation)

Value Iteration: Qt+1=BQtQ_{t+1} = B Q_t

Contraction Mappings

Definition: An operator B is a contraction mapping with factor γ < 1 if:

∥BF−BG∥∞≤γ∥F−G∥∞\|BF - BG\|_\infty \leq \gamma \|F - G\|_\infty

for all functions F, G.

The infinity norm: ∣∣F∣∣∞=max⁡s,a∣F(s,a)∣||F||_∞ = \max_{s,a} |F(s,a)|

Intuition: Applying B brings any two functions closer together.

The Bellman Operator is a Contraction! ⭐

Proof sketch:

∣[BQ1](s,a)−[BQ2](s,a)∣=γ∣∑s′T(s,a,s′)[max⁡a′Q1(s′,a′)−max⁡a′Q2(s′,a′)]∣≤γ∑s′T(s,a,s′)∣max⁡a′Q1(s′,a′)−max⁡a′Q2(s′,a′)∣≤γ∑s′T(s,a,s′)max⁡s′,a′∣Q1(s′,a′)−Q2(s′,a′)∣=γ∥Q1−Q2∥∞\begin{aligned} |[BQ_1](s,a) - [BQ_2](s,a)| &= \gamma \left| \sum_{s'} T(s,a,s') [\max_{a'} Q_1(s',a') - \max_{a'} Q_2(s',a')] \right| \\ &\leq \gamma \sum_{s'} T(s,a,s') \left| \max_{a'} Q_1(s',a') - \max_{a'} Q_2(s',a') \right| \\ &\leq \gamma \sum_{s'} T(s,a,s') \max_{s',a'} |Q_1(s',a') - Q_2(s',a')| \\ &= \gamma \|Q_1 - Q_2\|_\infty \end{aligned}

Contraction Mapping Theorem

If B is a contraction mapping with factor γ < 1, then:

  1. B has a unique fixed point Q* such that BQ∗=Q∗BQ^* = Q^*
  2. Iteration converges: For any starting Q0Q_0, the sequence Qt+1=BQtQ_{t+1} = BQ_t converges to Q*
  3. Convergence rate: ∣∣Qt−Q∗∣∣∞≤γt∣∣Q0−Q∗∣∣∞||Q_t - Q^*||_∞ ≤ γ^t ||Q_0 - Q^*||_∞

Q-Learning Convergence Theorem ⭐

Theorem: Q-learning converges to Q* with probability 1 if:

  1. All state-action pairs are visited infinitely often
  2. Learning rates satisfy: Σαt=∞Σα_t = ∞ and Σαt2<∞Σα_t² < ∞

The decomposition argument:

Q-learning combines two approximations:

  1. Sampling: Using samples instead of computing expectations
  2. Bootstrapping: Using Q estimates instead of true Q*

Both converge independently:

  • Sampling converges (law of large numbers + learning rate conditions)
  • Bootstrapping converges (Bellman operator is a contraction)

Together, they still converge!

What Operations are Non-Expansions?

The following operations, when used in place of max in the Bellman equation, preserve convergence:

OperationExample Use
maxStandard optimal control
minMinimax (adversarial)
Fixed convex combinationStochastic policies
Order statisticsRobust optimization
ExpectationPolicy evaluation

Warning: Boltzmann (softmax) exploration is NOT guaranteed to be a non-expansion because the weights depend on the Q values themselves!

Generalized MDPs

The convergence theory extends to "Generalized MDPs" where max is replaced by other non-expansion operators:

  • Minimax MDPs: For two-player zero-sum games
  • Stochastic games: Multiple agents with mixed strategies

10. Key Equations Summary

Bellman Equations

Value function (prediction): Vπ(s)=R(s)+γ∑s′T(s,π(s),s′)Vπ(s′)V^\pi(s) = R(s) + \gamma \sum_{s'} T(s, \pi(s), s') V^\pi(s')

Optimal value function: V∗(s)=R(s)+γmax⁡a∑s′T(s,a,s′)V∗(s′)V^*(s) = R(s) + \gamma \max_a \sum_{s'} T(s, a, s') V^*(s')

Q-function: Q∗(s,a)=R(s,a)+γ∑s′T(s,a,s′)max⁡a′Q∗(s′,a′)Q^*(s, a) = R(s, a) + \gamma \sum_{s'} T(s, a, s') \max_{a'} Q^*(s', a')

TD Update Rules

TD(0) for V: V(st)←V(st)+α[rt+1+γV(st+1)−V(st)]V(s_t) \leftarrow V(s_t) + \alpha \left[ r_{t+1} + \gamma V(s_{t+1}) - V(s_t) \right]

Q-Learning: Q(st,at)←Q(st,at)+α[rt+1+γmax⁡a′Q(st+1,a′)−Q(st,at)]Q(s_t, a_t) \leftarrow Q(s_t, a_t) + \alpha \left[ r_{t+1} + \gamma \max_{a'} Q(s_{t+1}, a') - Q(s_t, a_t) \right]

TD Error: δt=rt+1+γV(st+1)−V(st)\delta_t = r_{t+1} + \gamma V(s_{t+1}) - V(s_t)

Discounting

Discounted return: Gt=∑k=0∞γkrt+k+1G_t = \sum_{k=0}^{\infty} \gamma^k r_{t+k+1}

Geometric series bound: ∑t=0∞γtRmax=Rmax1−γ\sum_{t=0}^{\infty} \gamma^t R_{max} = \frac{R_{max}}{1-\gamma}

Learning Rate Conditions

∑t=1∞αt=∞AND∑t=1∞αt2<∞\sum_{t=1}^{\infty} \alpha_t = \infty \quad \text{AND} \quad \sum_{t=1}^{\infty} \alpha_t^2 < \infty

Contraction Condition

∥BF−BG∥∞≤γ∥F−G∥∞with γ<1\|BF - BG\|_\infty \leq \gamma \|F - G\|_\infty \quad \text{with } \gamma < 1