Policy Gradients in Reinforcement Learning

On this page

The RL foundations note evaluates a fixed policy through its Bellman equation. To improve a parameterized policy, we now differentiate that value with respect to its parameters. After proving the discounted policy-gradient theorem, we examine how algorithms estimate the gradient, control the update, and change the objective.

Recap: The Bellman inverse used in the proof

For a stationary policy in a finite discounted MDP, policy evaluation gives

Vπ=(I−γPπ)−1rπ,(I−γPπ)−1=∑t=0∞γt(Pπ)t.V^\pi=(I-\gamma P^\pi)^{-1}r^\pi, \qquad (I-\gamma P^\pi)^{-1}=\sum_{t=0}^\infty\gamma^t(P^\pi)^t.

Here PπP^\pi is the policy's state-transition matrix and rπr^\pi its expected reward vector. The series converges for γ<1\gamma<1. We use this inverse to propagate a policy change through future state visits.

1. One gradient, several algorithmic choices

We begin with a finite-state, finite-action, time-homogeneous Markov decision process. The environment's transition probabilities P(s′∣s,a)P(s'\mid s,a) and expected immediate rewards r(s,a)r(s,a) do not depend on the policy parameter. Assume bounded rewards, a fixed initial distribution ρ0\rho_0, and 0≤γ<10\le\gamma<1.

Let πθ(a∣s)>0\pi_\theta(a\mid s)>0 be a continuously differentiable stationary policy, with θ\theta in an open subset of Rp\mathbb R^p. Define

