RL lecture notes (archive)2 / 7

Lesson 2

RL 5-7

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

Foundational Concepts Review

Before diving into the lectures, make sure you understand these core RL concepts:

Markov Decision Process (MDP)

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

  • SS: Set of states
  • AA: Set of actions
  • T(s,a,s′)T(s, a, s'): Transition probability P(s′∣s,a)P(s' | s, a)
  • R(s,a)R(s, a) or R(s,a,s′)R(s, a, s'): Reward function
  • γ∈[0,1)\gamma \in [0, 1): Discount factor

Value Functions

  • State Value Function: Vπ(s)V^\pi(s) = expected return starting from state ss and following policy π\pi
  • Action Value Function: Qπ(s,a)Q^\pi(s, a) = expected return starting from state ss, taking action aa, then following π\pi

Bellman Equations

The Bellman equation relates the value of a state to the values of successor states:

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')

Key insight: This equation says "the value of taking action aa in state ss equals the immediate reward plus the discounted expected value of where you end up."


Lecture 5: Advanced Algorithmic Analysis (AAA)

This lecture covers three main algorithms for solving MDPs: Value Iteration (VI), Linear Programming (LP), and Policy Iteration (PI). It also establishes key theoretical properties about convergence and optimality.


Value Iteration Deep Dive

What is Value Iteration?

Value Iteration is an iterative algorithm that repeatedly applies the Bellman operator to converge to the optimal value function.

Bellman Operator BB: Given a value function VV, the Bellman operator produces a new value function:

[BV](s)=max⁡a[R(s,a)+γ∑s′T(s,a,s′)V(s′)][BV](s) = \max_a \left[ R(s, a) + \gamma \sum_{s'} T(s, a, s') V(s') \right]

Key Properties of Value Iteration

Property 1: Contraction Mapping

The Bellman operator is a contraction mapping with contraction factor γ\gamma:

∥BV1−BV2∥∞≤γ∥V1−V2∥∞\|BV_1 - BV_2\|_\infty \leq \gamma \|V_1 - V_2\|_\infty

What this means: Applying the Bellman operator brings any two value functions closer together by at least a factor of γ\gamma. This guarantees convergence to a unique fixed point.

Intuition: Think of it like two people walking toward the same destination. Each step, they get at least γ\gamma times closer. Eventually, they converge.

Property 2: K-Step Contraction

Applying the Bellman operator kk times has contraction factor γk\gamma^k:

∥BkV1−BkV2∥∞≤γk∥V1−V2∥∞\|B^k V_1 - B^k V_2\|_\infty \leq \gamma^k \|V_1 - V_2\|_\infty

Practical implication: Running 10 steps of VI is like running one step of "10-step VI" with much stronger contraction.

Convergence Results

Result 1: Greedy Policy Converges in Polynomial Time

There exists a finite T∗T^*, polynomial in:

  • ∣S∣|S| (number of states)
  • ∣A∣|A| (number of actions)
  • Magnitude of rewards
  • Bits of precision in transition probabilities
  • 11−γ\frac{1}{1-\gamma}

such that after T∗T^* iterations, the greedy policy with respect to QT∗Q_{T^*} is optimal.

Important distinction: The value function converges only in the limit, but the greedy policy becomes optimal in finite time.

Why does this work? Once you have enough precision in your Q-values to distinguish the best action from the second-best action in every state, the greedy policy will be correct. This gap exists because of the finite precision in the MDP specification (follows from Cramer's rule in linear algebra).

Result 2: Stopping Criterion

If consecutive value functions satisfy:

∥Vt+1−Vt∥∞<ϵ\|V_{t+1} - V_t\|_\infty < \epsilon

Then the greedy policy π\pi with respect to Vt+1V_{t+1} satisfies:

∥V∗−Vπ∥∞≤2ϵγ1−γ\|V^* - V^\pi\|_\infty \leq \frac{2\epsilon\gamma}{1-\gamma}

Why this matters: This gives us a practical stopping criterion! We can check if our value function has "stopped changing" and bound how far from optimal we are.

Intuition for the bound:

  • The ϵ\epsilon error at each step could compound over the effective horizon
  • Effective horizon is ≈11−γ\approx \frac{1}{1-\gamma}
  • The 22 accounts for error in either direction
  • The γ\gamma accounts for one-step delay

The Role of Gamma

Small γ\gamma (e.g., 0.1)Large γ\gamma (e.g., 0.99)
Short-sighted behaviorFar-sighted behavior
Easier to solveHarder to solve
Faster convergenceSlower convergence
Effective horizon ≈ 1Effective horizon ≈ 100

Effective horizon: 11−γ\frac{1}{1-\gamma} roughly tells you "how far into the future matters."

Trade-off: You want γ\gamma large enough to capture long-term consequences but not so large that computation becomes infeasible.


Linear Programming for MDPs

Why Linear Programming?

Value iteration is not polynomial in the true sense because convergence time depends on 11−γ\frac{1}{1-\gamma}, which can be exponentially large in the bits needed to represent γ\gamma.

Linear Programming provides the only known truly polynomial time algorithm for solving MDPs.

The Challenge

We want to solve the Bellman equation:

V(s)=max⁡a[R(s,a)+γ∑s′T(s,a,s′)V(s′)]V(s) = \max_a \left[ R(s, a) + \gamma \sum_{s'} T(s, a, s') V(s') \right]

Problem: The max⁡\max operator is non-linear!

The Key Insight: Max as Optimization

For scalars: x=max⁡(a,b,c)x = \max(a, b, c) is equivalent to:

  • Minimize xx
  • Subject to: x≥ax \geq a, x≥bx \geq b, x≥cx \geq c

The minimum xx satisfying all constraints equals the maximum of the values.

Primal LP Formulation

min⁡V∑sV(s)\min_{V} \sum_s V(s)

Subject to: V(s)≥R(s,a)+γ∑s′T(s,a,s′)V(s′)∀s,aV(s) \geq R(s, a) + \gamma \sum_{s'} T(s, a, s') V(s') \quad \forall s, a

Variables: V(s)V(s) for each state (one variable per state)

Constraints: One constraint per state-action pair

Interpretation: We're finding the smallest value function that satisfies all the Bellman inequalities. The minimum that satisfies all constraints is exactly the optimal value function.

Dual LP Formulation

Through LP duality (swapping variables and constraints), we get:

max⁡q∑s,aq(s,a)⋅R(s,a)\max_{q} \sum_{s,a} q(s,a) \cdot R(s,a)

Subject to: ∑aq(s′,a)=1+γ∑s,aq(s,a)⋅T(s,a,s′)∀s′\sum_a q(s',a) = 1 + \gamma \sum_{s,a} q(s,a) \cdot T(s,a,s') \quad \forall s' q(s,a)≥0∀s,aq(s,a) \geq 0 \quad \forall s, a

Variables: q(s,a)q(s,a) for each state-action pair

Interpretation - Policy Flow:

  • q(s,a)q(s,a) represents "how much agent-ness flows through" each state-action pair
  • The constraints ensure flow conservation: what flows into a state must flow out
  • We maximize expected reward (objective function directly corresponds to reward!)

Why the dual is intuitive: We're directly maximizing reward rather than minimizing values (which felt counterintuitive in the primal).

Practical Considerations

LP is theoretically elegant but often:

  • Has overhead compared to VI/PI
  • Is useful when you need additional linear constraints
  • Provides a rigorous polynomial-time guarantee

Policy Iteration

The Algorithm

Policy Iteration alternates between two steps:

1. Policy Evaluation: Given policy πt\pi_t, compute its value function Qt=QπtQ_t = Q^{\pi_t}

2. Policy Improvement: Take the greedy policy with respect to QtQ_t: πt+1(s)=arg⁡max⁡aQt(s,a)\pi_{t+1}(s) = \arg\max_a Q_t(s, a)

Repeat until the policy stops changing.

Why Policy Iteration Works: The Theoretical Foundation

Concept 1: Domination

Definition: Policy π1\pi_1 dominates policy π2\pi_2 (written π1⪰π2\pi_1 \succeq \pi_2) if: Vπ1(s)≥Vπ2(s)∀s∈SV^{\pi_1}(s) \geq V^{\pi_2}(s) \quad \forall s \in S

Strict domination (π1≻π2\pi_1 \succ \pi_2): π1\pi_1 dominates π2\pi_2 AND there exists some state where the inequality is strict.

Key insight: Domination is state-wise, not just aggregate. This prevents cycling.

Concept 2: Bellman Operators for Fixed Policies

For a fixed policy π\pi, define operator BπB_\pi:

[BπV](s)=R(s,π(s))+γ∑s′T(s,π(s),s′)V(s′)[B_\pi V](s) = R(s, \pi(s)) + \gamma \sum_{s'} T(s, \pi(s), s') V(s')

Properties of BπB_\pi:

  1. Contraction: ∥BπV1−BπV2∥≤γ∥V1−V2∥\|B_\pi V_1 - B_\pi V_2\| \leq \gamma \|V_1 - V_2\|
  2. Unique fixed point: BπVπ=VπB_\pi V^{\pi} = V^{\pi}
  3. Monotonicity: If V1≥V2V_1 \geq V_2 (pointwise), then BπV1≥BπV2B_\pi V_1 \geq B_\pi V_2

Concept 3: Value Improvement Lemma

The crucial lemma: If π2\pi_2 is greedy with respect to Qπ1Q^{\pi_1}, then:

Bπ2Qπ1≥Qπ1B_{\pi_2} Q^{\pi_1} \geq Q^{\pi_1}

Proof sketch:

  • π2\pi_2 is greedy, so π2(s)=arg⁡max⁡aQπ1(s,a)\pi_2(s) = \arg\max_a Q^{\pi_1}(s, a)
  • Therefore Qπ1(s,π2(s))≥Qπ1(s,π1(s))Q^{\pi_1}(s, \pi_2(s)) \geq Q^{\pi_1}(s, \pi_1(s))
  • The Bellman equation for π1\pi_1 says Qπ1(s,π1(s))=[Bπ1Qπ1](s)Q^{\pi_1}(s, \pi_1(s)) = [B_{\pi_1} Q^{\pi_1}](s)
  • So taking one greedy step can only improve (or maintain) value

The Policy Iteration Proof

Theorem: Each step of policy iteration produces Qπt+1≥QπtQ^{\pi_{t+1}} \geq Q^{\pi_t}

Proof (the four-step argument):

  1. Value Improvement: Qπ1≤B2Qπ1Q^{\pi_1} \leq B_2 Q^{\pi_1} (One step with greedy policy improves or maintains value)

  2. Monotonicity (applied repeatedly): B2kQπ1≤B2k+1Qπ1∀kB_2^k Q^{\pi_1} \leq B_2^{k+1} Q^{\pi_1} \quad \forall k (Each additional step maintains the ordering)

  3. Transitivity: Qπ1≤B2kQπ1∀kQ^{\pi_1} \leq B_2^k Q^{\pi_1} \quad \forall k (Chaining the inequalities)

  4. Fixed point: lim⁡k→∞B2kQπ1=Qπ2\lim_{k \to \infty} B_2^k Q^{\pi_1} = Q^{\pi_2} (Repeated application converges to π2\pi_2's value function)

Therefore: Qπ1≤Qπ2Q^{\pi_1} \leq Q^{\pi_2}

Why Policy Iteration Doesn't Get Stuck

Key insight: Value improvement is state-wise, not just aggregate.

If π\pi is not optimal, there exists some state where improvement is strict. This prevents cycling between policies.

Finite convergence:

  • There are only ∣A∣∣S∣|A|^{|S|} deterministic policies (finite!)
  • Each iteration strictly improves the policy (unless we're at optimal)
  • Therefore, we must converge in finite iterations

Convergence Bounds

Lower Bound: Ω(∣S∣)\Omega(|S|) iterations (Some MDPs require at least ∣S∣|S| iterations)

Upper Bound: O(∣A∣∣S∣)O(|A|^{|S|}) iterations (At most the number of policies)

Open question: The exact complexity of policy iteration remains unknown!

Value Iteration vs Policy Iteration

AspectValue IterationPolicy Iteration
Per-iteration costO(∥S∥2∥A∥)O(\|S\|^2\|A\|)O(∥S∥3+∥S∥2∥A∥)O(\|S\|^3 + \|S\|^2\|A\|)
Number of iterationsCan be large (depends on γ\gamma)Often very few
MemoryO(∥S∥∥A∥)O(\|S\|\|A\|)O(∥S∥∥A∥)O(\|S\|\|A\|)
ConvergenceAsymptoticExact in finite time

Rule of thumb: PI often converges in surprisingly few iterations (sometimes 5-10) but each iteration is expensive. VI iterations are cheap but you may need many.


Lecture 6: Messing with Rewards

This lecture explores how we can modify reward functions while preserving optimal behavior—and why this matters for learning efficiency.


Why Modify Reward Functions?

The reward function is like a programming language for specifying desired behavior:

  • Different "programs" (reward functions) can specify the same behavior
  • Some are easier to learn from than others
  • Some are easier to represent or reason about

Goals of reward modification:

  1. Make learning faster (fewer samples needed)
  2. Make computation cheaper (less planning required)
  3. Make representation simpler
  4. Guide exploration more effectively

Reward Function Transformations

Transformation 1: Multiply by Positive Constant

Claim: If R′(s,a)=c⋅R(s,a)R'(s,a) = c \cdot R(s,a) for c>0c > 0, then Q′(s,a)=c⋅Q(s,a)Q'(s,a) = c \cdot Q(s,a)

Proof: 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') =c⋅R(s,a)+γ∑s′T(s,a,s′)max⁡a′c⋅Q(s′,a′)= c \cdot R(s,a) + \gamma \sum_{s'} T(s,a,s') \max_{a'} c \cdot Q(s',a')

Since c>0c > 0, we can factor it out of the max: =c[R(s,a)+γ∑s′T(s,a,s′)max⁡a′Q(s′,a′)]=c⋅Q(s,a)= c \left[ R(s,a) + \gamma \sum_{s'} T(s,a,s') \max_{a'} Q(s',a') \right] = c \cdot Q(s,a)

Why cc must be positive: If c<0c < 0, the max becomes min (flipping reward and punishment). If c=0c = 0, all information is lost.

Optimal policy preserved: Since we multiply all Q-values by the same positive constant, the ordering (and thus the argmax) is unchanged.

Transformation 2: Add a Constant

Claim: If R′(s,a)=R(s,a)+cR'(s,a) = R(s,a) + c, then Q′(s,a)=Q(s,a)+c1−γQ'(s,a) = Q(s,a) + \frac{c}{1-\gamma}

Intuition: Adding cc to every reward adds cc at every step. The sum of cc over an infinite discounted horizon is: c+γc+γ2c+...=c1−γc + \gamma c + \gamma^2 c + ... = \frac{c}{1-\gamma}

Proof: Substitute Q′(s,a)=Q(s,a)+c1−γQ'(s,a) = Q(s,a) + \frac{c}{1-\gamma} and R′=R+cR' = R + c into Bellman:

Q(s,a)+c1−γ=R(s,a)+c+γ∑s′T(s,a,s′)max⁡a′[Q(s′,a′)+c1−γ]Q(s,a) + \frac{c}{1-\gamma} = R(s,a) + c + \gamma \sum_{s'} T(s,a,s') \max_{a'} \left[Q(s',a') + \frac{c}{1-\gamma}\right]

The constant c1−γ\frac{c}{1-\gamma} doesn't affect the max (doesn't depend on a′a'): =R(s,a)+c+γ∑s′T(s,a,s′)max⁡a′Q(s′,a′)+γc1−γ= R(s,a) + c + \gamma \sum_{s'} T(s,a,s') \max_{a'} Q(s',a') + \gamma \frac{c}{1-\gamma}

Simplify (using ∑s′T(s,a,s′)=1\sum_{s'} T(s,a,s') = 1): =R(s,a)+γ∑s′T(s,a,s′)max⁡a′Q(s′,a′)+c+γc1−γ= R(s,a) + \gamma \sum_{s'} T(s,a,s') \max_{a'} Q(s',a') + c + \frac{\gamma c}{1-\gamma} =Q(s,a)+c+γc1−γ⋅(1−γ)/(1−γ)= Q(s,a) + \frac{c + \gamma c}{1-\gamma} \cdot (1-\gamma)/(1-\gamma) =Q(s,a)+c(1−γ)+γc1−γ=Q(s,a)+c1−γ= Q(s,a) + \frac{c(1-\gamma) + \gamma c}{1-\gamma} = Q(s,a) + \frac{c}{1-\gamma}

Optimal policy preserved: Adding the same constant to all Q-values doesn't change the argmax.


Potential-Based Reward Shaping

The Problem with Naive Shaping

Example - Robot Soccer:

  • True reward: +100 for scoring a goal
  • Naive shaping: +10 for touching the ball

Problem: The robot might learn to "shiver" against the ball, repeatedly touching it to accumulate +10 rewards, never actually scoring!

This creates a suboptimal positive feedback loop—you can gain infinite reward without achieving the true objective.

The Solution: Potential Functions

Key insight: Design shaping rewards so they telescope (cancel out over trajectories).

Definition: A potential function Φ:S→R\Phi: S \rightarrow \mathbb{R} assigns a "potential value" to each state.

Potential-based shaping reward: F(s,a,s′)=γΦ(s′)−Φ(s)F(s, a, s') = \gamma \Phi(s') - \Phi(s)

New reward function: R′(s,a,s′)=R(s,a,s′)+γΦ(s′)−Φ(s)R'(s, a, s') = R(s, a, s') + \gamma \Phi(s') - \Phi(s)

Interpretation:

  • You get γΦ(s′)\gamma\Phi(s') for entering state s′s'
  • You lose Φ(s)\Phi(s) for leaving state ss
  • Net effect over a trajectory: only endpoints matter!

Why Potential-Based Shaping Preserves Optimal Policy

Theorem (Ng, Harada, Russell 1999): If shaping rewards have the form F(s,a,s′)=γΦ(s′)−Φ(s)F(s,a,s') = \gamma\Phi(s') - \Phi(s), then: Q′(s,a)=Q(s,a)−Φ(s)Q'(s,a) = Q(s,a) - \Phi(s)

Proof: Consider a trajectory: s0→s1→s2→...s_0 \to s_1 \to s_2 \to ...

Shaping rewards along the trajectory:

  • Step 0: γΦ(s1)−Φ(s0)\gamma\Phi(s_1) - \Phi(s_0)
  • Step 1: γ[γΦ(s2)−Φ(s1)]\gamma[\gamma\Phi(s_2) - \Phi(s_1)] (discounted)
  • Step 2: γ2[γΦ(s3)−Φ(s2)]\gamma^2[\gamma\Phi(s_3) - \Phi(s_2)]
  • ...

Sum them up (this is a telescoping sum): −Φ(s0)+γΦ(s1)−γΦ(s1)+γ2Φ(s2)−γ2Φ(s2)+...-\Phi(s_0) + \gamma\Phi(s_1) - \gamma\Phi(s_1) + \gamma^2\Phi(s_2) - \gamma^2\Phi(s_2) + ... =−Φ(s0)+lim⁡t→∞γtΦ(st)= -\Phi(s_0) + \lim_{t\to\infty} \gamma^t \Phi(s_t)

Since γ<1\gamma < 1 and Φ\Phi is bounded: lim⁡t→∞γtΦ(st)=0\lim_{t\to\infty} \gamma^t \Phi(s_t) = 0

Total shaping reward = −Φ(s0)-\Phi(s_0)

Therefore: Q′(s,a)=Q(s,a)−Φ(s)Q'(s,a) = Q(s,a) - \Phi(s)

Why optimal policy is preserved: The shift −Φ(s)-\Phi(s) depends only on the current state, not on the action. So the argmax over actions is unchanged!

Designing Good Potential Functions

Robot Soccer Example: Φ(s)=1drobot,ball+2dball,goal\Phi(s) = \frac{1}{d_{robot,ball}} + \frac{2}{d_{ball,goal}}

  • Higher potential when robot is closer to ball
  • Higher potential when ball is closer to goal
  • The factor of 2 makes ball-to-goal more important than robot-to-ball

The shaping reward:

  • Moving toward the ball: positive shaping reward
  • Ball moving toward goal: positive shaping reward
  • Moving away: negative shaping reward (you "pay back" what you gained)

No more shivering: Repeatedly touching and releasing the ball gives net zero shaping reward!

Potential Shaping and Q-Learning

Key result: Running Q-learning with potential-based shaping is equivalent to running Q-learning with a different initialization.

Specifically: Q-learning with shaping function Φ\Phi and Q0=0Q_0 = 0 produces the same sequence of policies as Q-learning without shaping but with Q0=−ΦQ_0 = -\Phi.

Implication:

  • Good potential function ≈ good initialization
  • Random initialization ≈ asserting a random (probably bad) potential
  • Inject knowledge, not noise!

Magic Potential: The Oracle Case

What if Φ(s)=V∗(s)\Phi(s) = V^*(s) (the optimal value function)?

Then: Q′(s,a)=Q∗(s,a)−V∗(s)=Q∗(s,a)−max⁡a′Q∗(s,a′)Q'(s,a) = Q^*(s,a) - V^*(s) = Q^*(s,a) - \max_{a'} Q^*(s,a')

Result:

  • Q′(s,a∗)=0Q'(s, a^*) = 0 for optimal action a∗a^*
  • Q′(s,a)<0Q'(s, a) < 0 for suboptimal actions

With Q0=0Q_0 = 0, the agent immediately behaves optimally and only needs to verify that suboptimal actions are indeed suboptimal!

Of course: If we knew V∗V^*, we wouldn't need to learn. But this shows the theoretical power of good shaping.


Lecture 7: Exploring Exploration

Exploration is the distinguishing feature of RL compared to other ML paradigms. This lecture develops the theory of efficient exploration.


K-Armed Bandits

The Setup

  • KK slot machines (arms), each with unknown payoff probability pip_i
  • At each time step, choose one arm to pull
  • Receive stochastic reward: 1 with probability pip_i, 0 otherwise
  • Goal: Maximize total reward (or identify the best arm)

Key insight: This is RL without state transitions—pure exploration/exploitation tradeoff.

The Exploration-Exploitation Dilemma

Exploration: Try different arms to learn their payoffs Exploitation: Pull the arm you believe is best to maximize reward

StrategyProblem
Always exploit (greedy)May lock onto suboptimal arm with 70% probability
Always explore (round-robin)Never uses learned information
Maximum likelihoodGets stuck if best-looking arm isn't actually best
Maximum confidenceJust shuffles arms without preference
Minimum confidenceExplores everything but never exploits

Example: After pulling arm A once (0 payoff) and arm B twice (1 payoff):

  • B looks better: p^B=0.5>p^A=0\hat{p}_B = 0.5 > \hat{p}_A = 0
  • But B is actually better only ~70% of the time!
  • We need to balance learning more vs. using what we know

Metrics for Bandit Algorithms

Metric 1: Identify Optimal Arm in the Limit

Problem: Round-robin achieves this but never exploits.

Metric 2: Maximize Discounted Reward

Optimal solution exists: Gittins Index

What is the Gittins Index? For each arm, compute a value based on (successes, trials) that captures both exploitation value and exploration value. Always pull the arm with highest index.

Intuition: The index equals "what guaranteed payoff would make you indifferent between that and this uncertain arm?"

Warning: Gittins Index is beautiful for bandits but does NOT generalize to MDPs. Many have tried; all have failed.

Metric 3: Maximize Finite Horizon Reward

Computable but expensive (exponential in horizon).

Metric 4: PAC-Style (proximally approximately correct) - Find Near-Optimal Arm

With probability ≥1−δ\geq 1-\delta, identify an ϵ\epsilon-optimal arm within poly(K,1/ϵ,1/δ)\text{poly}(K, 1/\epsilon, 1/\delta) pulls.

Metric 5: PAC-Style - Get Near-Optimal Reward

With probability ≥1−δ\geq 1-\delta, achieve per-step reward within ϵ\epsilon of optimal after poly(K,1/ϵ,1/δ)\text{poly}(K, 1/\epsilon, 1/\delta) steps.

Metric 6: Mistake Bound

Total number of suboptimal arm pulls is bounded by poly(K,1/ϵ,1/δ)\text{poly}(K, 1/\epsilon, 1/\delta).

Key result: Metrics 4, 5, and 6 are equivalent! An algorithm for one gives algorithms for the others.


The Core Problem

You have a slot machine (bandit arm) with unknown win probability pp. You pull it nn times and win kk times. Your estimate is p^=k/n\hat{p} = k/n.

Question: How close is p^\hat{p} to the true pp?

You can never be certain — maybe you got lucky or unlucky. But you can make probabilistic guarantees.


The Two Parameters

ParameterMeaningExample
ϵ\epsilonAccuracy: how close is your estimate?"within 0.05 of truth"
δ\deltaFailure probability: how often can you be wrong?"wrong at most 5% of the time"

The guarantee you want: P(∣p^−p∣>ϵ)≤δP\left( |\hat{p} - p| > \epsilon \right) \leq \delta

"The probability that my estimate is off by more than ϵ\epsilon is at most δ\delta."

Equivalently: "With probability ≥1−δ\geq 1-\delta, my estimate is within ϵ\epsilon of truth."


Hoeffding Bound

This tells you how nn, ϵ\epsilon, and δ\delta relate.

For nn i.i.d. samples from a distribution on [0,1][0,1] with true mean μ\mu:

P(∣μ^−μ∣>ϵ)≤2e−2nϵ2P\left( |\hat{\mu} - \mu| > \epsilon \right) \leq 2e^{-2n\epsilon^2}

The RHS is our δ\delta. So:

δ=2e−2nϵ2\delta = 2e^{-2n\epsilon^2}

This lets you solve for any variable given the other two:

Given nn and ϵ\epsilon, what's δ\delta? δ=2e−2nϵ2\delta = 2e^{-2n\epsilon^2}

Given ϵ\epsilon and δ\delta, how many samples nn? n=ln⁡(2/δ)2ϵ2n = \frac{\ln(2/\delta)}{2\epsilon^2}

Given nn and δ\delta, what accuracy ϵ\epsilon? ϵ=ln⁡(2/δ)2n\epsilon = \sqrt{\frac{\ln(2/\delta)}{2n}}

Concrete Example

You pull an arm n=100n = 100 times, win 30 times. So p^=0.3\hat{p} = 0.3.

How confident are you that p∈[0.25,0.35]p \in [0.25, 0.35]? (i.e., ϵ=0.05\epsilon = 0.05)

δ=2e−2(100)(0.05)2=2e−0.5≈1.21\delta = 2e^{-2(100)(0.05)^2} = 2e^{-0.5} \approx 1.21

That's bigger than 1, so the bound is useless here (probability can't exceed 1).

What about p∈[0.2,0.4]p \in [0.2, 0.4]? (i.e., ϵ=0.1\epsilon = 0.1)

δ=2e−2(100)(0.1)2=2e−2≈0.27\delta = 2e^{-2(100)(0.1)^2} = 2e^{-2} \approx 0.27

So with ~73% confidence, the true pp is in [0.2,0.4][0.2, 0.4].

What about n=500n = 500 samples with ϵ=0.05\epsilon = 0.05?

δ=2e−2(500)(0.05)2=2e−2.5≈0.16\delta = 2e^{-2(500)(0.05)^2} = 2e^{-2.5} \approx 0.16

~84% confidence that p∈[0.25,0.35]p \in [0.25, 0.35].

Key Intuitions

  1. More samples → tighter bounds (δ\delta decreases exponentially in nn)
  2. Tighter accuracy is expensive (nn scales as 1/ϵ21/\epsilon^2 — halving ϵ\epsilon requires 4× more samples)
  3. Higher confidence is cheap (nn scales as log⁡(1/δ)\log(1/\delta) — going from 90% to 99% confidence doesn't cost much)

Union Bound

Now suppose you have KK arms, and you want all estimates to be accurate.

  • Arm 1 estimate is ϵ\epsilon-accurate with probability ≥1−δ1\geq 1-\delta_1
  • Arm 2 estimate is ϵ\epsilon-accurate with probability ≥1−δ2\geq 1-\delta_2
  • ...
  • Arm K estimate is ϵ\epsilon-accurate with probability ≥1−δK\geq 1-\delta_K

What's the probability that ALL are accurate?

Naive Attempt (Wrong!)

You might think: (1−δ1)(1−δ2)...(1−δK)(1-\delta_1)(1-\delta_2)...(1-\delta_K)

But this assumes independence, which may not hold!

Union Bound (Always Works)

P(at least one fails)≤P(arm 1 fails)+P(arm 2 fails)+...+P(arm K fails)P(\text{at least one fails}) \leq P(\text{arm 1 fails}) + P(\text{arm 2 fails}) + ... + P(\text{arm K fails})

P(any failure)≤δ1+δ2+...+δKP(\text{any failure}) \leq \delta_1 + \delta_2 + ... + \delta_K

Why? Think Venn diagram — the "any failure" region is contained in the union of individual failure regions. The union's size is at most the sum of individual sizes.

Application

You want overall failure probability ≤δ\leq \delta. If you set each arm's failure probability to δ/K\delta/K:

P(any failure)≤K⋅δK=δP(\text{any failure}) \leq K \cdot \frac{\delta}{K} = \delta

So: to get overall confidence 1−δ1-\delta across KK arms, each arm needs confidence 1−δ/K1 - \delta/K.


Putting It Together: PAC Bandits

Goal: Find the best arm (within ϵ\epsilon) with probability ≥1−δ\geq 1-\delta.

Strategy

  1. Pull each arm CC times
  2. Pick the arm with highest sample mean

Step 1: For the best arm to win, we need all estimates within ϵ/2\epsilon/2 of truth.

(Why ϵ/2\epsilon/2? Worst case: best arm's estimate is ϵ/2\epsilon/2 too low, second-best is ϵ/2\epsilon/2 too high. They could swap. But if true gap is >ϵ> \epsilon, we're still okay.)

Step 2: Apply union bound — need each arm at confidence 1−δ/K1 - \delta/K.

Step 3: Apply Hoeffding — how many samples per arm?

C=ln⁡(2K/δ)2(ϵ/2)2=2ln⁡(2K/δ)ϵ2C = \frac{\ln(2K/\delta)}{2(\epsilon/2)^2} = \frac{2\ln(2K/\delta)}{\epsilon^2}

Total samples: KC=2Kln⁡(2K/δ)ϵ2=O(Kϵ2log⁡Kδ)KC = \frac{2K\ln(2K/\delta)}{\epsilon^2} = O\left(\frac{K}{\epsilon^2}\log\frac{K}{\delta}\right)

Interpretation

FactorMeaning
KKMore arms → more samples (linear)
1/ϵ21/\epsilon^2Tighter accuracy → many more samples (quadratic)
log⁡(K/δ)\log(K/\delta)More arms or higher confidence → slightly more samples (logarithmic)

Summary

ConceptWhat it does
HoeffdingRelates samples (nn), accuracy (ϵ\epsilon), confidence (1−δ1-\delta) for ONE estimate
Union BoundLets you combine guarantees across MULTIPLE estimates
TogetherLets you say "with KK arms and nn samples each, I find an ϵ\epsilon-optimal arm with probability ≥1−δ\geq 1-\delta"

The ϵ\epsilon-δ\delta framework is the language of PAC (Probably Approximately Correct) learning — you get approximate answers with high probability, and you can quantify exactly how approximate and how probable.

Key observations:

  • Dependence on ϵ\epsilon: Quadratic (1/ϵ21/\epsilon^2)—being very precise is expensive!
  • Dependence on δ\delta: Logarithmic—being very confident is cheap
  • Dependence on KK: Linear—more arms = more samples

Deterministic MDPs and Rmax

The Challenge

In MDPs, unlike bandits:

  • Actions affect future states
  • Random exploration can get you stuck
  • You can't teleport to unexplored regions

Example - Chain MDP: Need to take the "right" action nn times in a row to reach a high-reward state. Random exploration has probability 2−n2^{-n} of success!

The Rmax Algorithm

Key insight: Be optimistic about the unknown!

Algorithm:

  1. Maintain current knowledge of MDP (transitions and rewards seen so far)
  2. For any unknown state-action pair: assume it leads to a self-loop with reward RmaxR_{max} (the maximum possible reward)
  3. Solve this "optimistic MDP"
  4. Execute the optimal policy
  5. When you visit unknown state-action pairs, update knowledge and return to step 2

Why it works:

Case 1: The optimistic assumption is correct (or close enough)

  • Then we're getting good reward!

Case 2: The optimistic assumption is wrong

  • Then we'll visit the "unknown" state-action pair
  • We learn something new
  • We can only be wrong ∣S∣×∣A∣|S| \times |A| times (finite!)

The "Learn or Earn" Lemma

Theorem: At any time, either:

  1. We're achieving near-optimal reward, OR
  2. We'll reach an unknown state-action pair within polynomially many steps

Implication: We can't be stuck doing poorly without learning. Either we're doing well or we're about to learn something that helps us do better.

Analysis of Rmax

Mistake bound: The number of ϵ\epsilon-suboptimal actions is: O(∣S∣2∣A∣ϵ3⋅poly(11−γ)⋅ln⁡1δ)O\left( \frac{|S|^2 |A|}{\epsilon^3} \cdot \text{poly}\left(\frac{1}{1-\gamma}\right) \cdot \ln\frac{1}{\delta} \right)

Key property: Polynomial in all relevant quantities!


General Stochastic MDPs

The Challenge

Now we have BOTH:

  • Sequential decision making (from deterministic MDPs)
  • Stochastic outcomes (from bandits)

Combining the Ideas

Rmax for stochastic MDPs:

  1. Known vs Unknown: A state-action pair is "known" if we've visited it CC times (where CC is determined by Hoeffding bounds)

  2. Estimate transitions: After CC visits, our transition probability estimates are accurate enough

  3. Optimistic about unknown: Unknown state-action pairs are assumed to lead to the "Rmax state" with probability 1

  4. Solve and execute: Solve the optimistic MDP, execute the policy

The Parameter C

How many times must we visit each state-action pair?

Requirements:

  • Transition probability estimates must be ϵ\epsilon-accurate
  • Must hold for all ∣S∣×∣A∣|S| \times |A| pairs simultaneously
  • Must hold with overall probability ≥1−δ\geq 1-\delta

Result: C=O(1ϵ2ln⁡∣S∣∣A∣δ)C = O\left( \frac{1}{\epsilon^2} \ln\frac{|S||A|}{\delta} \right)

PAC-MDP Guarantee

Theorem: Rmax is PAC-MDP efficient:

With probability ≥1−δ\geq 1-\delta, the total number of ϵ\epsilon-suboptimal actions is polynomial in ∣S∣|S|, ∣A∣|A|, 1/ϵ1/\epsilon, 1/δ1/\delta, and 1/(1−γ)1/(1-\gamma).

The magic: We're either:

  1. Getting near-optimal reward (good!)
  2. Learning something new that will help us get near-optimal reward (also good!)

There's no "dark middle" where we're stuck being bad without learning.

Practical Considerations

Theory vs Practice:

  • Theoretical CC values are often very large
  • In practice, much smaller values work
  • Rmax is actually a very effective algorithm!

Why it works well:

  • Makes good use of all data
  • Naturally balances exploration/exploitation
  • Optimism provides principled guidance

Key Equations Summary

Bellman Equations

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')

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

Contraction Mapping

∥BV1−BV2∥∞≤γ∥V1−V2∥∞\|BV_1 - BV_2\|_\infty \leq \gamma \|V_1 - V_2\|_\infty

Value Iteration Stopping Criterion

If ∥Vt+1−Vt∥∞<ϵ\|V_{t+1} - V_t\|_\infty < \epsilon, then: ∥V∗−Vπt∥∞≤2ϵγ1−γ\|V^* - V^{\pi_t}\|_\infty \leq \frac{2\epsilon\gamma}{1-\gamma}

Reward Transformations

Scaling: R′=cR⇒Q′=cQR' = cR \Rightarrow Q' = cQ

Shifting: R′=R+c⇒Q′=Q+c1−γR' = R + c \Rightarrow Q' = Q + \frac{c}{1-\gamma}

Potential Shaping: R′(s,a,s′)=R(s,a,s′)+γΦ(s′)−Φ(s)⇒Q′(s,a)=Q(s,a)−Φ(s)R'(s,a,s') = R(s,a,s') + \gamma\Phi(s') - \Phi(s) \Rightarrow Q'(s,a) = Q(s,a) - \Phi(s)

Hoeffding Bound

P(∣μ^−μ∣>ϵ)≤2e−2nϵ2P\left( |\hat{\mu} - \mu| > \epsilon \right) \leq 2e^{-2n\epsilon^2}

Sample Complexity (Bandits)

C=O(1ϵ2ln⁡Kδ)pulls per armC = O\left( \frac{1}{\epsilon^2} \ln\frac{K}{\delta} \right) \text{pulls per arm}

Effective Horizon

Heff≈11−γH_{eff} \approx \frac{1}{1-\gamma}