Answer: (b).Why (b): the log-derivative trick turns ∇p into p∇logp, so the surviving factor is ∇θlogπθ — the log, not the bare probability. That rules out (a).
Why not (c): the weight is the return following t, Gt, not the single-step reward rt. An action is credited with everything that comes after it, not just the immediate payoff.
Recall Solution
Only ∑t∇θlogπθ(at∣st) survives.ρ(s0) (start-state distribution) and P(s′∣s,a) (environment transitions) come from the world, not from θ. Their gradient w.r.t. θ is exactly zero. This is precisely why REINFORCE is model-free.
Work backwards using Gt=rt+γGt+1 (cheaper than re-summing each time).
G3=r3=4.
G2=r2+0.5G3=6+0.5(4)=8.
G1=r1+0.5G2=0+0.5(8)=4.
G0=r0+0.5G1=2+0.5(4)=4.
Answers:G0=4,G1=4,G2=8,G3=4.
Why backwards: each Gt reuses the already-computed Gt+1, so the whole sweep is O(T) instead of O(T2).
Recall Solution
Write logπθ(R)=θR−log(eθL+eθR).
Differentiate w.r.t. θR:
∂θR∂[θR−log(eθL+eθR)]=1−eθL+eθReθR=1−πθ(R).Why this shape is beautiful: if we sampled R and got positive advantage, the update ∝(1−π(R)) pushes hardest when π(R) is small (lots of room to grow) and gently when π(R) is already near 1. Self-limiting, no manual clipping needed.
Recall Solution
Update rule: θR←θR+α∇θRlogπθ(R)⋅G.
From L2.2, ∇θRlogπ(R)=1−π(R)=1−0.5=0.5.
θR←0+0.1×0.5×1=0.05.Answer: θR=0.05 (and θL unchanged at 0). New π(R)=e0+e0.05e0.05≈0.5125 — nudged up, exactly as the positive return demands.
Pull b(s) out (it doesn't depend on a) and convert the expectation to a sum, then run the log-derivative trick backwards:
b(s)∑aπθ(a∣s)∇θlogπθ(a∣s)=b(s)∑a∇θπθ(a∣s).
Swap sum and gradient (finite sum, linear):
=b(s)∇θ∑aπθ(a∣s)=b(s)∇θ(1)=b(s)⋅0=0.■The key fact: probabilities sum to 1, a constant, whose gradient is 0. This is the whole reason baselines are "free" — variance drops, bias stays zero. See figure.
Recall Solution
No baseline: weights are +105 and +95. Both positive — both log-probs pushed up. The learner must resolve which is better from a tiny 105 vs 95 difference riding on huge magnitudes → high variance, slow.
With b=100: advantages are AA=+5, AB=−5. Now A is pushed up, B pushed down explicitly. The contrast is exposed; magnitudes are small and centered.
Why it works: the baseline removes the common-mode offset (≈100) that carried no information about which action was better. See figure.
Recall Solution
Full return is R(τ)=15. The naive estimator would multiply ∇logπ(a1) by 15; reward-to-go multiplies by G1=r1+r2=10, dropping the r0=5earned beforea1.
The past reward r0 is a constant with respect to a1's distribution, so — by exactly the L3.1 argument with b=r0 — its expected contribution to ∇logπ(a1) is zero. Removing it changes nothing in expectation but shrinks the weight's variance.
Answer:G1=10; unbiased, lower variance. ✅
The second term has no μ, so it drops. Differentiate the first w.r.t. μ:
∇μlogπθ(a∣s)=σ2a−μ.Interpretation of sign: if the sampled action a was above the mean (a>μ) and the advantage was positive, the update moves μtoward a (upward) — "we liked doing more than average, so aim higher." If a<μ, it pulls μ down. The magnitude ∝(a−μ)/σ2 scales the surprise by how tight the policy is.
Recall Solution
L(θ)=−∑t=0Tlogπθ(at∣st)At.Why the sum: the gradient is a sum over timesteps, and ∇ is linear, so summing the terms before differentiating gives the right total.
Why At is treated as a constant: in REINFORCE the advantage weight is a number computed from the rollout, not differentiated through — autograd sees it as a coefficient.
Why the leading minus: optimizers minimize. We want to maximizeJ, i.e. ascend. Minimizing −∑logπ⋅A = ascending +∑logπ⋅A. Drop the minus and you'd descend, making good actions less likely.
Recall Solution
Advantage of bootstrapping: using rt+γV^(st+1) instead of the full sampled Gt dramatically lowers variance (one random reward + a learned estimate, versus a long noisy sum). It also allows online, per-step updates instead of waiting for the episode to end.
Disadvantage: it introduces bias, because V^ is an imperfect estimate; the update is only as correct as the critic. REINFORCE's Monte-CarloGt is unbiased but high-variance. This is the classic bias–variance trade-off of policy gradient methods.
Write expectation as an integral:J=∫pθ(τ)R(τ)dτ. Tool: definition of expectation — a probability-weighted integral.
Push gradient inside:∇θJ=∫∇θpθ(τ)R(τ)dτ. Tool: linearity of the gradient; R(τ) is θ-free (rewards come from the environment).
Log-derivative trick:∇θp=p∇θlogp. Why: converts ∇p into something that keeps the factor p, so the integral becomes an expectation again → samplable. Gives ∇θJ=Eτ[∇θlogpθ(τ)R(τ)].
Factor the trajectory probability:pθ(τ)=ρ(s0)∏tπθ(at∣st)P(st+1∣st,at); take log (product→sum), differentiate. Tool:log turns products into sums; environment terms ρ,P are θ-free so vanish → ∇θlogpθ(τ)=∑t∇θlogπθ(at∣st). This is where model-freeness appears.
Apply causality: an action at t cannot influence rewards before t; those contribute zero in expectation (L3.1 argument), so replace R(τ) by the reward-to-go Gt for each term. Result:
∇θJ=Eτ[∑t∇θlogπθ(at∣st)Gt].■
Updateθ←θ+αg:
θR=0+0.1(0.25)=0.025,θL=0+0.1(−0.25)=−0.025.Answer:θR=0.025, θL=−0.025. The rewarding action R climbed, L fell — and thanks to the baseline the two moved by equal and opposite amounts, cleanly separating the winner.
Recall Self-test checklist
Which fact justifies dropping P(s′∣s,a) from the gradient? ::: P does not depend on θ, so ∇θlogP=0 → model-free.
What is the exponent inside the reward-to-go Gt? ::: γk−t (relative to the current step, not absolute).
What single property makes a baseline unbiased? ::: it must not depend on the action a.
Why the leading minus sign in the loss? ::: optimizers minimize; minimizing −J performs gradient ascent on J.