Reinforcement Learning Foundations
Level: 4 — Application (novel problems, no hints) Time limit: 60 minutes Total marks: 60
Answer all questions. Show full working. Use for the discount factor. State any assumptions.
Question 1 — Returns and the Discount Factor (10 marks)
A robot receives the infinite reward sequence starting at :
except that at exactly one step it receives a one-time penalty making (all other rewards are ).
(a) Write the general formula for the discounted return and compute it symbolically as a function of . (6)
(b) Evaluate for . (2)
(c) A colleague claims "with the agent is myopic." State for and explain in one sentence what behaviour this induces. (2)
Question 2 — Modelling as an MDP (12 marks)
A vending machine restocks a single product. Each morning the stock level is units. The manager chooses action . "Order" adds 1 unit (capped at 2) with reward (cost). During the day, demand consumes 1 unit with probability and 0 units with probability ; each unit sold gives reward . A stockout (demand arrives at stock 0) gives reward .
(a) Identify the state set, action set, and the discount interpretation appropriate for an ongoing daily process. (3)
(b) For state , action , write the full transition-and-reward distribution: list each next state , its probability, and the immediate reward. (5)
(c) Explain why the Markov property holds for this formulation, and give one realistic feature of the real machine whose inclusion would break it. (4)
Question 3 — Bellman Evaluation by Hand (14 marks)
Consider a 2-state MDP with states and a fixed policy . Under :
- From : reward , then go to with prob .
- From : reward , then go to with prob and stay in with prob .
Use .
(a) Write the two Bellman expectation equations for and . (4)
(b) Solve the linear system exactly for and . (8)
(c) Using your results, compute the action-value-style one-step consistency check: verify that . (2)
Question 4 — TD, SARSA vs Q-learning Update (14 marks)
An agent uses learning rate , . Current estimates:
The agent is in , takes , receives reward , and lands in . Its behaviour policy is -greedy; on the next step it happens to select in .
(a) Compute the updated under the SARSA rule. Show the TD target and TD error. (5)
(b) Compute the updated under the Q-learning rule. Show the TD target and TD error. (5)
(c) Explain precisely why the two results differ here, and state which one is on-policy. (4)
Question 5 — Exploration and Policy Design (10 marks)
An agent uses -greedy action selection over actions.
(a) With , and a unique greedy action, give the probability of selecting the greedy action and the probability of selecting each specific non-greedy action. (4)
(b) The designer uses a decay schedule for episode . Compute , and explain in one sentence why decaying supports convergence to a near-optimal policy. (4)
(c) State one situation where pure greedy () from the start would fail, referencing the exploration–exploitation tradeoff. (2)
Answer keyMark scheme & solutions
Question 1 (10 marks)
(a) Definition . (1) All rewards are except , i.e. the actual value differs from an all-2 stream by at .
The all-2 geometric series (converges for ). (3)
(2) (correct assembly)
(b) : . (2)
(c) : only counts, . The agent maximises immediate reward only, ignoring all future consequences. (2)
Question 2 (12 marks)
(a) States ; actions . For an ongoing (continuing, non-terminating) process a discount factor is appropriate to keep returns finite and weight nearer days more. (3)
(b) State , action wait (no ordering cost). Demand w.p. → sells one unit (reward ), stock . Demand w.p. → no sale (reward ), stock stays .
| prob | reward | |
|---|---|---|
No stockout possible since stock demand. (5) (2 for probabilities, 2 for rewards, 1 for correct next states)
(c) Markov property holds because next state and reward depend only on current stock and action, not on the history of previous days' demand. (2) A realistic breaker: demand that depends on recent sales history / day-of-week seasonality (a hidden trend), making the true state incomplete. (2)
Question 3 (14 marks)
(a) Bellman expectation equations, : (4)
(b) Substitute :
From second: . (3)
Substitute into first: (3)
Then . (2)
(c) Check: . ✓ (2)
Question 4 (14 marks)
, , took in , , next action chosen in .
(a) SARSA (uses the actually-chosen next action ):
- TD target . (2)
- TD error . (1)
- Update: . (2)
(b) Q-learning (uses ):
- TD target . (2)
- TD error . (1)
- Update: . (2)
(c) They differ because SARSA bootstraps on the action actually taken (, value 6), while Q-learning bootstraps on the greedy/max action (, value 10). Since was not greedy in , the targets differ ( vs ). SARSA is on-policy (it evaluates the behaviour policy); Q-learning is off-policy. (4)
Question 5 (10 marks)
(a) Greedy action prob . (2) Each specific non-greedy action prob . (2) (Check: )
(b) ; ; . (3) Early large ensures broad exploration of all state-actions (needed for value estimates to be accurate), while shrinking lets the agent increasingly exploit its improved estimates, approaching the greedy optimal policy. (1)
(c) With from the start, the agent commits to whatever action first looked best (possibly by chance/initialisation) and never tries alternatives, so it can get stuck in a suboptimal action having never explored the truly best one — pure exploitation with no exploration. (2)
[
{"claim":"Q1b return equals 14.168 for gamma=0.9","code":"g=Rational(9,10); G=2/(1-g)-8*g**3; result=(G==Rational(14168,1000))"},
{"claim":"Q3 solution V(A)=4.4 V(B)=6.8 satisfies Bellman eqs with gamma=0.5","code":"VA,VB=symbols('VA VB'); sol=solve([VA-(1+Rational(1,2)*VB), VB-(4+Rational(1,2)*(Rational(1,2)*VA+Rational(1,2)*VB))],[VA,VB]); result=(sol[VA]==Rational(22,5) and sol[VB]==Rational(34,5))"},
{"claim":"Q4a SARSA update gives 5.2","code":"a=Rational(1,2); g=Rational(9,10); target=3+g*6; q=2+a*(target-2); result=(q==Rational(52,10))"},
{"claim":"Q4b Q-learning update gives 7","code":"a=Rational(1,2); g=Rational(9,10); target=3+g*Max(10,6); q=2+a*(target-2); result=(q==7)"},
{"claim":"Q5a epsilon-greedy probs sum to 1 with eps=0.2,4 actions","code":"eps=Rational(2,10); n=4; pg=1-eps+eps/n; po=eps/n; result=(pg==Rational(85,100) and po==Rational(5,100) and pg+3*po==1)"}
]