RL lecture notes (archive)6 / 7

Lesson 6

RL Supplementary topics

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

1. Introduction and Core Concepts

1.1 The Three Types of Feedback in Machine Learning

Machine learning can be characterized by three types of feedback:

Feedback TypeDescriptionRL Relevance
Sequential vs One-shotMultiple decisions over time vs single decisionRL is sequential
Evaluative vs SupervisedOnly see rewards for actions taken vs see correct labelsRL is evaluative
Sample vs ExhaustiveLearn from samples vs see all possibilitiesRL uses samples

Key insight: Deep Reinforcement Learning combines ALL THREE challenges:

  • Sequential: Balance immediate vs long-term rewards
  • Evaluative: Balance exploration vs exploitation
  • Sample: Generalize across unseen states

1.2 Core Terminology

Reward (RtR_t): The immediate, one-step signal the agent receives at each timestep.

Return (GtG_t): The total (potentially discounted) sum of rewards from time tt onward:

Gt=Rt+1+γRt+2+γ2Rt+3+⋯=∑k=0∞γkRt+k+1G_t = R_{t+1} + \gamma R_{t+2} + \gamma^2 R_{t+3} + \cdots = \sum_{k=0}^{\infty} \gamma^k R_{t+k+1}

Value Function (Vπ(s)V^\pi(s)): The expected return when starting in state ss and following policy π\pi:

Vπ(s)=Eπ[Gt∣St=s]V^\pi(s) = \mathbb{E}_\pi[G_t | S_t = s]

Action-Value Function (Qπ(s,a)Q^\pi(s,a)): The expected return when starting in state ss, taking action aa, then following policy π\pi:

Qπ(s,a)=Eπ[Gt∣St=s,At=a]Q^\pi(s,a) = \mathbb{E}_\pi[G_t | S_t = s, A_t = a]

1.3 The Two Fundamental Problems

ProblemGoalInput → Output
PredictionEvaluate a given policyPolicy π\pi → Value function VπV^\pi or QπQ^\pi
ControlFind the optimal policyEnvironment → Optimal policy π∗\pi^*

Analogy:

  • Prediction is like a movie critic rating films — given a movie (policy), tell me how good it is
  • Control is like a movie studio trying to make the best film possible

2. The Exploration-Exploitation Trade-off

2.1 The Fundamental Dilemma

Exploration: Trying new actions to gather information about the environment

  • Pro: May discover better strategies
  • Con: May waste time on suboptimal actions

Exploitation: Using current knowledge to maximize rewards

  • Pro: Maximizes immediate expected reward
  • Con: May miss better opportunities

Real-world analogy: Restaurant choice

  • Exploitation: Always go to your favorite restaurant
  • Exploration: Try new restaurants to potentially find a better one

2.2 Multi-Armed Bandits

A simplified RL setting that isolates the exploration-exploitation problem:

  • Single state (no sequential decisions)
  • Multiple actions (arms) with unknown reward distributions
  • Goal: Minimize regret (cumulative difference from optimal)

Regret=∑t=1T(R∗−Rt)\text{Regret} = \sum_{t=1}^{T} (R^* - R_t)

where R∗R^* is the optimal expected reward.

2.3 Exploration Strategies

Greedy Strategy (Always Exploit)

  • Always choose arg⁡max⁡aQ(s,a)\arg\max_a Q(s,a)
  • Problem: Gets stuck with suboptimal actions
  • Example: First action happens to give reward → never try others

Random Strategy (Always Explore)

  • Choose actions uniformly at random
  • Problem: Never exploits learned knowledge
  • Eventually learns true values but very inefficiently

ε-Greedy Strategy (Balance Both)

