Skip to content
BIASED

Policy gradients and actor-critic

The policy gradient theorem, baselines and advantages, GAE, PPO, and the link to RLHF.

Why not argmax over Q

DQN acts by arg⁡max⁡aQ(s,a)\arg\max_a Q(s,a). Continuous torques make that an inner optimization; tiny Q-changes flip the greedy action; when states are aliased the best policy may be stochastic. In the short corridor (three lookalike states, swapped actions in the middle) the optimum is p⋆=2−2≈0.586p^\star=2-\sqrt{2}\approx 0.586 worth about −11.66-11.66; ε\varepsilon-greedy with ε=0.1\varepsilon=0.1 reaches only −44.2-44.2 or −82.1-82.1, and deterministic p∈{0,1}p\in\{0,1\} never finishes.

The policy gradient theorem

Key idea. Raise the probability of actions that led to high return. The log-derivative trick turns ∇J\nabla J into an expectation you can sample; unknown dynamics drop out of ∇log⁡pθ(τ)\nabla\log p_\theta(\tau):

∇J(θ)=Eτ∼pθ[∑t=0T−1γt Gt ∇log⁡πθ(at∣st)].\nabla J(\theta)=\mathbb E_{\tau\sim p_\theta}\Big[\sum_{t=0}^{T-1}\gamma^t\,G_t\,\nabla\log\pi_\theta(a_t\mid s_t)\Big].

Causality replaces the full return by the reward-to-go GtG_t. REINFORCE samples this sum; it is on-policy and noisy.

Baselines and advantages

Any action-independent baseline b(st)b(s_t) leaves the gradient unbiased because E[∇log⁡π]=0\mathbb E[\nabla\log\pi]=0. A baseline near VπV^\pi cuts variance: Gt−b(st)G_t-b(s_t) says whether the action beat the average. The advantage Aπ=Qπ−VπA^\pi=Q^\pi-V^\pi is the right weight; the TD error of a critic estimates it. Actor–critic: the actor steps along δt∇log⁡π\delta_t\nabla\log\pi; the critic learns VwV_w by TD.

GAE

GAE averages nn-step advantages with weights (γλ)l(\gamma\lambda)^l:

A^tGAE=∑l=0T−t−1(γλ)l δt+l,δt=rt+1+γVw(st+1)−Vw(st),\hat A_t^{\mathrm{GAE}}=\sum_{l=0}^{T-t-1}(\gamma\lambda)^l\,\delta_{t+l},\qquad \delta_t=r_{t+1}+\gamma V_w(s_{t+1})-V_w(s_t),

computed backwards A^t=δt+γλA^t+1\hat A_t=\delta_t+\gamma\lambda\hat A_{t+1}. λ=0\lambda=0 is one-step TD; λ=1\lambda=1 is Gt−Vw(st)G_t-V_w(s_t). With rewards 0,0,10,0,1, values 0.5,0.6,0.80.5,0.6,0.8, γ=0.9\gamma=0.9, λ=0.5\lambda=0.5: advantages 0.13450.1345, 0.210.21, 0.20.2.

PPO

Large policy steps change the data and can collapse learning. PPO maximizes a clipped surrogate

LCLIP=Et[min⁡(rt(θ)A^t, clip(rt(θ),1−ε,1+ε)A^t)]L^{\mathrm{CLIP}}=\mathbb E_t\Big[\min\big(r_t(\theta)\hat A_t,\ \mathrm{clip}(r_t(\theta),1-\varepsilon,1+\varepsilon)\hat A_t\big)\Big]

with rt=πθ/πoldr_t=\pi_\theta/\pi_{\mathrm{old}} and typically ε=0.2\varepsilon=0.2, plus a value loss and an entropy bonus. Clipping stops improving a sample once a good action grew (or a bad one shrank) by about 20%20\%, so several epochs per batch stay safe. An entropy bonus c H(π)c\,H(\pi) delays premature collapse.

LMs and next

A language model is already a policy over tokens; RLHF runs PPO (or a critic-free cousin) with a KL tether to the starting model. Model-free methods never ask what an untaken action would do — expensive. Next (extension): learn a world model and plan or imagine inside it — Dyna, MPC, Dreamer, MuZero.

Check your understanding

The same questions as in Pulse. Answers are shared between modes.

Full notes

Answers are saved on the server and tied to this browser until you sign in.