Gt=∑l=0∞γlRt+l+1,Vθ(s)=Esπθ[G0],Qθ(s,a)=r(s,a)+γ∑s′P(s′∣s,a)Vθ(s′),Aθ(s,a)=Qθ(s,a)−Vθ(s),J(θ)=∑sρ0(s)Vθ(s).\begin{aligned} G_t&=\sum_{l=0}^\infty\gamma^lR_{t+l+1},\\ V^\theta(s)&=\mathbb E_s^{\pi_\theta}[G_0],\qquad Q^\theta(s,a)=r(s,a)+\gamma\sum_{s'}P(s'\mid s,a)V^\theta(s'),\\ A^\theta(s,a)&=Q^\theta(s,a)-V^\theta(s),\\ J(\theta)&=\sum_s\rho_0(s)V^\theta(s). \end{aligned}

The normalized discounted state distribution and state–action distribution are

dθ(s)=(1−γ)∑t=0∞γtPρ0πθ(St=s),νθ(s,a)=dθ(s)πθ(a∣s).d_\theta(s)=(1-\gamma)\sum_{t=0}^\infty\gamma^t \mathbb P_{\rho_0}^{\pi_\theta}(S_t=s),\qquad \nu_\theta(s,a)=d_\theta(s)\pi_\theta(a\mid s).

Write Eνθ=E(S,A)∼νθ\mathbb E_{\nu_\theta}=\mathbb E_{(S,A)\sim\nu_\theta}: first draw S∼dθS\sim d_\theta, then A∣S∼πθ(⋅∣S)A\mid S\sim\pi_\theta(\cdot\mid S). This distribution weights state visits across time by their discount factors. It is not the distribution at a single time or an arbitrary distribution sampled from stored experience. Define the policy score ψθ(s,a)=∇θlog⁡πθ(a∣s)\psi_\theta(s,a)=\nabla_\theta\log\pi_\theta(a\mid s), which measures how the log action probability changes with the policy parameters.

Let PπθP_{\pi_\theta} be the trajectory distribution generated by S0∼ρ0S_0\sim\rho_0, actions from πθ(⋅∣St)\pi_\theta(\cdot\mid S_t), and next states/rewards from the fixed environment kernel p(⋅∣St,At)p(\cdot\mid S_t,A_t) of the foundations note. We write Eπθ=Eτ∼Pπθ\mathbb E_{\pi_\theta}=\mathbb E_{\tau\sim P_{\pi_\theta}} for trajectory expectations, including their conditional versions. The notation Esπθ\mathbb E_s^{\pi_\theta} fixes S0=sS_0=s instead of drawing it from ρ0\rho_0. All these averages hold θ\theta fixed; differentiating them later accounts for their dependence on θ\theta.

Original Spinning Up taxonomy branches from reinforcement learning into model-free and model-based methods. Model-free methods include policy optimization, Q-learning, and their overlap, with PPO, TRPO, DDPG, TD3, SAC and DQN among the examples.
Figure 1. A taxonomy of reinforcement-learning algorithms. Original figure from OpenAI, Spinning Up, Part 2: Kinds of RL Algorithms. This is the source's non-exhaustive map, not an exclusive partition: actor–critic methods and data-access choices can cross its branches. Full resolution ↗MIT License; © 2018 OpenAI

The methods below change different parts of policy optimization. REINFORCE and actor–critic estimate the gradient differently. Natural gradients change how we measure the size of a policy update, while TRPO and PPO change the update criterion. Deterministic gradients require different policy and action-space assumptions. Entropy regularization changes the objective to also reward randomness in action choices. An algorithm can combine several of these choices.

2. The discounted policy-gradient theorem

Theorem 1. Under the assumptions above,

∇θJ(θ)=11−γEνθ[ψθ(S,A)Qθ(S,A)]=11−γEνθ[ψθ(S,A)Aθ(S,A)].\boxed{ \begin{aligned} \nabla_\theta J(\theta) &=\frac1{1-\gamma}\mathbb E_{\nu_\theta} [\psi_\theta(S,A)Q^\theta(S,A)] \\&=\frac1{1-\gamma}\mathbb E_{\nu_\theta} [\psi_\theta(S,A)A^\theta(S,A)]. \end{aligned} }

This is the discounted start-distribution form of the policy-gradient theorem in Sutton et al. (1999), Theorem 1. The factor 1/(1−γ)1/(1-\gamma) appears because dθd_\theta is normalized.

First, differentiate the Bellman identity Vθ(s)=∑aπθ(a∣s)Qθ(s,a)V^\theta(s)=\sum_a\pi_\theta(a\mid s)Q^\theta(s,a). Put

uθ(s)=∇θVθ(s),cθ(s)=∑a∇θπθ(a∣s)Qθ(s,a).u_\theta(s)=\nabla_\theta V^\theta(s),\qquad c_\theta(s)=\sum_a\nabla_\theta\pi_\theta(a\mid s)Q^\theta(s,a).

Since the environment is fixed, ∇θQθ(s,a)=γ∑s′P(s′∣s,a)uθ(s′)\nabla_\theta Q^\theta(s,a)=\gamma\sum_{s'}P(s'\mid s,a)u_\theta(s'). The product rule gives

uθ(s)=cθ(s)+γ∑aπθ(a∣s)∑s′P(s′∣s,a)uθ(s′)=cθ(s)+γ(Pθuθ)(s),\begin{aligned} u_\theta(s) &=c_\theta(s)+\gamma\sum_a\pi_\theta(a\mid s) \sum_{s'}P(s'\mid s,a)u_\theta(s')\\ &=c_\theta(s)+\gamma(P_\theta u_\theta)(s), \end{aligned}

where Pθ(s,s′)=∑aπθ(a∣s)P(s′∣s,a)P_\theta(s,s')=\sum_a\pi_\theta(a\mid s)P(s'\mid s,a). The inverse exists by the Neumann-series argument. Applied coordinatewise to uθu_\theta,

uθ=(I−γPθ)−1cθ=∑t=0∞γtPθtcθ.u_\theta=(I-\gamma P_\theta)^{-1}c_\theta =\sum_{t=0}^\infty\gamma^tP_\theta^tc_\theta.

Next, average over the initial distribution:

∇θJ=∑t=0∞γtρ0⊤Pθtcθ=11−γ∑sdθ(s)∑a∇θπθ(a∣s)Qθ(s,a)=11−γEνθ[ψθQθ].\begin{aligned} \nabla_\theta J &=\sum_{t=0}^\infty\gamma^t\rho_0^\top P_\theta^tc_\theta\\ &=\frac1{1-\gamma}\sum_s d_\theta(s) \sum_a\nabla_\theta\pi_\theta(a\mid s)Q^\theta(s,a)\\ &=\frac1{1-\gamma}\mathbb E_{\nu_\theta}[\psi_\theta Q^\theta]. \end{aligned}

The final equality uses ∇πθ=πθ∇log⁡πθ\nabla\pi_\theta=\pi_\theta\nabla\log\pi_\theta. Differentiability follows directly from the finite-dimensional inverse formula for VθV^\theta; the convergent series represents that derivative. We have not discarded the effect of changing state visitation: the inverse propagates it through every future transition.

Finally, for each state,

∑aπθ(a∣s)ψθ(s,a)=∇θ∑aπθ(a∣s)=0.\sum_a\pi_\theta(a\mid s)\psi_\theta(s,a) =\nabla_\theta\sum_a\pi_\theta(a\mid s)=0.

Thus any finite state-only baseline b(s)b(s) has Eνθ[ψθb(S)]=0\mathbb E_{\nu_\theta}[\psi_\theta b(S)]=0. Choosing b=Vθb=V^\theta proves the advantage form. □\square

3. REINFORCE: Use sampled returns

The likelihood-ratio construction leads to the Monte Carlo estimator

g^MC=1n∑i=1n∑t≥0γtψθ(Sti,Ati){Gti−b(Sti)}.\widehat g_{\mathrm{MC}} =\frac1n\sum_{i=1}^n\sum_{t\ge0}\gamma^t \psi_\theta(S_{ti},A_{ti})\{G_{ti}-b(S_{ti})\}.

The batch B=(τ1,…,τn)∼Pπθ⊗n\mathcal B=(\tau_1,\ldots,\tau_n)\sim P_{\pi_\theta}^{\otimes n} consists of independent current-policy trajectories. Conditional on (St,At)(S_t,A_t), the return under PπθP_{\pi_\theta} has mean Qθ(St,At)Q^\theta(S_t,A_t). The tower property and the mean-zero score therefore give EB∼Pπθ⊗n[g^MC]=∇J\mathbb E_{\mathcal B\sim P_{\pi_\theta}^{\otimes n}}[\widehat g_{\mathrm{MC}}]=\nabla J. This is the return-based policy-gradient construction associated with Williams's REINFORCE algorithms.

The identity uses full returns, or returns through genuine terminal states in episodic problems. An arbitrary rollout cutoff without its continuation value changes the target. The baseline must be held fixed relative to the trajectory used for this unbiasedness argument; estimating it from those same outcomes needs an additional argument.

Which baseline minimizes variance?

Fix a state ss and consider the vector contribution Xb=ψθ(s,A)(G−b)X_b=\psi_\theta(s,A)(G-b). In this subsection, (A,G)∣S=s(A,G)\mid S=s is drawn by sampling A∼πθ(⋅∣s)A\sim\pi_\theta(\cdot\mid s) and then the discounted continuation return from the environment and policy. The conditional expectations below use that distribution, with s,θ,bs,\theta,b fixed. Its conditional mean is independent of bb. Hence minimizing the trace of its conditional covariance is equivalent to minimizing

E[∥ψθ(s,A)∥2(G−b)2∣S=s].\mathbb E[\|\psi_\theta(s,A)\|^2(G-b)^2\mid S=s].

Differentiate this scalar quadratic in bb. If its denominator is positive, the minimizer is

b∗(s)=E[G∥ψθ(s,A)∥2∣S=s]E[∥ψθ(s,A)∥2∣S=s].\boxed{ b^*(s)= \frac{\mathbb E[G\|\psi_\theta(s,A)\|^2\mid S=s]} {\mathbb E[\|\psi_\theta(s,A)\|^2\mid S=s]}. }

If the denominator is zero, the score is zero almost surely at that state and every baseline is equivalent. This is a variance optimum for a single conditional score contribution, not automatically for the sum of correlated contributions in an episode. In general b∗(s)≠Vθ(s)b^*(s)\ne V^\theta(s).

For one decision, let A∼Bernoulli⁡(p)A\sim\operatorname{Bernoulli}(p) with p=σ(θ)=0.2p=\sigma(\theta)=0.2, reward Y=A∈{0,1}Y=A\in\{0,1\}, and score ψ=A−p\psi=A-p. Only AA is random, so

EA∼Bernoulli⁡(p)[Xb]=p(1−p)=0.16,Var⁡A∼Bernoulli⁡(p)(Xb)=0.16(b−0.8)2.\begin{aligned} \mathbb E_{A\sim\operatorname{Bernoulli}(p)}[X_b]&=p(1-p)=0.16,\\ \operatorname{Var}_{A\sim\operatorname{Bernoulli}(p)}(X_b)&=0.16(b-0.8)^2. \end{aligned}

The value baseline b=0.2b=0.2 reduces variance from 0.10240.1024 to 0.05760.0576; b∗=0.8b^*=0.8 makes both possible gradient contributions equal to 0.160.16. This is an exact illustrative calculation, not an empirical benchmark.

The value baseline need not minimize gradient varianceExact variance curve 0.16 times (b minus 0.8) squared for a Bernoulli logit policy with probability 0.2 and reward equal to its action. No baseline gives variance 0.1024. The value baseline 0.2 gives variance 0.0576. The optimal conditional baseline 0.8 gives zero variance. The mean gradient remains 0.16 for every baseline.Bernoulli p = 0.2; mean gradient = 0.16 for every baseline0.000.080.16varianceno baseline0.0value baseline0.2conditional optimum0.8baseline b
Figure 2. The value baseline need not minimize gradient variance. Original analytical example calculated in Section 3, illustrating the baseline in Williams's REINFORCE update. These are exact variances, not learning curves or paper experiment results. Source.

4. Actor–critic and generalized advantage estimation

An actor–critic method learns a value function alongside the policy. With an approximate action value QwQ_w, replacing QθQ^\theta in the theorem gives

gw−g=11−γEνθ[ψθ{Qw−Qθ}].g_w-g =\frac1{1-\gamma}\mathbb E_{\nu_\theta} [\psi_\theta\{Q_w-Q^\theta\}].

Consequently Cauchy–Schwarz yields

∥gw−g∥≤Eνθ∥ψθ∥21−γEνθ(Qw−Qθ)2.\|g_w-g\| \le\frac{\sqrt{\mathbb E_{\nu_\theta}\|\psi_\theta\|^2}} {1-\gamma} \sqrt{\mathbb E_{\nu_\theta}(Q_w-Q^\theta)^2}.

A critic can introduce bias; a small prediction error and an exactly unbiased gradient are different properties. Sutton et al., Theorem 2 gives an important exception. For a compatible advantage critic fw(s,a)=w⊤ψθ(s,a)f_w(s,a)=w^\top\psi_\theta(s,a), minimize the population loss

E(w)=12Eνθ[{Aθ−w⊤ψθ}2].\mathcal E(w)=\tfrac12\mathbb E_{\nu_\theta} [\{A^\theta-w^\top\psi_\theta\}^2].

Stationarity in ww gives

Eνθ[ψθ{Aθ−fw}]=0,11−γEνθ[ψθfw]=g.\mathbb E_{\nu_\theta}[\psi_\theta\{A^\theta-f_w\}]=0, \qquad \frac1{1-\gamma}\mathbb E_{\nu_\theta}[\psi_\theta f_w]=g.

Here the fitted critic gives the exact gradient because the mean product of its residual and the policy score is zero. This is the orthogonality established by the preceding equation. The result requires the displayed population regression, with policy parameters and the sampling distribution fixed. It does not hold for an arbitrary neural critic.

From TD residuals to GAE

For a bounded state-value approximation VwV_w, define its temporal-difference residual

δtw=Rt+1+γVw(St+1)−Vw(St).\delta_t^w=R_{t+1}+\gamma V_w(S_{t+1})-V_w(S_t).

Here ww and θ\theta are fixed. Conditional on (St,At)(S_t,A_t), δtw\delta_t^w varies through (St+1,Rt+1)∼p(⋅∣St,At)(S_{t+1},R_{t+1})\sim p(\cdot\mid S_t,A_t). If Vw=VθV_w=V^\theta, the Bellman equation gives Eπθ[δtw∣St,At]=Aθ(St,At)\mathbb E_{\pi_\theta}[\delta_t^w\mid S_t,A_t]=A^\theta(S_t,A_t). To incorporate more subsequent rewards, sum kk residuals:

A^t(k)=∑l=0k−1γlδt+lw=∑l=0k−1γlRt+l+1+γkVw(St+k)−Vw(St).\begin{aligned} \widehat A_t^{(k)} &=\sum_{l=0}^{k-1}\gamma^l\delta_{t+l}^w\\ &=\sum_{l=0}^{k-1}\gamma^lR_{t+l+1} +\gamma^kV_w(S_{t+k})-V_w(S_t). \end{aligned}

The intermediate value terms cancel. Generalized advantage estimation (GAE) mixes these horizons. For 0≤λ<10\le\lambda<1,

A^tGAE=(1−λ)∑k=1∞λk−1A^t(k)=∑l=0∞γlδt+lw{(1−λ)∑k=l+1∞λk−1}=∑l=0∞(γλ)lδt+lw.\begin{aligned} \widehat A_t^{\mathrm{GAE}} &=(1-\lambda)\sum_{k=1}^\infty\lambda^{k-1}\widehat A_t^{(k)}\\ &=\sum_{l=0}^\infty\gamma^l\delta_{t+l}^w \left\{(1-\lambda)\sum_{k=l+1}^\infty\lambda^{k-1}\right\}\\ &=\boxed{\sum_{l=0}^\infty(\gamma\lambda)^l\delta_{t+l}^w}. \end{aligned}

Bounded rewards and VwV_w justify the rearrangement by absolute convergence. Here λ\lambda is a trace parameter, unrelated to the kernel noise scale in the earlier article.

GAE weights future TD residuals geometricallyWith discount 0.9, coefficients of the first six TD residuals are (0.9 lambda) to powers zero through five. Lambda zero retains only the current residual. Lambda 0.9 gives coefficients 1, 0.81, 0.6561 and smaller future weights. Lambda one gives coefficients 1, 0.9, 0.81 and so on. The infinite tail is omitted from the drawing but retained by the formula.Weight of TD residual δₜ₊ₗ is (γλ)ˡ; γ = 0.9λ = 0.01.000.000.000.000.000.00λ = 0.91.000.810.660.530.430.35λ = 1.01.000.900.810.730.660.59l = 0l = 1l = 2l = 3l = 4l = 5The infinite-series tail continues beyond the displayed terms.
Figure 3. GAE weights future TD residuals geometrically. Original coefficient plot from Schulman et al. (2016), Equations (16)–(18). Discount γ = 0.9; the six displayed terms do not replace the infinite-series definition. Source.

At λ=0\lambda=0, the estimator is one TD residual. At λ=1\lambda=1, the residual series telescopes to Gt−Vw(St)G_t-V_w(S_t) because γkVw(St+k)→0\gamma^kV_w(S_{t+k})\to0. The latter gives an unbiased score-gradient contribution for any fixed state-only VwV_w; its conditional mean need not equal the true advantage unless Vw=VθV_w=V^\theta.

If Vw=VθV_w=V^\theta, all later residuals have zero conditional mean after averaging over their policy-selected actions. Thus every λ∈[0,1]\lambda\in[0,1] yields the correct conditional advantage. With an imperfect critic, λ<1\lambda<1 can introduce bias while changing variance. No universal monotone ordering of variances is implied. Unlike the GAE paper's discussion of discounting an undiscounted objective, our target is explicitly JJ with the fixed discount γ\gamma.

5. Natural gradients: Measure changes in policies

Ordinary ascent uses the direction g=∇Jg=\nabla J in parameter coordinates. Natural policy gradients instead use a local metric on action distributions. Following Kakade's natural policy gradient, define

Fθ=Eνθ[ψθψθ⊤].F_\theta=\mathbb E_{\nu_\theta}[\psi_\theta\psi_\theta^\top].

For this derivation, assume the policy is twice continuously differentiable and FθF_\theta is positive definite. We measure the change between action distributions using Kullback–Leibler (KL) divergence. Holding the reference state distribution dθd_\theta fixed, expand its average:

D‾θ(θ+Δ)=ES∼dθDKL{πθ(⋅∣S)∥πθ+Δ(⋅∣S)}=12Δ⊤FθΔ+o(∥Δ∥2).\begin{aligned} \overline D_\theta(\theta+\Delta) &=\mathbb E_{S\sim d_\theta} D_{\mathrm{KL}}\{\pi_\theta(\cdot\mid S)\|\pi_{\theta+\Delta}(\cdot\mid S)\} \\&=\tfrac12\Delta^\top F_\theta\Delta+o(\|\Delta\|^2). \end{aligned}

The linear term vanishes by the mean-zero score. For the Hessian, differentiating ∑aπθ(a∣s)=1\sum_a\pi_\theta(a\mid s)=1 twice gives

−∑aπθ(a∣s)∇θ2log⁡πθ(a∣s)=∑aπθ(a∣s)ψθ(s,a)ψθ(s,a)⊤.-\sum_a\pi_\theta(a\mid s)\nabla_\theta^2\log\pi_\theta(a\mid s) =\sum_a\pi_\theta(a\mid s)\psi_\theta(s,a)\psi_\theta(s,a)^\top.

The KL expansion measures policy change by a quadratic form. We therefore compare candidate update directions under the local constraint

max⁡Δg⊤Δsubject to12Δ⊤FθΔ≤δ.\max_\Delta g^\top\Delta \quad\text{subject to}\quad \tfrac12\Delta^\top F_\theta\Delta\le\delta.

For g≠0g\ne0 and δ>0\delta>0, the Lagrangian equation g=ηFθΔg=\eta F_\theta\Delta and an active constraint give

Δ∗=2δg⊤Fθ−1g Fθ−1g.\boxed{ \Delta^* =\sqrt{\frac{2\delta}{g^\top F_\theta^{-1}g}}\,F_\theta^{-1}g. }

The natural-gradient direction is Fθ−1gF_\theta^{-1}g. For g=0g=0, choose Δ=0\Delta=0. Redundant parameterizations, including unrestricted softmax logits, can make FθF_\theta singular; an ordinary inverse is then unavailable. Damping or an appropriate pseudoinverse requires a modified treatment, not the positive-definite calculation above.

Euclidean and natural directions under the same local KL budgetThe ellipse 9 delta-theta-1 squared plus delta-theta-2 squared at most one represents twice the local KL constraint. For gradient (1,1), the budget-normalized Euclidean step is (0.3162,0.3162), while the natural step is (0.1054,0.9487). Both lie on the ellipse, but the natural step gives a larger linearized objective increase. This is a local quadratic illustration, not a policy performance guarantee.F = diag(9,1), g = (1,1), 2δ = 1Δθ₁Δθ₂natural directionF⁻¹g, scaled to the budgetEuclidean directiong, scaled to the same budgetLinearized gains:natural 1.054; Euclidean 0.632The ellipse is a local quadratic constraint, not an exact finite-step KL region.
Figure 4. Euclidean and natural directions under the same local KL budget. Original geometry example using the Fisher metric in Kakade (2001). F = diag(9,1), g = (1,1), and 2δ = 1. The ellipse is a quadratic KL approximation, not an exact finite-step KL region. Source.

The compatible-critic normal equations from the preceding section are Fθw=(1−γ)gF_\theta w=(1-\gamma)g. When the inverse exists, its coefficients therefore point in the natural-gradient direction. Kakade's original presentation uses an average-reward distribution; the factor here follows from our normalized discounted convention.

6. TRPO and PPO: Change the update criterion

Let π\pi be the old policy and π′\pi' a candidate. The performance-difference identity is

J(π′)−J(π)=11−γES∼dπ′, A∼π′(⋅∣S)[Aπ(S,A)].\boxed{ J(\pi')-J(\pi) =\frac1{1-\gamma}\mathbb E_{S\sim d_{\pi'},\,A\sim\pi'(\cdot\mid S)}[A^\pi(S,A)]. }

To establish it, take a trajectory under π′\pi'. Conditional expectation of Rt+1+γVπ(St+1)−Vπ(St)R_{t+1}+\gamma V^\pi(S_{t+1})-V^\pi(S_t) given (St,At)(S_t,A_t) equals Aπ(St,At)A^\pi(S_t,A_t). Discount and sum through time m−1m-1:

Eπ′∑t=0m−1γt{Rt+1+γVπ(St+1)−Vπ(St)}=Eπ′∑t=0m−1γtRt+1−Eρ0Vπ(S0)+γmEπ′Vπ(Sm).\begin{aligned} &\mathbb E_{\pi'}\sum_{t=0}^{m-1}\gamma^t \{R_{t+1}+\gamma V^\pi(S_{t+1})-V^\pi(S_t)\}\\ &\quad=\mathbb E_{\pi'}\sum_{t=0}^{m-1}\gamma^tR_{t+1} -\mathbb E_{\rho_0}V^\pi(S_0) +\gamma^m\mathbb E_{\pi'}V^\pi(S_m). \end{aligned}

Bounded values make the final term vanish as m→∞m\to\infty. The definition of normalized occupancy then gives the identity. This is the starting point of Schulman et al.'s TRPO analysis.

A local surrogate and a trust region

Replace the candidate state distribution by the old one to define

Lπ(π′)=J(π)+11−γES∼dπ,A∼π(⋅∣S)[π′(A∣S)π(A∣S)Aπ(S,A)].L_\pi(\pi') =J(\pi)+\frac1{1-\gamma} \mathbb E_{S\sim d_\pi,A\sim\pi(\cdot\mid S)} \left[\frac{\pi'(A\mid S)}{\pi(A\mid S)}A^\pi(S,A)\right].

At π′=π\pi'=\pi, it equals J(π)J(\pi) and has the same parameter gradient as JJ. For the derivative, any change in dπ′d_{\pi'} multiplies ∑aπ(a∣s)Aπ(s,a)=0\sum_a\pi(a\mid s)A^\pi(s,a)=0 at the old policy, leaving exactly the policy-gradient term. Away from the old policy the two objectives need not agree.

Practical trust region policy optimization (TRPO) approximately maximizes the sample surrogate subject to an average KL constraint. It uses a linear approximation to the objective and a quadratic approximation to KL, giving the natural-gradient calculation above. It then checks the proposed update.

The paper's theoretical improvement bound instead controls the largest divergence over all states. Replacing that quantity by a sampled average KL is a practical approximation. It does not guarantee that every update improves the true return.

PPO's clipped surrogate

Proximal policy optimization (PPO) uses the action ratio ϱθ(s,a)=πθ(a∣s)/πold(a∣s)\varrho_\theta(s,a)=\pi_\theta(a\mid s)/\pi_{\mathrm{old}}(a\mid s) and a fixed advantage estimate A^\widehat A. For 0<ϵ<10<\epsilon<1, its clipped term is

ℓ(ϱ,A^)=min⁡{ϱA^,clip⁡(ϱ,1−ϵ,1+ϵ)A^}.\ell(\varrho,\widehat A) =\min\{\varrho\widehat A, \operatorname{clip}(\varrho,1-\epsilon,1+\epsilon)\widehat A\}.

The two signs of advantage give different plateaus:

ℓ(ϱ,A^)={A^min⁡(ϱ,1+ϵ),A^≥0,A^max⁡(ϱ,1−ϵ),A^<0.\ell(\varrho,\widehat A)= \begin{cases} \widehat A\min(\varrho,1+\epsilon),&\widehat A\ge0,\\ \widehat A\max(\varrho,1-\epsilon),&\widehat A<0. \end{cases}

The sampled objective averages these terms. The original PPO paper's Figure 1 shows the sign-dependent clipping directly.

Original PPO Figure 1. With positive advantage the objective rises with the probability ratio and then plateaus above one plus epsilon. With negative advantage it is flat below one minus epsilon and decreases thereafter. Red markers indicate the initial ratio one.
Figure 5. The PPO paper's clipped-surrogate figure. Original figure from Schulman et al. (2017), Proximal Policy Optimization Algorithms, Figure 1. The horizontal axis is the new-to-old action-probability ratio r. These are the authors' original objective plots, not new experimental evidence. Full resolution ↗Figure excerpt for discussion; copyright remains with the authors/rightsholder.

At ratio one, its derivative matches the ordinary surrogate's derivative. Clipping removes an individual sample's incentive to increase a favorable ratio beyond its plateau. It does not constrain every ratio to the clipping interval, clip the policy's action probabilities, or establish a hard KL bound. This is why PPO's objective and TRPO's constrained update remain distinct.

7. Deterministic and reparameterized policy gradients

We now change assumptions. Keep finite states and γ<1\gamma<1, but let actions range over an open subset of Rm\mathbb R^m. A deterministic policy μθ(s)\mu_\theta(s) takes values in that set. Assume μθ\mu_\theta, the expected reward, and transition probabilities are continuously differentiable in the relevant parameters/actions; rewards remain bounded. These finite-state conditions make the Bellman inverse differentiable.

Let Dθμθ(s)∈Rm×pD_\theta\mu_\theta(s)\in\mathbb R^{m\times p} be the action Jacobian. Differentiating the deterministic Bellman equation gives

∇θVμθ(s)=Dθμθ(s)⊤∇aQμθ(s,a)∣a=μθ(s)+γ∑s′P(s′∣s,μθ(s))∇θVμθ(s′).\begin{aligned} \nabla_\theta V^{\mu_\theta}(s) &=D_\theta\mu_\theta(s)^\top \nabla_aQ^{\mu_\theta}(s,a)|_{a=\mu_\theta(s)} \\&\quad+\gamma\sum_{s'}P(s'\mid s,\mu_\theta(s)) \nabla_\theta V^{\mu_\theta}(s'). \end{aligned}

Differentiating the current action produces the first term. The second accounts for changes in future actions, which we propagate through the Bellman inverse as in Theorem 1:

∇θJ(μθ)=11−γES∼dμθ[Dθμθ(S)⊤∇aQμθ(S,a)∣a=μθ(S)].\boxed{ \nabla_\theta J(\mu_\theta) =\frac1{1-\gamma}\mathbb E_{S\sim d_{\mu_\theta}} \left[D_\theta\mu_\theta(S)^\top \nabla_aQ^{\mu_\theta}(S,a)|_{a=\mu_\theta(S)}\right]. }

This is a finite-state version of Silver et al.'s deterministic policy-gradient theorem. There is no log⁡πθ\log\pi_\theta for a point-mass policy. A deterministic argmax over categorical action labels is not the differentiable continuous-action map required here.

The gradient passes through the action input of a critic, not through the unknown physical environment. Exploration may use a separate stochastic behavior policy. Replacing dμθd_{\mu_\theta} by an uncorrected replay-state distribution does not preserve this exact start-distribution gradient in general; Silver et al. explicitly distinguish their off-policy approximation.

Original Jang, Gu and Poole Figure 2 contains five panels: ordinary deterministic backpropagation; a stochastic sample blocking ordinary backpropagation; a score-function estimator using a surrogate loss; a straight-through approximation; and a reparameterized Gumbel–Softmax relaxation. Black arrows are forward computation and red arrows are backward derivatives.
Figure 6. Gradient estimators in stochastic computation graphs. Original figure from Jang, Gu and Poole (2017), Categorical Reparameterization with Gumbel-Softmax, Figure 2. Panel (3) shows the score-function route used in likelihood-ratio gradients. Panel (5) is a categorical relaxation, not a depiction of DPG or SAC. The methods are compared, not identified with one another. Full resolution ↗Figure excerpt for discussion; copyright remains with the authors/rightsholder.

A stochastic policy can also admit a pathwise gradient: write A=gθ(s,ξ)A=g_\theta(s,\xi) with parameter-independent noise ξ\xi. The policy remains stochastic because ξ\xi varies. This differs from both a deterministic actor and a score-function estimator; Jang et al., Figure 2 illustrates the distinction between differentiating a likelihood and differentiating a sample transformation.

8. Entropy-regularized stochastic actors

Soft actor–critic (SAC) combines a stochastic actor, a critic, off-policy training, and an entropy-regularized objective. It is not another name for natural gradients or PPO. In the finite-action setting, the discounted maximum-entropy target is

Jα(π)=Eπ∑t=0∞γt{Rt+1−αlog⁡π(At∣St)},α>0.J_\alpha(\pi)=\mathbb E_\pi\sum_{t=0}^\infty\gamma^t \{R_{t+1}-\alpha\log\pi(A_t\mid S_t)\},\qquad\alpha>0.

The conditional mean of −log⁡π(At∣St)-\log\pi(A_t\mid S_t) is the policy's entropy. To isolate one policy-improvement subproblem, hold a soft critic QwQ_w fixed at a state and consider the actor loss

Ls(π)=∑aπ(a∣s){αlog⁡π(a∣s)−Qw(s,a)}.\mathcal L_s(\pi) =\sum_a\pi(a\mid s)\{\alpha\log\pi(a\mid s)-Q_w(s,a)\}.

For finite actions, define Zw(s)=∑aexp⁡{Qw(s,a)/α}Z_w(s)=\sum_a\exp\{Q_w(s,a)/\alpha\} and pw(a∣s)=exp⁡{Qw(s,a)/α}/Zw(s)p_w(a\mid s)=\exp\{Q_w(s,a)/\alpha\}/Z_w(s). Direct substitution gives

Ls(π)=αDKL(π∥pw)−αlog⁡Zw(s).\mathcal L_s(\pi) =\alpha D_{\mathrm{KL}}(\pi\|p_w)-\alpha\log Z_w(s).

Nonnegativity of KL shows that unrestricted minimization chooses π=pw\pi=p_w. This is the finite-action counterpart of the soft policy-improvement projection in Haarnoja et al., Sections 4.1–4.2. Its critic is entropy-regularized; simply adding entropy to an update using an unchanged ordinary critic is not a derivation of the full SAC algorithm.

Entropy changes the policy-improvement targetFor fixed critic values (0,1,2), vertical probability bars show the exact categorical target softmax(Q divided by alpha). Alpha 0.25 concentrates on action three; alpha one spreads probability more broadly; alpha three is closer to uniform. Each row sums to one. This is a fixed-state analytical subproblem, not a SAC training result.Fixed critic Q = (0,1,2); target policy ∝ exp(Q / α)α = 0.25<0.0010.0180.982α = 10.0900.2450.665α = 30.2300.3210.448action 1action 2action 3Bar heights are probabilities, with the same vertical scale in every row.
Figure 7. Entropy changes the policy-improvement target. Original finite-action illustration of the soft policy-improvement projection in Haarnoja et al. (2018), Sections 4.1–4.2. Fixed Q = (0,1,2); rows are probability distributions, not measured performance. Source.

For continuous actions and a reparameterizable actor, let dDd_{\mathcal D} be the fixed distribution used to draw replay states (for uniform sampling from a buffer of mm states, dD=m−1∑j=1mδsjd_{\mathcal D}=m^{-1}\sum_{j=1}^m\delta_{s_j}). Draw S∼dDS\sim d_{\mathcal D} and independently ξ∼qξ\xi\sim q_\xi, a specified parameter-independent noise distribution, with gθ(s,ξ)∼πθ(⋅∣s)g_\theta(s,\xi)\sim\pi_\theta(\cdot\mid s). Hold the critic, buffer, and qξq_\xi fixed. The SAC-style actor objective is

L(θ)=ES∼dD, ξ∼qξ[αlog⁡πθ(gθ(S,ξ)∣S)−Qw(S,gθ(S,ξ))].\mathcal L(\theta) =\mathbb E_{S\sim d_{\mathcal D},\,\xi\sim q_\xi} \left[\alpha\log\pi_\theta(g_\theta(S,\xi)\mid S) -Q_w(S,g_\theta(S,\xi))\right].

Assuming differentiability and an integrable local bound that permits differentiation under the expectation, its pathwise derivative is

∇θL=ES∼dD, ξ∼qξ[αddθlog⁡πθ(gθ(S,ξ)∣S)−Dθgθ(S,ξ)⊤∇aQw(S,gθ(S,ξ))].\nabla_\theta\mathcal L =\mathbb E_{S\sim d_{\mathcal D},\,\xi\sim q_\xi}\left[ \alpha\frac{d}{d\theta}\log\pi_\theta(g_\theta(S,\xi)\mid S) -D_\theta g_\theta(S,\xi)^\top\nabla_aQ_w(S,g_\theta(S,\xi))\right].

The log density changes in two ways: its parameters change directly, and its action input changes through the sampled action. The total derivative includes both terms. This gives the actor-loss derivative in the SAC paper, Equations (12)–(13), with α\alpha written explicitly. Averaging this actor loss over stored states does not generally give the ordinary on-policy gradient of JJ.

9. An on-policy actor–critic template

For a compact algorithm, specialize to episodes that terminate after TT decisions, include decision time in the state, and set terminal value to zero. The continuing formulation above then represents the same problem with absorbing zero rewards after termination. Take unconstrained policy parameters in Rp\mathbb R^p.

Algorithm 1 On-policy actor–critic with GAE

Input: Initial policy parameters θ\theta and critic parameters ww; 0≤γ<10\le\gamma<1; 0≤λ≤10\le\lambda\le1; iterations B≥1B\ge1; n≥1n\ge1 episodes per iteration; positive actor learning rates ηr\eta_r.

Output: Fitted stochastic policy πθ\pi_\theta.

  1. for r=0,…,B−1r=0,\ldots,B-1 do
  2. Freeze the current actor θold←θ\theta_{\mathrm{old}}\gets\theta and critic wold←ww_{\mathrm{old}}\gets w.
  3. Collect nn independent complete episodes under πθold\pi_{\theta_{\mathrm{old}}}.
  4. for each episode ii do
  5. Set A^Ti←0\widehat A_{Ti}\gets0, GTi←0G_{Ti}\gets0, and Vwold(STi)←0V_{w_{\mathrm{old}}}(S_{Ti})\gets0 at the terminal state.
  6. for t=T−1,…,0t=T-1,\ldots,0 do
  7. Set δti←Rt+1,i+γVwold(St+1,i)−Vwold(Sti)\delta_{ti}\gets R_{t+1,i}+\gamma V_{w_{\mathrm{old}}}(S_{t+1,i})-V_{w_{\mathrm{old}}}(S_{ti}).
  8. Set A^ti←δti+γλA^t+1,i\widehat A_{ti}\gets\delta_{ti}+\gamma\lambda\widehat A_{t+1,i} and Gti←Rt+1,i+γGt+1,iG_{ti}\gets R_{t+1,i}+\gamma G_{t+1,i}.
  9. end for
  10. end for
  11. Compute g^←n−1∑i∑t=0T−1γt∇θlog⁡πθold(Ati∣Sti)A^ti\widehat g\gets n^{-1}\sum_i\sum_{t=0}^{T-1}\gamma^t\nabla_\theta\log\pi_{\theta_{\mathrm{old}}}(A_{ti}\mid S_{ti})\widehat A_{ti}, holding all advantages fixed.
  12. Update θ←θold+ηrg^\theta\gets\theta_{\mathrm{old}}+\eta_r\widehat g.
  13. Fit VwV_w to the fixed targets {(Sti,Gti)}\{(S_{ti},G_{ti})\}, retaining value zero at terminal states.
  14. end for
  15. return πθ\pi_\theta.

This is a simplified methodological template, not a reproduction of TRPO, PPO, or SAC. Advantages use the critic frozen before the current batch. For λ<1\lambda<1, critic approximation can bias the actor update; no general global-convergence guarantee is asserted. The factor γt\gamma^t retains the start-distribution discounted objective used in this article.

10. Connect the method to its assumptions

ChoiceWhat changesPrincipal qualification
REINFORCEEstimate action values using sampled returnsOn-policy sampling and complete returns for the displayed unbiased estimator
Actor–critic / GAEEstimate values or advantages using a critic and TD residualsApproximation error, baseline dependence, and rollout boundaries matter
Natural policy gradientUse the Fisher metric instead of Euclidean parameter lengthThe inverse formula needs a nonsingular metric
TRPOOptimize a local surrogate with a divergence constraintPractical average-KL optimization approximates the theoretical bound
PPOOptimize a clipped, sign-dependent surrogateClipping is not a hard probability-ratio or KL constraint
Deterministic policy gradientDifferentiate a smooth continuous-action actor through action valuesNot an argmax derivative for categorical actions; data-distribution correction remains separate
SAC-style stochastic actorOptimize an entropy-regularized critic objective, often pathwiseDifferent objective and critic; stochastic even with reparameterization

The offline-learning article separates data access from policy type. Neither an actor–critic label nor a single action-probability ratio automatically corrects the state distribution of arbitrary logged data.

References