AI-ML interleaved practice
Instructions: Work each problem independently. These deliberately mix RL fundamentals with deep RL algorithms in random order — part of your task is deciding which framework or update rule applies before computing. Show all reasoning. Total: 50 marks.
Problem 1. (5 marks) An agent in a 2-state MDP is in state . The immediate reward for the next step is , then , then , and every reward thereafter is . With discount factor , compute the return observed from the start of this trajectory.
Problem 2. (5 marks) You observe the following single transition: state , action , reward , next state . Current estimates are , and for the values are , . The agent's policy at actually selected . Using , : (a) Compute the Q-learning update for . (b) Compute the SARSA update for . (c) State the one conceptual reason the two answers differ.
Problem 3. (5 marks) An -greedy policy over 4 actions uses . The greedy action is . Give the probability of selecting and the probability of selecting any one specific non-greedy action.
Problem 4. (6 marks) A 3-state MDP has a fixed policy . Under the dynamics give deterministic transitions: (reward 0), (reward 0), (reward 1, absorbing self-loop). Discount . Using the Bellman expectation equation, compute , , .
Problem 5. (5 marks) For a stochastic policy, an episode gives return following action taken in state , where . In the REINFORCE update, the parameter step is . If and , compute the size of the update . Why do we use rather than ?
Problem 6. (5 marks) Explain concisely why Double DQN was introduced over vanilla DQN. Write the target used in vanilla DQN and the target used in Double DQN, clearly showing which network selects and which evaluates the action.
Problem 7. (6 marks) Monte Carlo prediction: three episodes visit state once each, producing returns . (a) Give the first-visit MC estimate of . (b) A new episode gives return . Update using the incremental MC rule with starting from your answer in (a). (c) State one reason to prefer TD(0) over MC here.
Problem 8. (4 marks) Match each algorithm to the property that distinguishes it: (i) SARSA, (ii) Q-learning, (iii) A2C, (iv) SAC — against — (A) off-policy, maximizes reward plus an entropy term; (B) on-policy TD control; (C) off-policy control using the max over next-state values; (D) on-policy actor-critic using an advantage estimate.
Problem 9. (5 marks) In experience replay with a target network, explain: (a) what problem experience replay solves, and (b) what problem the separate target network solves. State how often the target network parameters are typically updated relative to the online network.
Problem 10. (4 marks) PPO uses a clipped surrogate objective. Given the probability ratio , advantage , and clip parameter , compute the value of the clipped term .
Answer keyMark scheme & solutions
Problem 1 — Subtopic 5.1.6 (Discount factor & returns). . Why this method: a pure return computation — no bootstrapping, just geometric discounting of a finite reward sequence.
Problem 2 — Subtopics 5.1.13 (Q-learning) vs 5.1.12 (SARSA). (a) Q-learning target . Update: . (b) SARSA uses the actual next action : target . Update: . (c) Q-learning is off-policy (uses , the greedy target), SARSA is on-policy (uses the action the behavior policy actually took). The choice hinges on spotting "policy actually selected " → SARSA must use it.
Problem 3 — Subtopic 5.1.8 (ε-greedy). . Each non-greedy action: . Check: . ✓ Why: standard ε-greedy split — greedy gets the leftover mass plus its share of exploration.
Problem 4 — Subtopics 5.1.5 (Bellman) + 5.1.3/5.1.4 (value functions). Work backward from absorbing state. . . . . Why: deterministic policy → Bellman expectation collapses to a chain; solve the self-loop first as a geometric fixed point.
Problem 5 — Subtopic 5.2.6 (REINFORCE). . Log used because ; the log-derivative (score function) trick turns the policy-gradient expectation into a sample-averageable form , and dividing by correctly weights actions inversely to their sampling probability.
Problem 6 — Subtopic 5.2.4 (Double DQN). Vanilla DQN overestimates values because the same network both selects and evaluates the max action, and over noisy estimates is biased upward. Vanilla target: . Double DQN target: — the online net selects the action, the target net evaluates it, decoupling selection from evaluation to reduce overestimation bias.
Problem 7 — Subtopic 5.1.10 (Monte Carlo), contrasted with 5.1.11 (TD). (a) . (b) . (c) TD(0) bootstraps, so it can update online per-step (no need to wait for episode end) and typically has lower variance than MC (which needs full returns).
Problem 8 — Subtopics 5.1.12, 5.1.13, 5.2.8, 5.2.11. (i) SARSA → (B) on-policy TD control. (ii) Q-learning → (C) off-policy, max over next values. (iii) A2C → (D) on-policy actor-critic with advantage. (iv) SAC → (A) off-policy with entropy-augmented objective.
Problem 9 — Subtopics 5.2.2 (replay) + 5.2.3 (target networks). (a) Experience replay breaks the temporal correlation between consecutive samples (and reuses data), giving more i.i.d.-like minibatches and better sample efficiency. (b) The target network provides a stationary/fixed target for a number of steps, preventing the moving-target instability where the network chases its own rapidly changing predictions. Update cadence: target net is updated to the online net's weights periodically (every steps, e.g. every few thousand) or via slow Polyak averaging.
Problem 10 — Subtopic 5.2.9 (PPO). Since , clip caps the ratio at . Unclipped: . Clipped: . . Why: the clip removes incentive to push the ratio beyond for a positive advantage, limiting destructive policy updates.
[
{"claim":"P1 return G0 = 5.51",
"code":"G = 2 + 0.9*3 + 0.9**2*1\nresult = abs(G - 5.51) < 1e-9"},
{"claim":"P2 Q-learning update gives 13.5 and SARSA gives 11.5",
"code":"ql = 10 + 0.5*((5 + 1.0*12) - 10)\nsa = 10 + 0.5*((5 + 1.0*8) - 10)\nresult = (ql == 13.5) and (sa == 11.5)"},
{"claim":"P10 PPO clipped term equals 2.4",
"code":"r=1.4; A=2; eps=0.2\nclip = min(max(r,1-eps),1+eps)\nval = min(r*A, clip*A)\nresult = abs(val - 2.4) < 1e-9"}
]