Level 4 — ApplicationDeep & Advanced RL

Deep & Advanced RL

60 minutes60 marksprintable — key stays hidden on paper

Level 4 (Application: novel/unseen problems) Time limit: 60 minutes Total marks: 60

Answer all questions. Show all working. Calculators permitted. Assume all logarithms are natural unless stated.


Question 1 — DQN Targets & Double DQN (12 marks)

An agent uses a Deep Q-Network with discount factor γ=0.9\gamma = 0.9. For a sampled transition (s,a,r,s)(s, a, r, s') with reward r=2r = 2 and ss' non-terminal, the online network and target network give the following action-values at ss' (three actions a0,a1,a2a_0, a_1, a_2):

Network Q(s,a0)Q(s',a_0) Q(s,a1)Q(s',a_1) Q(s,a2)Q(s',a_2)
Online QθQ_\theta 5.0 8.0 3.0
Target QθQ_{\theta^-} 6.0 4.0 7.0

(a) Compute the standard DQN TD target yDQNy_{\text{DQN}}. (3) (b) Compute the Double DQN TD target yDDQNy_{\text{DDQN}}. (4) (c) Explain precisely which estimation problem Double DQN mitigates, and using the numbers above argue why yDDQN<yDQNy_{\text{DDQN}} < y_{\text{DQN}} here. (5)


Question 2 — REINFORCE with Baseline (14 marks)

A single-step (one-action) episodic task uses a softmax policy over two actions with parameter vector θ=(θ0,θ1)\theta=(\theta_0,\theta_1) and logits equal to θ0,θ1\theta_0, \theta_1. Currently θ0=0\theta_0 = 0, θ1=ln3\theta_1 = \ln 3 (so θ11.0986\theta_1 \approx 1.0986).

(a) Compute the policy probabilities π(a0)\pi(a_0) and π(a1)\pi(a_1). (3) (b) The agent samples a1a_1 and receives return G=1G = 1. Using a learned baseline b=0.5b = 0.5, and learning rate α=0.1\alpha = 0.1, write the REINFORCE-with-baseline gradient update and compute the new θ0,θ1\theta_0, \theta_1. Use the softmax gradient θlogπ(a)=eaπ\nabla_\theta \log\pi(a) = \mathbf{e}_a - \pi, where ea\mathbf{e}_a is the one-hot of the taken action. (7) (c) State the purpose of the baseline and prove that subtracting a state-dependent (action-independent) baseline leaves the policy-gradient estimator unbiased. (4)


Question 3 — PPO Clipped Objective (12 marks)

PPO uses the clipped surrogate objective for a single sample: L(θ)=min ⁣(ρtA^t, clip(ρt,1ϵ,1+ϵ)A^t),ρt=πθ(atst)πθold(atst)L(\theta) = \min\!\Big(\rho_t \hat{A}_t,\ \text{clip}(\rho_t, 1-\epsilon, 1+\epsilon)\,\hat{A}_t\Big),\quad \rho_t = \frac{\pi_\theta(a_t|s_t)}{\pi_{\theta_{\text{old}}}(a_t|s_t)} with ϵ=0.2\epsilon = 0.2.

(a) For A^t=+3\hat{A}_t = +3 and ρt=1.5\rho_t = 1.5, evaluate L(θ)L(\theta). (3) (b) For A^t=2\hat{A}_t = -2 and ρt=1.5\rho_t = 1.5, evaluate L(θ)L(\theta). (3) (c) For a positive advantage, once ρt>1+ϵ\rho_t > 1+\epsilon, what is L/ρt\partial L/\partial\rho_t, and what does this imply about the gradient signal? Contrast with a vanilla (unclipped) importance-weighted objective. (6)


Question 4 — Actor-Critic Advantage & TD (10 marks)

An A2C agent observes a trajectory fragment s0s1s2s_0 \to s_1 \to s_2 with rewards r1=1r_1 = 1 (from s0s_0), r2=0r_2 = 0 (from s1s_1), and γ=0.8\gamma = 0.8. The critic VV estimates V(s0)=2.0V(s_0)=2.0, V(s1)=3.0V(s_1)=3.0, V(s2)=1.5V(s_2)=1.5.

(a) Compute the one-step TD advantage A(s0,a0)=r1+γV(s1)V(s0)A(s_0,a_0) = r_1 + \gamma V(s_1) - V(s_0). (3) (b) Compute the 2-step advantage estimate A(2)=r1+γr2+γ2V(s2)V(s0)A^{(2)} = r_1 + \gamma r_2 + \gamma^2 V(s_2) - V(s_0). (3) (c) Using GAE with λ=0.5\lambda = 0.5, γ=0.8\gamma = 0.8, compute A^0GAE\hat{A}^{\text{GAE}}_{0} from the two TD errors δ0\delta_0 (at s0s_0) and δ1\delta_1 (at s1s_1), where δ1=r2+γV(s2)V(s1)\delta_1 = r_2 + \gamma V(s_2) - V(s_1). (4)


Question 5 — Reward Shaping & Design (12 marks)

A robot navigates a sparse-reward gridworld: reward +1+1 only at the goal, 00 elsewhere. A designer adds a shaping reward.

(a) State the potential-based reward shaping form F(s,s)=γΦ(s)Φ(s)F(s,s') = \gamma\Phi(s') - \Phi(s) and the key theoretical guarantee it provides. (4) (b) A colleague instead adds +0.1+0.1 every time the robot moves closer to the goal (measured by Euclidean distance), regardless of a potential function. Describe one concrete failure mode (reward hacking) this can produce. (4) (c) Suppose Φ(s)=d(s)\Phi(s) = -d(s) where d(s)d(s) is grid distance to goal, and γ=1\gamma=1. For a step from a cell with d=5d=5 to a cell with d=4d=4, compute FF. Then explain why potential-based shaping does not change the optimal policy. (4)

Answer keyMark scheme & solutions

Question 1 (12 marks)

(a) Standard DQN: uses the target network for both action selection and evaluation. yDQN=r+γmaxaQθ(s,a)=2+0.9×max(6.0,4.0,7.0)=2+0.9×7.0=8.3y_{\text{DQN}} = r + \gamma \max_{a'} Q_{\theta^-}(s',a') = 2 + 0.9 \times \max(6.0,4.0,7.0) = 2 + 0.9\times 7.0 = 8.3

  • Correct max of target net (7.0): 1
  • Correct discount+reward assembly: 1
  • Answer 8.38.3: 1

(b) Double DQN: online net selects the argmax action, target net evaluates it.

  • Online argmax at ss': a1a_1 (value 8.0 is largest). (2)
  • Evaluate with target: Qθ(s,a1)=4.0Q_{\theta^-}(s',a_1) = 4.0. (1) yDDQN=2+0.9×4.0=5.6y_{\text{DDQN}} = 2 + 0.9\times 4.0 = 5.6 (1)

(c) (5 marks)

  • Double DQN mitigates maximization bias / overestimation of Q-values (2). The single max\max operator in standard DQN couples selection and evaluation, so noise/errors are systematically over-selected: E[max]maxE\mathbb{E}[\max] \ge \max \mathbb{E} (2).
  • Here the online net picks a1a_1 (its optimistic choice), but the target net values a1a_1 only at 4.0, whereas the standard target greedily grabs the target net's own max (7.0). Decoupling yields the smaller, less optimistic target 5.6<8.35.6 < 8.3 (1).

Question 2 (14 marks)

(a) Softmax over logits (0,ln3)(0, \ln 3): π(a0)=e0e0+eln3=11+3=0.25,π(a1)=34=0.75\pi(a_0) = \frac{e^0}{e^0+e^{\ln 3}} = \frac{1}{1+3} = 0.25,\qquad \pi(a_1) = \frac{3}{4} = 0.75

  • Setup: 1, each probability: 1+1

(b) Update rule (REINFORCE-with-baseline): θθ+α(Gb)θlogπ(a1)\theta \leftarrow \theta + \alpha (G-b)\nabla_\theta\log\pi(a_1).

  • Gb=10.5=0.5G - b = 1 - 0.5 = 0.5. (1)
  • θlogπ(a1)=ea1π=(0,1)(0.25,0.75)=(0.25,0.25)\nabla_\theta\log\pi(a_1) = \mathbf{e}_{a_1} - \pi = (0,1) - (0.25, 0.75) = (-0.25, 0.25). (2)
  • Update vector: α(Gb)=0.1×0.5×(0.25,0.25)=(0.0125,0.0125)\alpha(G-b)\nabla = 0.1\times 0.5 \times(-0.25,0.25) = (-0.0125, 0.0125). (2)
  • New parameters: θ0=0+(0.0125)=0.0125,θ1=1.0986+0.0125=1.1111\theta_0 = 0 + (-0.0125) = -0.0125,\qquad \theta_1 = 1.0986 + 0.0125 = 1.1111 (2)

(Interpretation: positive advantage on a1a_1 raises its logit, lowers a0a_0's.)

(c) (4 marks)

  • Purpose: baseline reduces variance of the gradient estimate without introducing bias, giving faster/stabler learning (2).
  • Unbiasedness proof (2): the extra term is Eaπ[b(s)θlogπ(as)]=b(s)aπ(as)θlogπ(as)=b(s)aθπ(as)=b(s)θ ⁣aπ(as)=b(s)θ1=0.\mathbb{E}_{a\sim\pi}\big[b(s)\nabla_\theta\log\pi(a|s)\big] = b(s)\sum_a \pi(a|s)\nabla_\theta\log\pi(a|s) = b(s)\sum_a \nabla_\theta\pi(a|s) = b(s)\nabla_\theta\!\sum_a\pi(a|s) = b(s)\nabla_\theta 1 = 0. Since it adds zero in expectation, the estimator's expectation is unchanged.

Question 3 (12 marks)

(a) A^=+3>0\hat A=+3>0, ρ=1.5\rho=1.5, clip range [0.8,1.2][0.8,1.2].

  • Unclipped: 1.5×3=4.51.5\times 3 = 4.5; clipped: clip(1.5,0.8,1.2)×3=1.2×3=3.6\text{clip}(1.5,0.8,1.2)\times3 = 1.2\times3 = 3.6.
  • L=min(4.5,3.6)=3.6L = \min(4.5, 3.6) = 3.6. (3)

(b) A^=2<0\hat A=-2<0, ρ=1.5\rho=1.5.

  • Unclipped: 1.5×(2)=3.01.5\times(-2) = -3.0; clipped: 1.2×(2)=2.41.2\times(-2) = -2.4.
  • L=min(3.0,2.4)=3.0L = \min(-3.0, -2.4) = -3.0. (3)

(c) (6 marks)

  • For positive advantage with ρ>1+ϵ\rho > 1+\epsilon, the clipped branch (1+ϵ)A^(1+\epsilon)\hat A is constant in ρ\rho, and since it is the smaller of the two when ρ>1+ϵ\rho>1+\epsilon, L=(1+ϵ)A^L = (1+\epsilon)\hat A, so L/ρ=0\partial L/\partial\rho = 0 (3).
  • Implication: no gradient once the policy has moved "too far" in the improving direction → prevents excessively large policy updates / destructive steps (2).
  • Contrast: a vanilla importance-weighted objective ρA^\rho\hat A has constant gradient A^\hat A and keeps pushing ρ\rho up without bound, causing large, unstable off-policy updates (1).

Question 4 (10 marks)

(a) A(s0,a0)=1+0.8×3.02.0=1+2.42.0=1.4A(s_0,a_0) = 1 + 0.8\times 3.0 - 2.0 = 1 + 2.4 - 2.0 = 1.4. (3)

(b) A(2)=1+0.8×0+0.82×1.52.0=1+0+0.64×1.52=1+0.962=0.04A^{(2)} = 1 + 0.8\times 0 + 0.8^2\times 1.5 - 2.0 = 1 + 0 + 0.64\times1.5 - 2 = 1 + 0.96 - 2 = -0.04. (3)

(c) TD errors:

  • δ0=r1+γV(s1)V(s0)=1.4\delta_0 = r_1 + \gamma V(s_1) - V(s_0) = 1.4 (same as (a)). (1)
  • δ1=r2+γV(s2)V(s1)=0+0.8×1.53.0=1.23.0=1.8\delta_1 = r_2 + \gamma V(s_2) - V(s_1) = 0 + 0.8\times1.5 - 3.0 = 1.2 - 3.0 = -1.8. (1)
  • GAE: A^0GAE=δ0+(γλ)δ1=1.4+(0.8×0.5)(1.8)=1.4+0.4×(1.8)=1.40.72=0.68\hat A^{\text{GAE}}_0 = \delta_0 + (\gamma\lambda)\delta_1 = 1.4 + (0.8\times0.5)(-1.8) = 1.4 + 0.4\times(-1.8) = 1.4 - 0.72 = 0.68. (2)

Question 5 (12 marks)

(a) (4 marks)

  • Form: F(s,s)=γΦ(s)Φ(s)F(s,s') = \gamma\Phi(s') - \Phi(s) for a real-valued potential Φ\Phi over states (2).
  • Guarantee: potential-based shaping preserves the optimal policy (policy invariance) — the set of optimal policies of the shaped MDP equals that of the original (Ng, Harada & Russell) (2).

(b) (4 marks) Adding +0.1+0.1 for every "closer" move (not potential-based) creates exploitable cycles: e.g. the robot can oscillate/loop to repeatedly gain the shaping bonus, or take a longer meandering path that maximizes distance-decreasing steps rather than reaching the goal fast. It can even avoid the goal to keep farming the bonus. Any concrete reward-hacking loop earns full marks (4).

(c) (4 marks)

  • F=γΦ(s)Φ(s)=1×(4)(5)=4+5=+1F = \gamma\Phi(s') - \Phi(s) = 1\times(-4) - (-5) = -4 + 5 = +1. (2)
  • Reason: the shaping term telescopes over any trajectory — its cumulative contribution depends only on start/end potentials (with γ\gamma weighting), adding a state-only offset to the value function that does not alter the relative ordering of actions, hence the argmax (optimal) policy is unchanged (2).

[
  {"claim":"DQN target = 8.3, Double DQN target = 5.6","code":"gamma=Rational(9,10); r=2; y_dqn=r+gamma*7; y_ddqn=r+gamma*4; result=(y_dqn==Rational(83,10)) and (y_ddqn==Rational(56,10))"},
  {"claim":"REINFORCE update gives theta0=-0.0125, theta1=ln3+0.0125","code":"alpha=Rational(1,10); Gb=Rational(1,2); grad0=Rational(-1,4); grad1=Rational(1,4); t0=0+alpha*Gb*grad0; t1=alpha*Gb*grad1; result=(t0==Rational(-1,80)) and (t1==Rational(1,80))"},
  {"claim":"PPO L values: 3.6 for A=3,rho=1.5 and -3.0 for A=-2,rho=1.5","code":"def clip(x,lo,hi): return Max(lo,Min(hi,x))\nrho=Rational(3,2); eps=Rational(1,5)\nL1=Min(rho*3, clip(rho,1-eps,1+eps)*3)\nL2=Min(rho*(-2), clip(rho,1-eps,1+eps)*(-2))\nresult=(L1==Rational(18,5)) and (L2==-3)"},
  {"claim":"A2C: A1step=1.4, A2step=-0.04, GAE=0.68","code":"g=Rational(8,10); d0=1+g*3-2; A2=1+g*0+g**2*Rational(3,2)-2; d1=0+g*Rational(3,2)-3; lam=Rational(1,2); gae=d0+(g*lam)*d1; result=(d0==Rational(7,5)) and (A2==Rational(-1,25)) and (gae==Rational(17,25))"}
]