📝 Reinforcement Learning — Quick Notes
1. Key Definitions
| Term | Definition |
|---|---|
| MDP | Tuple (S, A, P, R, γ) — States, Actions, Transition probability P(s′|s,a), Reward function R(s,a,s′), Discount factor γ ∈ [0,1) |
| Policy π | Mapping from states to actions. Deterministic: π(s) = a. Stochastic: π(a|s) = P(At=a | St=s) |
| Return Gt | Gt = Rt+1 + γRt+2 + γ²Rt+3 + … = ∑k=0∞ γk Rt+k+1 |
| State-Value Vπ(s) | Expected return starting from s, following π: Vπ(s) = Eπ[Gt | St=s] |
| Action-Value Qπ(s,a) | Expected return starting from s, taking a, then following π: Qπ(s,a) = Eπ[Gt | St=s, At=a] |
| Optimal V*(s) | V*(s) = maxπ Vπ(s) for all s |
| Optimal Q*(s,a) | Q*(s,a) = maxπ Qπ(s,a) for all s, a |
| Markov Property | P(St+1|St) = P(St+1|S1,…,St) — future depends only on current state |
2. All Bellman Equations
Bellman Expectation Equations (for policy π)
Vπ(s) = ∑a π(a|s) ∑s′ P(s′|s,a) [R(s,a,s′) + γ Vπ(s′)]
Qπ(s,a) = ∑s′ P(s′|s,a) [R(s,a,s′) + γ ∑a′ π(a′|s′) Qπ(s′,a′)]
V–Q link: Vπ(s) = ∑a π(a|s) Qπ(s,a)
Q–V link: Qπ(s,a) = ∑s′ P(s′|s,a) [R(s,a,s′) + γ Vπ(s′)]
Bellman Optimality Equations
V*(s) = maxa ∑s′ P(s′|s,a) [R(s,a,s′) + γ V*(s′)]
Q*(s,a) = ∑s′ P(s′|s,a) [R(s,a,s′) + γ maxa′ Q*(s′,a′)]
V*–Q* link: V*(s) = maxa Q*(s,a)
π*(s) = argmaxa Q*(s,a)
3. Algorithm Comparison Table
| Algorithm | Type | Model? | On/Off Policy | Update Rule | Key Feature |
|---|---|---|---|---|---|
| Value Iteration | DP | Yes | N/A | V(s) ← maxa ∑ P[R + γV(s′)] | Combines eval + improve in one step |
| Policy Iteration | DP | Yes | N/A | Eval: solve Vπ; Improve: π ← greedy(V) | Exact evaluation, fewer iterations |
| TD(0) | TD | No | On-policy | V(s) ← V(s) + α[r + γV(s′) − V(s)] | Bootstrap, step-by-step update |
| SARSA | TD | No | On-policy | Q(s,a) ← Q(s,a) + α[r + γQ(s′,a′) − Q(s,a)] | Uses actual next action a′ |
| Q-Learning | TD | No | Off-policy | Q(s,a) ← Q(s,a) + α[r + γ maxa′ Q(s′,a′) − Q(s,a)] | Uses max over next actions |
| DQN | Deep | No | Off-policy | Minimize (y − Q(s,a;θ))² with replay | Neural net, experience replay, target net |
4. Model-Based vs Model-Free
| Aspect | Model-Based | Model-Free |
|---|---|---|
| Needs P(s′|s,a)? | Yes | No |
| Needs R(s,a,s′)? | Yes | No |
| Examples | Value Iteration, Policy Iteration | MC, TD(0), SARSA, Q-Learning, DQN |
| Sample Efficiency | Higher (uses model to plan) | Lower (learns from experience only) |
| Applicability | When model is known or learnable | When model is unknown or complex |
| Computation | Can be done offline (sweeps) | Requires interaction with environment |
5. On-Policy vs Off-Policy
| Aspect | On-Policy | Off-Policy |
|---|---|---|
| Definition | Evaluates/improves the same policy used to generate data | Evaluates/improves a different (target) policy from the one generating data (behaviour policy) |
| Examples | SARSA, A2C, REINFORCE | Q-Learning, DQN |
| Exploration | Must balance explore/exploit in the learning policy | Can learn optimal policy while exploring with a different policy |
| Convergence | Learns value of the ε-greedy policy (safe but suboptimal) | Learns value of the optimal policy directly |
| Data Reuse | Data from old policy is stale | Can reuse data (experience replay) |
6. Key Formulas & Update Rules
TD Error
δt = Rt+1 + γ V(St+1) − V(St)
TD(0) Update
V(St) ← V(St) + α δt
SARSA Update
Q(St,At) ← Q(St,At) + α [Rt+1 + γ Q(St+1,At+1) − Q(St,At)]
Q-Learning Update
Q(St,At) ← Q(St,At) + α [Rt+1 + γ maxa Q(St+1,a) − Q(St,At)]
Monte Carlo Update
V(St) ← V(St) + α [Gt − V(St)]
ε-Greedy Policy
a = argmaxa Q(s,a) with probability 1−ε, random action with probability ε
Value Iteration
Vk+1(s) = maxa ∑s′ P(s′|s,a) [R(s,a,s′) + γ Vk(s′)]
Policy Gradient (REINFORCE)
θ ← θ + α ∇θ log π(a|s;θ) · Gt
Q-Learning Convergence Conditions
∑ αt = ∞ and ∑ αt² < ∞ (e.g., αt = 1/t), plus all (s,a) pairs visited infinitely often.
7. Common GATE Question Patterns
- Compute V(s) or Q(s,a): Given an MDP (small grid, 2–3 states), apply Bellman equations iteratively. Expect 1–2 iterations of value iteration.
- Identify optimal policy: Given V* or Q* values, extract π*(s) = argmaxa Q*(s,a).
- One-step TD/Q-learning update: Given current Q-values, (s,a,r,s′), α, γ — compute the new Q-value. This is a very common numerical question.
- SARSA vs Q-learning: Explain why they differ (on-policy vs off-policy) or compute different updates for the same transition.
- Discount factor effect: What happens to V(s) as γ → 0 or γ → 1?
- Model-free vs model-based: Classify algorithms. Which ones need transition probabilities?
- MDP formulation: Given a word problem, define S, A, P, R, γ.
- Convergence: Under what conditions does Q-learning converge? (Robbins-Monro conditions on α)
8. Tips & Common Mistakes
⚠ Common Mistakes
- Confusing V and Q: V(s) is over states only; Q(s,a) is over state-action pairs. V*(s) = maxa Q*(s,a).
- Wrong subscript in returns: Gt starts with Rt+1, NOT Rt.
- SARSA vs Q-Learning target: SARSA uses Q(s′,a′) where a′ is the actual next action. Q-Learning uses maxa′ Q(s′,a′).
- Forgetting γ in updates: The discount factor multiplies the next-state value, not the reward.
- Terminal states: V(sterminal) = 0 always. Don’t bootstrap from terminal states.
- Policy iteration ≠ value iteration: PI does full evaluation then improves; VI does one sweep of Bellman optimality.
💡 Quick Tips
- For numerical GATE problems, write out the full update equation with numbers before simplifying.
- Draw the state transition diagram for small MDPs — it makes Bellman equations much clearer.
- γ = 0 means the agent is completely myopic (only immediate reward matters).
- γ close to 1 means the agent is far-sighted (future rewards are almost as important as immediate).
- In a deterministic MDP, the ∑s′ P(s′|s,a) collapses to a single successor state, simplifying all equations.
- Q-learning is off-policy because it updates toward maxa′ (greedy) regardless of the action actually taken.