At={arg⁡max⁡aQ(s,a)with probability 1−εrandom actionwith probability εA_t = \begin{cases} \arg\max_a Q(s,a) & \text{with probability } 1-\varepsilon \\ \text{random action} & \text{with probability } \varepsilon \end{cases}

  • Typical values: ε=0.1\varepsilon = 0.1 or ε=0.01\varepsilon = 0.01
  • Often decayed over time: start exploratory, become greedy
  • Simple but surprisingly effective in practice

3. Prediction Methods

The goal: Given a policy π\pi, estimate Vπ(s)V^\pi(s) for all states ss.

3.1 Monte Carlo Prediction

Core Idea: Run episodes, collect returns, average them.

Algorithm:

  1. Generate episodes using policy π\pi
  2. For each state ss visited in episode:
    • Calculate return GtG_t from that point
    • Update: V(s)←V(s)+α(Gt−V(s))V(s) \leftarrow V(s) + \alpha(G_t - V(s))

Incremental Update Formula:

V(St)←V(St)+α(Gt−V(St))⏟MC ErrorV(S_t) \leftarrow V(S_t) + \alpha \underbrace{(G_t - V(S_t))}_{\text{MC Error}}

Key Components:

  • MC Target: GtG_t (the actual return)
  • MC Error: Gt−V(St)G_t - V(S_t)

Two Variants:

  • First-visit MC: Only count first visit to each state per episode
  • Every-visit MC: Count every visit to each state

Properties:

PropertyValue
BiasUnbiased (uses actual returns)
VarianceHigh (returns vary a lot)
BootstrappingNo (waits for episode end)
Works for non-episodic?No

Analogy: Like computing your average grade by actually taking all exams and averaging the scores.

3.2 Temporal Difference (TD) Learning

Core Idea: Don't wait for episode end — bootstrap from current estimates.

TD(0) Update:

V(St)←V(St)+α(Rt+1+γV(St+1)−V(St))⏟TD Error δtV(S_t) \leftarrow V(S_t) + \alpha \underbrace{(R_{t+1} + \gamma V(S_{t+1}) - V(S_t))}_{\text{TD Error } \delta_t}

Key Components:

  • TD Target: Rt+1+γV(St+1)R_{t+1} + \gamma V(S_{t+1})
  • TD Error: δt=Rt+1+γV(St+1)−V(St)\delta_t = R_{t+1} + \gamma V(S_{t+1}) - V(S_t)

Why This Works (Bellman Equation):

Vπ(s)=Eπ[Rt+1+γVπ(St+1)∣St=s]V^\pi(s) = \mathbb{E}_\pi[R_{t+1} + \gamma V^\pi(S_{t+1}) | S_t = s]

TD learning uses this relationship — the value of a state should equal the expected immediate reward plus the discounted value of the next state.

Properties:

PropertyValue
BiasBiased (uses estimated values)
VarianceLow (only one-step randomness)
BootstrappingYes
Works for non-episodic?Yes

Analogy: Like estimating your final grade after each exam by combining your current score with your predicted average for remaining exams.

3.3 Comparing MC vs TD

MC Targets (for state 3 in random walk):   TD Targets:
     1                                      V(4) or V(2)
     0                                      ↓
     1                                   Approaches true
     0                                   values more smoothly
     ...                                 but with initial bias
High variance, unbiased                  Low variance, biased

Visual intuition:

  • MC estimates jump around the true value (high variance, unbiased)
  • TD estimates start off-target but converge smoothly (low variance, initially biased)

3.4 n-Step TD Learning

Generalization: Use nn steps of actual rewards before bootstrapping.

Gt(n)=Rt+1+γRt+2+⋯+γn−1Rt+n+γnV(St+n)G_t^{(n)} = R_{t+1} + \gamma R_{t+2} + \cdots + \gamma^{n-1} R_{t+n} + \gamma^n V(S_{t+n})

nMethod
n = 1TD(0)
n = 22-step TD
n = ∞Monte Carlo

3.5 TD(λ) — Eligibility Traces

Core Idea: Blend ALL n-step returns using exponentially decaying weights.

λ-Return:

Gtλ=(1−λ)∑n=1∞λn−1Gt(n)G_t^\lambda = (1-\lambda) \sum_{n=1}^{\infty} \lambda^{n-1} G_t^{(n)}

Special Cases:

  • λ=0\lambda = 0: Pure TD(0)
  • λ=1\lambda = 1: Pure Monte Carlo

Eligibility Traces (Backward View):

For each state ss, maintain an eligibility trace E(s)E(s):

Et(s)={γλEt−1(s)+1if St=sγλEt−1(s)otherwiseE_t(s) = \begin{cases} \gamma \lambda E_{t-1}(s) + 1 & \text{if } S_t = s \\ \gamma \lambda E_{t-1}(s) & \text{otherwise} \end{cases}

Update all states simultaneously:

V(s)←V(s)+αδtEt(s)∀sV(s) \leftarrow V(s) + \alpha \delta_t E_t(s) \quad \forall s

Intuition: When you receive a reward, credit goes back to recently visited states (high eligibility) more than distant states (decayed eligibility).

Analogy: If you win a game, the moves just before winning get more credit than moves at the start. Eligibility traces implement this "recency credit assignment."


4. Control Methods

The goal: Find the optimal policy π∗\pi^*.

4.1 Generalized Policy Iteration (GPI)

All control methods follow this pattern:

        Policy Evaluation
              ↓
    π → V^π (or Q^π)
    ↑           ↓
    └── Policy Improvement

Policy Improvement Theorem: If Qπ(s,π′(s))≥Vπ(s)Q^\pi(s, \pi'(s)) \geq V^\pi(s) for all ss, then π′≥π\pi' \geq \pi.

4.2 Monte Carlo Control

Idea: Use MC for evaluation + ε-greedy for improvement.

Algorithm:

  1. Generate episode using ε-greedy policy
  2. For each (s,a)(s,a) pair in episode:
    • Q(s,a)←Q(s,a)+α(Gt−Q(s,a))Q(s,a) \leftarrow Q(s,a) + \alpha(G_t - Q(s,a))
  3. Update policy: π(s)=arg⁡max⁡aQ(s,a)\pi(s) = \arg\max_a Q(s,a) (with ε-greedy)

4.3 SARSA (On-Policy TD Control)

Name origin: Uses (St,At,Rt+1,St+1,At+1)(S_t, A_t, R_{t+1}, S_{t+1}, A_{t+1}) — hence SARSA.

Update:

Q(St,At)←Q(St,At)+α[Rt+1+γQ(St+1,At+1)−Q(St,At)]Q(S_t, A_t) \leftarrow Q(S_t, A_t) + \alpha[R_{t+1} + \gamma Q(S_{t+1}, A_{t+1}) - Q(S_t, A_t)]

Key characteristic: Uses the action At+1A_{t+1} that you actually take (including exploratory actions).

On-Policy: The policy being learned IS the policy being used to collect data.

# SARSA pseudocode
for each episode:
    S = initial state
    A = ε-greedy action from Q(S,·)
    
    while not terminal:
        Take action A, observe R, S'
        A' = ε-greedy action from Q(S',·)  # Choose next action
        Q(S,A) += α * (R + γ*Q(S',A') - Q(S,A))
        S, A = S', A'

4.4 Q-Learning (Off-Policy TD Control)

Update:

Q(St,At)←Q(St,At)+α[Rt+1+γmax⁡aQ(St+1,a)−Q(St,At)]Q(S_t, A_t) \leftarrow Q(S_t, A_t) + \alpha[R_{t+1} + \gamma \max_a Q(S_{t+1}, a) - Q(S_t, A_t)]

Key difference from SARSA: Uses max⁡aQ(St+1,a)\max_a Q(S_{t+1}, a) instead of Q(St+1,At+1)Q(S_{t+1}, A_{t+1}).

Off-Policy: Learning about the greedy policy while following an exploratory policy.

# Q-learning pseudocode
for each episode:
    S = initial state
    
    while not terminal:
        A = ε-greedy action from Q(S,·)
        Take action A, observe R, S'
        Q(S,A) += α * (R + γ*max_a Q(S',a) - Q(S,A))  # Use max!
        S = S'

4.5 SARSA vs Q-Learning: Key Differences

AspectSARSAQ-Learning
TypeOn-policyOff-policy
TargetR+γQ(S′,A′)R + \gamma Q(S', A')R+γmax⁡aQ(S′,a)R + \gamma \max_a Q(S', a)
Action usedActual next actionBest next action
Learns aboutCurrent ε-greedy policyOptimal greedy policy
Safer behaviorYes (accounts for exploration)No (assumes greedy future)

When does this matter?

Consider a cliff-walking problem:

  • SARSA learns a safer path (avoids cliff edge because it knows it might accidentally fall)
  • Q-learning learns the optimal path (hugs cliff edge, assuming perfect execution)

5. Deep Reinforcement Learning Foundations

5.1 Why Function Approximation?

Problem with Tabular Methods:

For Atari games: State space ≈ 256210×160×3256^{210 \times 160 \times 3} (a number with 242,000 digits!)

Three Reasons for Function Approximation:

  1. High-dimensional discrete spaces: Too many states to store in a table
  2. Continuous state spaces: Infinite states (e.g., robot joint angles)
  3. Generalization: Learn about similar states simultaneously

Analogy: You can't memorize the value of every possible chess position. Instead, you learn general principles (control the center, protect your king) that generalize.

5.2 How Function Approximation Helps

Without FA: Each state updated independently

V(s1) = 2.1    # Update s1 only affects s1
V(s2) = 3.4
V(s3) = 1.8

With FA: Updates affect similar states

V_θ(s) = θ₀ + θ₁·s    # A linear function
# Updating θ affects V for ALL states

Key insight: One update can improve estimates for many states you've never visited.

5.3 Neural Network Basics for RL

Architecture for Q-learning:

Input Layer (state)     Hidden Layer(s)     Output Layer (Q-values)
    [s1]                    [h1]                [Q(s,a1)]
    [s2]     →    W1    →   [h2]    →   W2  →   [Q(s,a2)]
    [s3]                    [h3]                [Q(s,a3)]
    [s4]                                        [Q(s,a4)]

For this course: One hidden layer is typically sufficient.

Warning: Deeper networks require more data and training time.

5.4 The CartPole Environment

A standard benchmark for testing RL algorithms:

Observations (4 continuous values):

  1. Cart position: [−2.4,2.4][-2.4, 2.4]
  2. Cart velocity: (−∞,∞)(-\infty, \infty)
  3. Pole angle: [−12°,12°][-12°, 12°] (terminal if exceeded)
  4. Pole tip velocity: (−∞,∞)(-\infty, \infty)

Actions: 2 discrete (push left or push right)

Reward: +1 for each timestep the pole stays upright

Goal: Keep the pole balanced for as long as possible


6. Value-Based Deep RL: DQN and Beyond

6.1 The Ideal Objective

We want to minimize:

L(θ)=E[(Q∗(s,a)−Qθ(s,a))2]L(\theta) = \mathbb{E}\left[(Q^*(s,a) - Q_\theta(s,a))^2\right]

Problem: We don't have Q∗Q^*!

Solution: Use TD targets as a proxy:

L(θ)=E[(R+γmax⁡a′Qθ(s′,a′)−Qθ(s,a))2]L(\theta) = \mathbb{E}\left[(R + \gamma \max_{a'} Q_\theta(s', a') - Q_\theta(s,a))^2\right]

6.2 Two Critical Issues with Naive Deep Q-Learning

Issue 1: Non-Stationary Targets

When you update QθQ_\theta, the target R+γmax⁡a′Qθ(s′,a′)R + \gamma \max_{a'} Q_\theta(s', a') also changes!

Imagine chasing a moving target:
Before update: Target at position X
After update: Target moved to position Y
→ Optimization landscape keeps shifting!

This can cause divergence — the agent "unlearns" and performance collapses.

Issue 2: Correlated Data

Standard ML assumes IID (independent, identically distributed) data.

But in RL, consecutive samples are highly correlated:

  • st+1s_{t+1} depends on sts_t and ata_t
  • Training on trajectory data violates IID assumption

6.3 DQN: Deep Q-Networks

Two key innovations:

1. Experience Replay Buffer

Store transitions (s,a,r,s′,done)(s, a, r, s', done) in a buffer (e.g., 1 million samples).

Sample random mini-batches for training → breaks correlation!

Replay Buffer D: [(s₁,a₁,r₁,s₁'), (s₂,a₂,r₂,s₂'), ...]
                         ↓
Sample mini-batch uniformly at random
                         ↓
Train on decorrelated data

2. Target Network

Maintain a separate network Qθ−Q_{\theta^-} for computing targets.

y=R+γmax⁡a′Qθ−(s′,a′)y = R + \gamma \max_{a'} Q_{\theta^-}(s', a')

Update θ−\theta^- only periodically (e.g., every 10,000 steps).

Why it helps: Target stays fixed for many updates → stable optimization.

6.4 DQN Algorithm

Initialize Q_θ (online network) and Q_θ⁻ (target network)
Initialize replay buffer D
 
for each episode:
    s = initial state
    
    while not terminal:
        # Select action (ε-greedy)
        a = ε-greedy from Q_θ(s,·)
        
        # Execute and observe
        s', r, done = env.step(a)
        
        # Store transition
        D.store(s, a, r, s', done)
        
        # Sample mini-batch from D
        batch = D.sample(batch_size=32)
        
        # Compute targets (using target network!)
        y = r + γ * max_a' Q_θ⁻(s', a') * (1 - done)
        
        # Update Q_θ via gradient descent
        loss = (y - Q_θ(s,a))²
        θ = θ - α∇_θ loss
        
        # Periodically update target network
        if step % C == 0:
            θ⁻ = θ
        
        s = s'

6.5 The Target Network Equation

DQN Loss:

L(θ)=E(s,a,r,s′)∼D[(r+γmax⁡a′Qθ−(s′,a′)−Qθ(s,a))2]L(\theta) = \mathbb{E}_{(s,a,r,s') \sim D}\left[\left(r + \gamma \max_{a'} Q_{\theta^-}(s', a') - Q_\theta(s,a)\right)^2\right]

Note: θ−\theta^- is the target network (fixed), θ\theta is the online network (being updated).

Critical: Don't backpropagate through the target! (Use .detach() in PyTorch)

6.6 Double DQN

Problem with DQN: Overestimation bias

When computing max⁡aQ(s′,a)\max_a Q(s', a), we use the same network to:

  1. Select the best action
  2. Evaluate that action's value

If Q-values are noisy (they always are), max picks the one with the highest noise → systematic overestimation.

Solution: Decouple selection and evaluation

Standard DQN: y=R+γQθ−(s′,arg⁡max⁡a′Qθ−(s′,a′))y = R + \gamma Q_{\theta^-}(s', \arg\max_{a'} Q_{\theta^-}(s', a'))

Double DQN: y=R+γQθ−(s′,arg⁡max⁡a′Qθ(s′,a′))y = R + \gamma Q_{\theta^-}(s', \arg\max_{a'} Q_\theta(s', a'))

  • Online network QθQ_\theta: Selects the best action
  • Target network Qθ−Q_{\theta^-}: Evaluates that action

Example:

Online network estimates:   Q_θ(s', a0) = 3.5, Q_θ(s', a1) = 1.2, Q_θ(s', a2) = 3.9
                           → argmax = a2
 
Target network estimates:   Q_θ⁻(s', a0) = 3.8, Q_θ⁻(s', a1) = -1.5, Q_θ⁻(s', a2) = 3.6
                           → Use Q_θ⁻(s', a2) = 3.6 as target
 
Without Double DQN:         Would use Q_θ⁻(s', a0) = 3.8 (target's argmax)

This cross-validation style approach reduces overestimation.

6.7 Summary of DQN Improvements

TechniqueProblem Solved
Experience ReplayCorrelated data, IID violation
Target NetworkNon-stationary targets
Double DQNOverestimation bias

Additional improvements (not covered in depth):

  • Prioritized Experience Replay: Sample important transitions more often
  • Dueling Networks: Separate state value and advantage
  • Noisy Nets: Learned exploration
  • Rainbow: Combines multiple improvements

7. Policy-Based Methods

7.1 Value-Based vs Policy-Based

Value-Based (DQN)Policy-Based
Learn Q(s,a)Q(s,a), derive policy as arg max⁡\argmaxLearn policy π\pi directly
Outputs valuesOutputs action probabilities
Implicit policyExplicit policy
Struggles with continuous actionsNatural for continuous actions
Deterministic policy (plus ε-greedy)Can learn stochastic policies

7.2 Why Policy-Based Methods?

Advantage 1: Continuous Action Spaces

With DQN, you need to compute arg⁡max⁡aQ(s,a)\arg\max_a Q(s,a). For continuous actions, this is intractable!

Policy networks output distributions directly:

Input: state s
Output: μ₁, σ₁, μ₂, σ₂, ... (means and std devs for each action dimension)

Sample actions from ai∼N(μi,σi2)a_i \sim \mathcal{N}(\mu_i, \sigma_i^2)

Advantage 2: Stochastic Policies

Some problems require randomness. Example: Rock-Paper-Scissors

The optimal strategy is uniform random: P(rock)=P(paper)=P(scissors)=1/3P(\text{rock}) = P(\text{paper}) = P(\text{scissors}) = 1/3

A deterministic policy would be exploitable!

Advantage 3: State Aliasing

If two different states look identical to the agent, a stochastic policy can hedge:

State looks like X, but could be:
  - State A (optimal action: left)
  - State B (optimal action: right)
  
Optimal response: 50% left, 50% right

7.3 Policy Gradient Objective

Goal: Find parameters θ\theta that maximize expected return:

J(θ)=Eτ∼πθ[G(τ)]=Eτ∼πθ[∑t=0TγtRt]J(\theta) = \mathbb{E}_{\tau \sim \pi_\theta}[G(\tau)] = \mathbb{E}_{\tau \sim \pi_\theta}\left[\sum_{t=0}^{T} \gamma^t R_t\right]

where τ\tau is a trajectory (s0,a0,r1,s1,a1,...)(s_0, a_0, r_1, s_1, a_1, ...)

7.4 The Policy Gradient Theorem

Key Result:

∇θJ(θ)=Eπθ[∑t=0T∇θlog⁡πθ(at∣st)⋅Gt]\nabla_\theta J(\theta) = \mathbb{E}_{\pi_\theta}\left[\sum_{t=0}^{T} \nabla_\theta \log \pi_\theta(a_t|s_t) \cdot G_t\right]

Intuition:

  • ∇θlog⁡πθ(at∣st)\nabla_\theta \log \pi_\theta(a_t|s_t): Direction to make action ata_t more likely
  • GtG_t: How good was the outcome?
  • Product: Increase probability of good actions, decrease probability of bad actions

Derivation insight (optional): Uses the "log-derivative trick": ∇θπ=π∇θlog⁡π\nabla_\theta \pi = \pi \nabla_\theta \log \pi

7.5 REINFORCE Algorithm

The simplest policy gradient algorithm:

for each episode:
    Generate trajectory τ = (s₀, a₀, r₁, ..., sT) using π_θ
    
    for t = 0 to T:
        G_t = Σ_{k=t}^T γ^(k-t) r_{k+1}  # Return from t
        θ = θ + α · ∇_θ log π_θ(aₜ|sₜ) · G_t

Key improvement: Use rewards-to-go instead of full return

Instead of using G0G_0 for all timesteps, use GtG_t (future rewards only).

Why? Actions at time tt shouldn't get credit for rewards that happened before tt.

7.6 Baselines and Variance Reduction

Problem: Policy gradients have high variance (noisy updates).

Solution: Subtract a baseline b(s)b(s) that doesn't depend on actions:

∇θJ(θ)=E[∇θlog⁡πθ(at∣st)⋅(Gt−b(st))]\nabla_\theta J(\theta) = \mathbb{E}\left[\nabla_\theta \log \pi_\theta(a_t|s_t) \cdot (G_t - b(s_t))\right]

Why this works: E[∇θlog⁡πθ(a∣s)⋅b(s)]=0\mathbb{E}[\nabla_\theta \log \pi_\theta(a|s) \cdot b(s)] = 0 (baseline doesn't change expected gradient)

Best baseline: b(s)=V(s)b(s) = V(s) (the value function!)

This leads to the Advantage Function:

A(s,a)=Q(s,a)−V(s)A(s,a) = Q(s,a) - V(s)

Interpretation: How much better is action aa compared to the average action in state ss?


8. Actor-Critic Methods

8.1 The Actor-Critic Framework

Two networks:

  • Actor: Policy πθ(a∣s)\pi_\theta(a|s) — chooses actions
  • Critic: Value function Vϕ(s)V_\phi(s) — evaluates states
         Environment
            ↓ state s
    ┌───────┴───────┐
    ↓               ↓
  Actor           Critic
  π_θ(a|s)        V_φ(s)
    ↓               ↓
  action a      value estimate
    ↓               ↓
         └────┬────┘
              ↓
        TD error δ = r + γV(s') - V(s)
              ↓
        Update both networks

8.2 Advantage Estimation

One-step advantage (TD error):

A^t=Rt+1+γV(St+1)−V(St)\hat{A}_t = R_{t+1} + \gamma V(S_{t+1}) - V(S_t)

This IS the TD error! It estimates how much better the action was than expected.

8.3 A3C: Asynchronous Advantage Actor-Critic

Key idea: Run multiple workers in parallel, each with its own environment copy.

Benefits:

  • Natural decorrelation (workers explore different parts of state space)
  • Better CPU utilization (no GPU needed)
  • Faster wall-clock training

Architecture:

         Global Network (θ, φ)
        /      |      \      \
    Worker1  Worker2  Worker3  ...
      ↓        ↓        ↓
    Env1     Env2     Env3
      ↓        ↓        ↓
   gradients (asynchronous updates to global network)

"Asynchronous": Workers update the global network independently, without waiting for each other.

8.4 A2C: Advantage Actor-Critic (Synchronous)

Same as A3C but:

  • Workers collect data in parallel
  • Wait for all workers to finish
  • Update network once with combined batch

Advantage: More stable updates (no race conditions)

Trade-off: Faster workers must wait for slower ones

8.5 n-Step Returns and GAE

n-Step Advantage:

A^t(n)=Rt+1+γRt+2+⋯+γn−1Rt+n+γnV(St+n)−V(St)\hat{A}_t^{(n)} = R_{t+1} + \gamma R_{t+2} + \cdots + \gamma^{n-1} R_{t+n} + \gamma^n V(S_{t+n}) - V(S_t)

Generalized Advantage Estimation (GAE):

A^tGAE=∑l=0∞(γλ)lδt+l\hat{A}_t^{GAE} = \sum_{l=0}^{\infty} (\gamma \lambda)^l \delta_{t+l}

where δt=Rt+1+γV(St+1)−V(St)\delta_t = R_{t+1} + \gamma V(S_{t+1}) - V(S_t)

Special cases:

  • λ=0\lambda = 0: One-step TD advantage (low variance, high bias)
  • λ=1\lambda = 1: Monte Carlo advantage (high variance, low bias)

Practical: λ=0.95\lambda = 0.95 or 0.970.97 works well

8.6 Actor-Critic Update Equations

Critic Update (minimize TD error):

ϕ←ϕ−αϕ∇ϕ(R+γVϕ(s′)−Vϕ(s))2\phi \leftarrow \phi - \alpha_\phi \nabla_\phi (R + \gamma V_\phi(s') - V_\phi(s))^2

Actor Update (policy gradient with advantage):

θ←θ+αθ∇θlog⁡πθ(a∣s)⋅A^\theta \leftarrow \theta + \alpha_\theta \nabla_\theta \log \pi_\theta(a|s) \cdot \hat{A}

Entropy bonus (encourages exploration):

Jentropy(θ)=β⋅H(πθ(⋅∣s))J_\text{entropy}(\theta) = \beta \cdot H(\pi_\theta(\cdot|s))

where HH is entropy. Added to actor objective to prevent premature convergence.


9. Deterministic Policy Gradient Methods

9.1 Motivation: Continuous Control

Problem with Q-learning for continuous actions:

Computing max⁡aQ(s,a)\max_a Q(s,a) requires iterating over all actions — impossible for continuous spaces!

Solution: Learn a deterministic policy μθ(s)\mu_\theta(s) that directly outputs the optimal action.

9.2 DDPG: Deep Deterministic Policy Gradient

Key insight: Combine DQN techniques with policy gradients for continuous control.

Two networks:

  • Actor: μθ(s)\mu_\theta(s) — outputs deterministic action
  • Critic: Qϕ(s,a)Q_\phi(s, a) — evaluates state-action pairs

Note: Unlike A3C/A2C, the critic is a Q-function, not a V-function!

9.3 DDPG Architecture

State s → Actor μ_θ(s) → Action a
                ↓
    ┌───────────┴───────────┐
    ↓                       ↓
State s, Action a → Critic Q_φ(s,a) → Q-value

Actor objective: Maximize Q-values for chosen actions

J(θ)=E[Qϕ(s,μθ(s))]J(\theta) = \mathbb{E}[Q_\phi(s, \mu_\theta(s))]

Critic objective: Minimize TD error

L(ϕ)=E[(R+γQϕ−(s′,μθ−(s′))−Qϕ(s,a))2]L(\phi) = \mathbb{E}[(R + \gamma Q_{\phi^-}(s', \mu_{\theta^-}(s')) - Q_\phi(s,a))^2]

9.4 DDPG Key Features

From DQN:

  • Experience replay buffer
  • Target networks (both actor and critic)

Different from DQN:

  • Soft target updates: Instead of copying weights every CC steps,

θ−←τθ+(1−τ)θ−\theta^- \leftarrow \tau \theta + (1-\tau) \theta^-

where τ≪1\tau \ll 1 (e.g., 0.001). Smoother, more stable.

Exploration: Add noise to actions (e.g., Ornstein-Uhlenbeck noise for temporally correlated exploration)

9.5 Algorithm Family

AlgorithmKey Features
DDPGDeterministic policy + Q-learning for continuous control
TD3Twin critics + delayed policy updates (reduces overestimation)
SACSoft Actor-Critic, adds entropy regularization

Recommendation for continuous control: TD3 or SAC are more stable than DDPG


10. Convergence and Theory

10.1 GLIE: Greedy in the Limit with Infinite Exploration

For control algorithms to converge to optimal, two conditions must hold:

Condition 1: All state-action pairs must be visited infinitely often:

lim⁡t→∞Nt(s,a)=∞∀s,a\lim_{t \to \infty} N_t(s,a) = \infty \quad \forall s,a

Condition 2: Policy must converge to greedy:

lim⁡t→∞πt(a∣s)=1[a=arg⁡max⁡a′Q(s,a′)]\lim_{t \to \infty} \pi_t(a|s) = \mathbf{1}[a = \arg\max_{a'} Q(s,a')]

ε-greedy with decay satisfies GLIE:

  • Start with high ε (explore)
  • Decay towards 0 (exploit)
  • But decay slowly enough to keep exploring

10.2 Robbins-Monro Conditions for Step Sizes

For stochastic approximation (including TD/Q-learning) to converge:

Condition 1: Sum of step sizes is infinite (can reach any target): ∑t=1∞αt=∞\sum_{t=1}^{\infty} \alpha_t = \infty

Condition 2: Sum of squared step sizes is finite (variance goes to zero): ∑t=1∞αt2<∞\sum_{t=1}^{\infty} \alpha_t^2 < \infty

Example: αt=1/t\alpha_t = 1/t satisfies both.

In practice: Often use constant small α (doesn't technically converge but tracks changing targets)

10.3 On-Policy vs Off-Policy Convergence

On-Policy (SARSA)Off-Policy (Q-Learning)
Convergence guaranteeNeeds GLIENeeds GLIE for optimal control
What it converges toValue of ε-greedy policyOptimal Q-values
For accurate Q*Needs both conditionsOnly needs condition 1

10.4 Deep RL: No Guarantees

Important: All classical convergence guarantees assume:

  • Tabular representations
  • Exact updates

With function approximation (especially neural networks):

  • No convergence guarantees
  • Can diverge in practice
  • "Deadly triad": function approximation + bootstrapping + off-policy = potential divergence

Mitigation techniques (used in DQN, etc.):

  • Target networks
  • Experience replay
  • Gradient clipping
  • Careful hyperparameter tuning

11. Algorithm Summary and Comparison

11.1 Prediction Methods

MethodUpdate TargetBiasVarianceBootstraps
Monte CarloGtG_t (actual return)NoneHighNo
TD(0)R+γV(s′)R + \gamma V(s')YesLowYes
TD(λ)λ-weighted mixTunableTunableYes

11.2 Tabular Control Methods

MethodTypeUpdate Target
MC ControlOn-policyGtG_t
SARSAOn-policyR+γQ(s′,a′)R + \gamma Q(s', a') where a′a' is actual next action
Q-LearningOff-policyR+γmax⁡aQ(s′,a)R + \gamma \max_a Q(s', a)

11.3 Deep RL Methods

MethodTypeAction SpaceKey Features
DQNValue-basedDiscreteReplay buffer, target network
Double DQNValue-basedDiscrete+ Decoupled action selection/evaluation
REINFORCEPolicy-basedBothSimplest policy gradient
A2C/A3CActor-CriticBothParallel workers, advantage
DDPGActor-CriticContinuousDeterministic policy, soft updates
TD3Actor-CriticContinuousTwin critics, delayed updates
PPOActor-CriticBothClipped objective, stable

11.4 When to Use What

ScenarioRecommended Algorithm
Discrete actions, image inputDQN / Double DQN / Rainbow
Continuous actionsDDPG / TD3 / SAC / PPO
Simple discrete environmentQ-Learning (tabular)
Need stable trainingPPO or TD3
Multi-CPU, no GPUA3C
Sample efficiency criticalSAC or model-based methods

11.5 Key Equations Reference Card

Bellman Equation: Vπ(s)=Eπ[Rt+1+γVπ(St+1)∣St=s]V^\pi(s) = \mathbb{E}_\pi[R_{t+1} + \gamma V^\pi(S_{t+1}) | S_t = s]

TD Error: δt=Rt+1+γV(St+1)−V(St)\delta_t = R_{t+1} + \gamma V(S_{t+1}) - V(S_t)

Q-Learning Update: Q(s,a)←Q(s,a)+α[R+γmax⁡a′Q(s′,a′)−Q(s,a)]Q(s,a) \leftarrow Q(s,a) + \alpha[R + \gamma \max_{a'} Q(s',a') - Q(s,a)]

Policy Gradient: ∇θJ(θ)=Eπθ[∇θlog⁡πθ(a∣s)⋅A(s,a)]\nabla_\theta J(\theta) = \mathbb{E}_{\pi_\theta}[\nabla_\theta \log \pi_\theta(a|s) \cdot A(s,a)]

DQN Loss: L(θ)=E[(R+γmax⁡a′Qθ−(s′,a′)−Qθ(s,a))2]L(\theta) = \mathbb{E}[(R + \gamma \max_{a'} Q_{\theta^-}(s',a') - Q_\theta(s,a))^2]

Double DQN Target: y=R+γQθ−(s′,arg⁡max⁡a′Qθ(s′,a′))y = R + \gamma Q_{\theta^-}(s', \arg\max_{a'} Q_\theta(s',a'))


Exam Preparation Tips

  1. Know the core update equations for Q-learning, SARSA, TD, and policy gradients
  2. Understand the motivation for each technique (why replay buffers? why target networks?)
  3. Be able to trace through one update step for each algorithm
  4. Distinguish on-policy vs off-policy and when each matters
  5. Understand the bias-variance trade-off in MC vs TD
  6. Know the advantages of policy-based vs value-based methods
  7. Remember the two DQN innovations: replay buffer and target network
  8. Understand Double DQN: why it reduces overestimation