Understand: state assumptions, shapes/units and a counterexample.
Implement: reproduce a numerical example and inspect boundaries.
Investigate: compare one alternative under a matched budget.
Understand the mechanism
Policy gradients increase the log probability of actions associated with better-than-baseline outcomes. A state-dependent baseline that does not depend on the sampled action can reduce variance without changing the expected score-function gradient under standard assumptions. Actor–critic methods learn a value estimate to build that baseline, introducing estimation and bootstrapping considerations.
Original schematic; read the steps from top to bottom. SVG ↓
Symbols and assumptions
Symbol
Meaning
θ
Policy logit in the two-action example
σ(θ)
Probability of action 1
b(s)
Action-independent baseline for this derivation
With action rewards 0.8 and 0.2,
Differentiate: At , probability is 0.5, expected reward 0.5 and gradient 0.15. A small ascent step increases action-1 probability.
The baseline cancels in expectation because Σₐ This cancellation assumes the baseline does not depend on the sampled action.
Experiment checkpoint
Compare Monte Carlo gradient averages with the exact 0.15 reference at Increasing samples should reduce estimation noise.
LOCAL / SYNTHETIC / INTERACTIVE
Change one variable. Explain what moves.
Original teaching calculation, not a reproduction of the paper’s benchmark. Bars are relative within this panel; numeric values and units are authoritative.
Original exercise & analysis
Use a two-action bandit with rewards 0.8 and 0.2 and action-1 probability σ(θ). The exact expected reward is 0.2+0.6σ(θ); its derivative is 0.6σ(θ)(1−σ(θ)). Compare a sampled gradient estimate to this analytic reference across many seeds.
An action-dependent baseline generally needs a correction; subtracting any convenient function is not automatically unbiased.
Does a negative advantage mean the action is always bad?
No. It means worse than the baseline in that context under the estimator. Absolute reward may still be positive.
Use δ__(t+1)+γ(1−d_t)V(s_(t+1))−V(s_t), with d marking true termination, not rollout truncation. GAE is a finite masked sum through T−1. Baselines are action-independent; stop gradients through advantages. State the discounted occupancy normalization when deriving ∇J.
Formula conditions, units and worked arithmetic reviewed. The implementation isolates one numerical mechanism; it does not train a policy or control real hardware.
Before running: predict a boundary case
Compare analytic 0.15 to central finite differences of J at
Hint: isolate the assumption
Keep the baseline input fixed, change one parameter or boundary, and compare both the numerical result and the claimed units. A passing example verifies this fixture only.
Minimal executable example
Save the example and linked modules in one folder. Use Node.js 22 or newer, then run node policy-gradient.mjs. No third-party runtime dependencies.
Compare analytic 0.15 to central finite differences of J at
Record input, code version, expected result and observed result in the notebook below. Then construct a counterexample that violates the assumption above and explain why the original conclusion no longer follows.
Before revealing an answer, predict one result. After the exercise, record the discrepancy and a transfer test. Saved locally across language editions.
The mathematical review scope is recorded per lesson. It does not establish empirical paper reproduction; report suspected errors in your notes. Review scope