Simple Algorithm
Reinforcement Learning · Fixed Point · 28 min

The Natural Policy Gradient

Fisher information, covariant updates and the link to policy iteration.

Plain gradient ascent is steepest ascent under a ruler nobody chose on purpose: the Euclidean length of the parameter change. The natural gradient picks the ruler deliberately, the KL divergence between action distributions, and inherits its invariances. This lesson derives the Fisher metric from the KL divergence, proves that the natural gradient ignores how the policy is parameterized, shows that for tabular softmax policies it becomes multiplicative weights on advantages, a soft form of policy iteration, proves its dimension-free rate, and explains how it is computed for networks with millions of parameters.

What you’ll learn

  • Show that the KL divergence between nearby policies is the quadratic form of the Fisher information, and derive the natural gradient as steepest ascent in that metric.
  • Prove that natural-gradient flow is invariant under smooth reparameterization, and say what the invariance does not cover.
  • Derive the tabular softmax update πt+1(a∣s)∝πt(a∣s)exp⁡(ηAπt(s,a)/(1−γ))\pi_{t+1}(a\mid s)\propto\pi_t(a\mid s)\exp\big(\eta A^{\pi_t}(s,a)/(1-\gamma)\big) and relate it to mirror descent and to policy iteration.
  • Prove the log⁡∣A∣ηT+1(1−γ)2T\frac{\log\abs{\mathcal A}}{\eta T}+\frac{1}{(1-\gamma)^2T} rate of natural policy gradient with a per-state regret argument.
  • Compute natural-gradient steps at scale with Fisher–vector products and conjugate gradient, and explain the Kronecker-factored approximation behind ACKTR.

KL divergence as a ruler

Fix a positive definite matrix GG and ask for the step that raises JJ most among steps of a given length in the metric GG. Maximizing ∇J⊤Δ\nabla J^\top\Delta subject to 12Δ⊤GΔ≤ε\tfrac12\Delta^\top G\Delta\le\varepsilon gives Δ∝G−1∇J\Delta\propto G^{-1}\nabla J; plain gradient ascent is the choice G=IG=I. Amari (1998) argued that for a family of probability distributions the right GG comes from the distributions themselves, and the KL divergence supplies it.

DerivationLocally, the KL divergence is the Fisher quadratic form
  1. DKL(pθ ∥ pθ+Δ)=−E[∇log⁡pθ]⊤Δ−12 Δ⊤E[∇2log⁡pθ]Δ+O(∥Δ∥3)\KL(p_{\boldsymbol\theta}\,\|\,p_{\boldsymbol\theta+\Delta})=-\E\big[\nabla\log p_{\boldsymbol\theta}\big]^\top\Delta-\tfrac12\,\Delta^\top\E\big[\nabla^2\log p_{\boldsymbol\theta}\big]\Delta+O\big(\norm{\Delta}^3\big)

    Expand DKL(pθ ∥ pθ+Δ)=Ex∼pθ[log⁡pθ(x)−log⁡pθ+Δ(x)]\KL(p_{\boldsymbol\theta}\,\|\,p_{\boldsymbol\theta+\Delta})=\E_{x\sim p_{\boldsymbol\theta}}\big[\log p_{\boldsymbol\theta}(x)-\log p_{\boldsymbol\theta+\Delta}(x)\big] to second order in Δ\Delta:

  2. −E[∇2log⁡pθ]=E[∇log⁡pθ ∇log⁡pθ⊤]=F(θ)-\E\big[\nabla^2\log p_{\boldsymbol\theta}\big]=\E\big[\nabla\log p_{\boldsymbol\theta}\,\nabla\log p_{\boldsymbol\theta}^\top\big]=F(\boldsymbol\theta)

    The linear term vanishes because the score has mean zero. For the quadratic term, ∇2log⁡p=∇2p/p−∇log⁡p ∇log⁡p⊤\nabla^2\log p=\nabla^2p/p-\nabla\log p\,\nabla\log p^\top, and E[∇2p/p]=∇2∑xp(x)=0\E[\nabla^2p/p]=\nabla^2\sum_xp(x)=0:

  3. DKL(pθ ∥ pθ+Δ)=12 Δ⊤F(θ) Δ+O(∥Δ∥3)\KL(p_{\boldsymbol\theta}\,\|\,p_{\boldsymbol\theta+\Delta})=\tfrac12\,\Delta^\top F(\boldsymbol\theta)\,\Delta+O\big(\norm{\Delta}^3\big)

    Hence the KL divergence to a nearby distribution is half the Fisher quadratic form. The reverse divergence DKL(pθ+Δ ∥ pθ)\KL(p_{\boldsymbol\theta+\Delta}\,\|\,p_{\boldsymbol\theta}) has the same expansion; the two directions first differ at third order.

A policy is a family of distributions, one per state, so its metric averages the per-state Fisher matrices Fs(θ)=EA∼πθ(⋅∣s)[ψψ⊤]F_s(\boldsymbol\theta)=\E_{A\sim\pi_{\boldsymbol\theta}(\cdot\mid s)}[\boldsymbol\psi\boldsymbol\psi^\top], with the score ψ=∇log⁡πθ(A∣s)\boldsymbol\psi=\nabla\log\pi_{\boldsymbol\theta}(A\mid s), over a state distribution: F(θ)=ES∼d[FS(θ)]F(\boldsymbol\theta)=\E_{S\sim d}\big[F_S(\boldsymbol\theta)\big]. Kakade (2001) used the stationary distribution of an average-reward problem, Agarwal et al. (2021) the discounted distribution dρπθd^{\pi_{\boldsymbol\theta}}_\rho, and TRPO simply the states in the batch. The natural policy gradient is F(θ)†∇J(θ)F(\boldsymbol\theta)^{\dagger}\nabla J(\boldsymbol\theta), with the Moore–Penrose pseudoinverse because FF is often singular: adding a constant to every logit of a softmax changes nothing, and a policy that has become nearly deterministic has a nearly vanishing score. In his experiments Kakade added about 10−3I10^{-3}I to FF at every step for that reason.

The state weighting has a cleaner justification than it looks. Bagnell and Schneider (2003) built the metric from the distribution over whole trajectories, and for episodes the two agree: the trajectory's score is ∑tψt\sum_t\boldsymbol\psi_t, the transition probabilities do not depend on θ\boldsymbol\theta, and the cross terms vanish because E[ψt′∣S0,A0,…,St′]=0\E[\boldsymbol\psi_{t'}\mid S_0,A_0,\dots,S_{t'}]=\mathbf 0 for t<t′t<t':

Ftraj(θ)=E[(∑tψt)(∑t′ψt′) ⁣⊤]=E[∑tψtψt⊤]=∑sη(s) Fs(θ)F_{\text{traj}}(\boldsymbol\theta)=\E\Big[\Big(\sum_t\boldsymbol\psi_t\Big)\Big(\sum_{t'}\boldsymbol\psi_{t'}\Big)^{\!\top}\Big]=\E\Big[\sum_t\boldsymbol\psi_t\boldsymbol\psi_t^\top\Big]=\sum_s\eta(s)\,F_s(\boldsymbol\theta)
η(s)\eta(s) is the expected number of visits to ss per episode. The trajectory metric is the state-averaged Fisher under the on-policy distribution, scaled by the expected episode length.
Predict before you look

For a Gaussian policy with mean mm and log standard deviation log⁡σ\log\sigma, the Fisher matrix in the coordinates (m,log⁡σ)(m,\log\sigma) is diag⁡(1/σ2, 2)\operatorname{diag}(1/\sigma^2,\,2). A trust-region step with KL budget δ=0.01\delta=0.01 moves only the mean. How far can the mean move when σ=0.05\sigma=0.05?

Show the answer

0.0071

The budget is 12Δm2/σ2=δ\tfrac12\Delta m^2/\sigma^2=\delta, so Δm=σ2δ=0.05×0.1414≈0.0071\Delta m=\sigma\sqrt{2\delta}=0.05\times0.1414\approx0.0071. The natural step in the mean scales with σ\sigma: as the policy sharpens, its steps shrink automatically, exactly enough to keep the change in behavior fixed. The plain gradient does the opposite: ∂log⁡π/∂m=(a−m)/σ2\partial\log\pi/\partial m=(a-m)/\sigma^2, so its steps in mm grow as σ\sigma shrinks.

Invariance under reparameterization

DerivationProof
  1. ∇ζlog⁡π=J⊤∇θlog⁡π,∇ζJ=J⊤∇θJ,Fζ=J⊤Fθ J\nabla_{\boldsymbol\zeta}\log\pi=\mathcal J^\top\nabla_{\boldsymbol\theta}\log\pi,\qquad\nabla_{\boldsymbol\zeta}J=\mathcal J^\top\nabla_{\boldsymbol\theta}J,\qquad F_{\boldsymbol\zeta}=\mathcal J^\top F_{\boldsymbol\theta}\,\mathcal J

    By the chain rule the score and the gradient pick up the Jacobian, so the Fisher matrix picks it up twice:

  2. J ζ˙=J(J−1Fθ−1J−⊤)J⊤∇θJ=Fθ−1∇θJ\mathcal J\,\dot{\boldsymbol\zeta}=\mathcal J\big(\mathcal J^{-1}F_{\boldsymbol\theta}^{-1}\mathcal J^{-\top}\big)\mathcal J^\top\nabla_{\boldsymbol\theta}J=F_{\boldsymbol\theta}^{-1}\nabla_{\boldsymbol\theta}J

    Map the ζ\boldsymbol\zeta-velocity of the natural flow into θ\boldsymbol\theta-coordinates; the Jacobians cancel:

  3. Both flows solve the same differential equation in θ\boldsymbol\theta, so from the same starting policy they produce the same policies at every time. The plain flow instead gives Jζ˙=JJ⊤∇θJ\mathcal J\dot{\boldsymbol\zeta}=\mathcal J\mathcal J^\top\nabla_{\boldsymbol\theta}J, which equals ∇θJ\nabla_{\boldsymbol\theta}J only when J\mathcal J is orthogonal. ■\blacksquare

Kakade (2001) illustrated the point on a one-dimensional linear–quadratic regulator, rescaling the units of one parameter or the other by a factor of 10: the natural gradient reached a good controller about three orders of magnitude sooner than the plain gradient. Its curves under the different rescalings were not identical either, which Kakade attributed to the state weighting inside FF. A classical result explains why the Fisher matrix is the metric to use: by Chentsov's theorem for distributions over a finite set it is, up to scale, the only Riemannian metric that is invariant under sufficient statistics.

Three limits of the invariance matter in practice. It holds for the flow; a finite step is invariant only to first order, which is one reason TRPO checks its steps with a line search. It concerns coordinates within one family of policies, not the choice of the family. And the natural gradient is not Newton's method: FF is the curvature of the KL divergence, not of JJ. Kakade noted that the Hessian of JJ couples the curvature of π\pi to the action values and is generally indefinite away from a maximum, while FF is positive semidefinite everywhere.

Tabular softmax: multiplicative weights on advantages

Take the tabular softmax policy πθ(a∣s)∝eθs,a\pi_{\boldsymbol\theta}(a\mid s)\propto e^{\theta_{s,a}}, exact gradients of Vπ(ρ)V^{\pi}(\rho), and the Fisher matrix weighted by dρπd^{\pi}_\rho. Global Convergence of Policy Gradients states the resulting update; here is where it comes from (Kakade, 2001; Agarwal, Kakade, Lee & Mahajan, 2021, Lemma 15).

DerivationThe state distribution cancels
  1. ∂Vπ(ρ)∂θs,a=11−γ dρπ(s) π(a∣s) Aπ(s,a)\frac{\partial V^{\pi}(\rho)}{\partial\theta_{s,a}}=\frac{1}{1-\gamma}\,d^{\pi}_\rho(s)\,\pi(a\mid s)\,A^{\pi}(s,a)

    The score is ∂log⁡π(a′∣s′)/∂θs,a=1[s′=s](1[a′=a]−π(a∣s))\partial\log\pi(a'\mid s')/\partial\theta_{s,a}=\mathbb 1[s'=s]\big(\mathbb 1[a'=a]-\pi(a\mid s)\big). By the policy gradient theorem, using ∑a′π(a′∣s)Qπ(s,a′)=Vπ(s)\sum_{a'}\pi(a'\mid s)Q^\pi(s,a')=V^\pi(s):

  2. Fs=dρπ(s)(diag⁡(πs)−πsπs⊤),∇θsVπ(ρ)=dρπ(s)1−γ(diag⁡(πs)−πsπs⊤)Aπ(s,⋅)F_{s}=d^{\pi}_\rho(s)\big(\operatorname{diag}(\pi_s)-\pi_s\pi_s^\top\big),\qquad\nabla_{\boldsymbol\theta_s}V^\pi(\rho)=\frac{d^{\pi}_\rho(s)}{1-\gamma}\big(\operatorname{diag}(\pi_s)-\pi_s\pi_s^\top\big)A^\pi(s,\cdot)

    The Fisher matrix has no blocks across states, and its block for state ss is dρπ(s)d^\pi_\rho(s) times the covariance matrix of a one-hot draw from πs=π(⋅∣s)\pi_s=\pi(\cdot\mid s). Because πs⊤Aπ(s,⋅)=0\pi_s^\top A^\pi(s,\cdot)=0, the gradient block has the same form:

  3. ws=11−γAπ(s,⋅)+cs1⟹πt+1(a∣s)=πt(a∣s) exp⁡(ηAπt(s,a)/(1−γ))Zt(s)\mathbf w_s=\frac{1}{1-\gamma}A^\pi(s,\cdot)+c_s\mathbf 1\qquad\Longrightarrow\qquad\pi_{t+1}(a\mid s)=\frac{\pi_t(a\mid s)\,\exp\big(\eta A^{\pi_t}(s,a)/(1-\gamma)\big)}{Z_t(s)}

    For every state with dρπ(s)>0d^\pi_\rho(s)>0, Fsws=∇θsVF_s\mathbf w_s=\nabla_{\boldsymbol\theta_s}V is solved by the advantages up to the null direction 1\mathbf 1 of diag⁡(πs)−πsπs⊤\operatorname{diag}(\pi_s)-\pi_s\pi_s^\top. The visitation weight cancels, and a constant added to a state's logits does not change its policy:

Three readings of the same update:

  • Multiplicative weights. Each state runs Hedge (exponential weights) with gains Aπt(s,⋅)/(1−γ)A^{\pi_t}(s,\cdot)/(1-\gamma). No state's step is scaled down by how rarely it is visited, which is precisely what plain softmax policy gradient suffers from.
  • Mirror descent. In each state, πt+1(⋅∣s)=arg max⁡p{η1−γ p⊤Qπt(s,⋅)−DKL(p ∥ πt(⋅∣s))}\pi_{t+1}(\cdot\mid s)=\argmax_{p}\big\{\tfrac{\eta}{1-\gamma}\,p^\top Q^{\pi_t}(s,\cdot)-\KL\big(p\,\|\,\pi_t(\cdot\mid s)\big)\big\}: a linear model of improvement, held close to the current policy by a KL proximity term. This is policy mirror descent, the template TRPO and PPO approximate.
  • Soft policy iteration. As η→∞\eta\to\infty the update puts all mass on arg max⁡aAπt(s,a)\argmax_aA^{\pi_t}(s,a): policy iteration. Kakade (2001, Theorem 2) proved the general form for exponential-family policies, where the limit is greedy with respect to the compatible critic's estimate of the advantage (exact in the tabular case). With entropy regularization of weight τ\tau, the step η=(1−γ)/τ\eta=(1-\gamma)/\tau gives exactly soft policy iteration, πt+1∝exp⁡(Qτπt/τ)\pi_{t+1}\propto\exp\big(Q^{\pi_t}_\tau/\tau\big) (Cen et al., 2022).
Predict before you look

Use the closed form in the caption. At which iteration does the natural gradient's suboptimality first fall below 10−410^{-4}? (Check your answer in the widget.)

Show the answer

173

For large tt the third arm is gone and the suboptimality is about 0.1e−0.04t/(1+e−0.04t)0.1e^{-0.04t}/(1+e^{-0.04t}). Setting 0.1e−0.04t≈10−40.1e^{-0.04t}\approx10^{-4} gives t≈ln⁡(1000)/0.04≈172.7t\approx\ln(1000)/0.04\approx172.7, and the exact formula crosses at iteration 173 (below 10−610^{-6} at 288). The plain gradient needs 16,869 iterations to reach 10−410^{-4} from the same start.

A dimension-free rate, by a regret argument

DerivationProof: Hedge in every state, paid for by improvement
  1. η1−γ A(t)(s,a)=log⁡πt+1(a∣s)πt(a∣s)+log⁡Zt(s)\frac{\eta}{1-\gamma}\,A^{(t)}(s,a)=\log\frac{\pi_{t+1}(a\mid s)}{\pi_t(a\mid s)}+\log Z_t(s)

    Write πt,s=πt(⋅∣s)\pi_{t,s}=\pi_t(\cdot\mid s), A(t)=AπtA^{(t)}=A^{\pi_t}, V(t)=VπtV^{(t)}=V^{\pi_t} and d⋆=dρπ⋆d^\star=d^{\pi^\star}_\rho. Taking logs of the update turns advantages into log-ratios of consecutive policies:

  2. V⋆(ρ)−V(t)(ρ)=11−γEs∼d⋆[∑aπ⋆(a∣s)A(t)(s,a)]=1η Es∼d⋆[DKL(πs⋆∥πt,s)−DKL(πs⋆∥πt+1,s)+log⁡Zt(s)]V^\star(\rho)-V^{(t)}(\rho)=\frac{1}{1-\gamma}\E_{s\sim d^\star}\Big[\sum_a\pi^\star(a\mid s)A^{(t)}(s,a)\Big]=\frac1\eta\,\E_{s\sim d^\star}\Big[\KL(\pi^\star_s\|\pi_{t,s})-\KL(\pi^\star_s\|\pi_{t+1,s})+\log Z_t(s)\Big]

    Regret side. The performance difference lemma compares π⋆\pi^\star with πt\pi_t under π⋆\pi^\star's state distribution. Averaged under πs⋆\pi^\star_s, the log-ratios telescope into KL divergences, exactly as in the analysis of Hedge:

  3. V(t+1)(ν)−V(t)(ν)=1ηEs∼dνπt+1[DKL(πt+1,s∥πt,s)+log⁡Zt(s)] ≥ 1−γη Es∼νlog⁡Zt(s) ≥ 0V^{(t+1)}(\nu)-V^{(t)}(\nu)=\frac1\eta\E_{s\sim d^{\pi_{t+1}}_\nu}\Big[\KL(\pi_{t+1,s}\|\pi_{t,s})+\log Z_t(s)\Big]\ \ge\ \frac{1-\gamma}{\eta}\,\E_{s\sim\nu}\log Z_t(s)\ \ge\ 0

    Improvement side. Apply the lemma to πt+1\pi_{t+1} against πt\pi_t from any start distribution ν\nu. Averaged under πt+1\pi_{t+1}, the log-ratios give a nonnegative KL term, and log⁡Zt(s)≥η1−γ∑aπt(a∣s)A(t)(s,a)=0\log Z_t(s)\ge\frac{\eta}{1-\gamma}\sum_a\pi_t(a\mid s)A^{(t)}(s,a)=0 by Jensen's inequality. Since dνπt+1≥(1−γ)νd^{\pi_{t+1}}_\nu\ge(1-\gamma)\nu:

  4. V⋆(ρ)−V(T)(ρ) ≤ 1T∑t<T(V⋆(ρ)−V(t)(ρ)) ≤ log⁡∣A∣ηT+11−γ⋅1(1−γ) TV^\star(\rho)-V^{(T)}(\rho)\ \le\ \frac1T\sum_{t<T}\big(V^\star(\rho)-V^{(t)}(\rho)\big)\ \le\ \frac{\log\abs{\mathcal A}}{\eta T}+\frac{1}{1-\gamma}\cdot\frac{1}{(1-\gamma)\,T}

    Values never decrease, in any state (take ν\nu a point mass), and with ν=d⋆\nu=d^\star the log⁡Zt\log Z_t terms are bounded by the increase of V(d⋆)V(d^\star). Sum over t<Tt<T: the KL terms telescope to at most DKL(πs⋆∥uniform)≤log⁡∣A∣\KL(\pi^\star_s\|\text{uniform})\le\log\abs{\mathcal A}, the increases add up to at most V(T)(d⋆)−V(0)(d⋆)≤11−γV^{(T)}(d^\star)-V^{(0)}(d^\star)\le\frac{1}{1-\gamma}, and monotonicity puts the last iterate below the average. ■\blacksquare

In the adversarial analysis of Hedge, the log⁡Zt\log Z_t terms are bounded by a variance term of order η\eta per round, which forces a step size of order 1/T1/\sqrt T and an average regret of order 1/T1/\sqrt T. Here they are charged instead to the guaranteed improvement of the policy's own values, a structural fact about MDPs, so every step size works and the rate is 1/T1/T.

The bound is a worst case. From the uniform start in the widget's bandit it gives (log⁡3/0.4+1)/T≈3.75/T(\log3/0.4+1)/T\approx3.75/T, about 0.070.07 at T=55T=55, when the actual suboptimality is already below 0.010.01 and falling like e−0.04te^{-0.04t}. Faster guarantees exist: linear convergence with entropy regularization (Cen, Cheng, Chen, Wei & Chi, 2022; stated in Global Convergence of Policy Gradients) and, with no regularization at all, with geometrically increasing step sizes, which move the update toward policy iteration (Xiao, 2022).

Natural gradients for networks

For a network with nn parameters, FF is an n×nn\times n matrix: storing it, let alone inverting it, is out of the question when nn runs into the millions. Two routes avoid it.

Matrix-free: conjugate gradient. Conjugate gradient solves Fx=gF\mathbf x=\mathbf g using only products FvF\mathbf v. Because FF is the Hessian of the mean KL divergence at θold\boldsymbol\theta_{\text{old}}, FvF\mathbf v is a Hessian–vector product: differentiate the KL's gradient along v\mathbf v (double backpropagation), for a small multiple of the cost of one gradient. TRPO used this analytic Fisher, which averages over all actions in each visited state rather than using only the sampled one. In RL the sampled estimate E^[ψψ⊤]\hat\E[\boldsymbol\psi\boldsymbol\psi^\top] is unbiased too, because the actions come from the policy itself, unlike the "empirical Fisher" of supervised learning, which uses the data's labels instead of the model's own samples.

python
import torch
from torch.distributions import Categorical, kl_divergence

def fvp(policy_net, states, v, damping=0.1):
    """(F + damping*I) v, with F the Hessian of the mean KL(pi_old || pi) at theta_old."""
    params = list(policy_net.parameters())
    logits = policy_net(states)
    kl = kl_divergence(Categorical(logits=logits.detach()), Categorical(logits=logits)).mean()
    grads = torch.autograd.grad(kl, params, create_graph=True)   # zero at theta_old
    g_dot_v = torch.cat([g.reshape(-1) for g in grads]) @ v
    hv = torch.autograd.grad(g_dot_v, params)                    # differentiate again
    return torch.cat([h.reshape(-1) for h in hv]) + damping * v

def conjugate_gradient(Av, b, iters=10, tol=1e-10):
    x, r, p = torch.zeros_like(b), b.clone(), b.clone()
    rr = r @ r
    for _ in range(iters):
        Ap = Av(p)
        alpha = rr / (p @ Ap)
        x, r = x + alpha * p, r - alpha * Ap
        rr_new = r @ r
        if rr_new < tol:
            break
        p, rr = r + (rr_new / rr) * p, rr_new
    return x        # natural direction: conjugate_gradient(lambda v: fvp(net, s, v), g)

The detached copy of the logits plays πold\pi_{\text{old}}, so the KL and its gradient vanish at the current parameters while the second derivative gives the Fisher matrix. Damping (F+λIF+\lambda I) guards against a singular or badly estimated FF. Ten iterations, TRPO's choice, are typical: an approximate solve suffices, since g\mathbf g and FF are themselves estimated from one batch.

Structured: K-FAC. Martens and Grosse (2015) approximate FF by a block-diagonal matrix with one block per layer, each factored into two small matrices. For a layer s=Wa\mathbf s=W\mathbf a with input activations a\mathbf a and backpropagated derivatives g=∇slog⁡π\mathbf g=\nabla_{\mathbf s}\log\pi, the gradient is ga⊤\mathbf g\mathbf a^\top, and the block's expectation is split as if the two were uncorrelated:

FW=E[aa⊤⊗gg⊤] ≈ E[aa⊤]⏟A⊗E[gg⊤]⏟S,ΔW=S−1(∇WJ)A−1F_W=\E\big[\mathbf a\mathbf a^\top\otimes\mathbf g\mathbf g^\top\big]\ \approx\ \underbrace{\E\big[\mathbf a\mathbf a^\top\big]}_{A}\otimes\underbrace{\E\big[\mathbf g\mathbf g^\top\big]}_{S},\qquad\Delta W=S^{-1}\big(\nabla_WJ\big)A^{-1}
Inverting a Cin×CinC_{\text{in}}\times C_{\text{in}} and a Cout×CoutC_{\text{out}}\times C_{\text{out}} matrix replaces inverting one of size CinCoutC_{\text{in}}C_{\text{out}}. Damping and running averages of AA and SS keep the factors well conditioned.

ACKTR (Wu, Mansimov, Liao, Grosse & Ba, 2017) applied K-FAC to both the actor and the critic (for a critic with a Gaussian output, the Gauss–Newton matrix is its Fisher matrix) and capped each step with a trust region, η=min⁡(ηmax⁡,2δ/Δθ⊤F^Δθ)\eta=\min\big(\eta_{\max},\sqrt{2\delta/\Delta\boldsymbol\theta^\top\hat F\Delta\boldsymbol\theta}\big). The authors reported 2- to 3-fold gains in sample efficiency over earlier on-policy actor–critic methods on Atari and MuJoCo, at 10–25% more computation per update than first-order methods.

Key takeaways

  • The KL divergence between nearby policies is 12Δ⊤FΔ\tfrac12\Delta^\top F\Delta in either direction, with FF the state-averaged covariance of the score; steepest ascent in this metric is the natural gradient F†∇JF^\dagger\nabla J.
  • Natural-gradient flow traces the same policies in any smooth reparameterization; finite steps are invariant only to first order, and FF is the curvature of the KL divergence, not of JJ.
  • For tabular softmax policies the state weighting cancels and the update is multiplicative weights on advantages, πt+1∝πtexp⁡(ηAπt/(1−γ))\pi_{t+1}\propto\pi_t\exp\big(\eta A^{\pi_t}/(1-\gamma)\big): policy mirror descent, policy iteration as η→∞\eta\to\infty, and soft policy iteration with entropy at η=(1−γ)/τ\eta=(1-\gamma)/\tau.
  • Natural policy gradient reaches log⁡∣A∣ηT+1(1−γ)2T\frac{\log\abs{\mathcal A}}{\eta T}+\frac{1}{(1-\gamma)^2T} for every step size: Hedge's regret in each state, with the normalization terms paid for by monotone improvement.
  • At scale, F−1gF^{-1}\mathbf g is computed without forming FF, by conjugate gradient on Fisher–vector products (TRPO), or through Kronecker-factored layer blocks (K-FAC, ACKTR).

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

For nearby parameters, how do DKL(πθ ∥ πθ+Δ)\KL(\pi_{\boldsymbol\theta}\,\|\,\pi_{\boldsymbol\theta+\Delta}) and DKL(πθ+Δ ∥ πθ)\KL(\pi_{\boldsymbol\theta+\Delta}\,\|\,\pi_{\boldsymbol\theta}) compare?

  1. They differ already at first order in Δ\Delta, which is why TRPO must pick the direction carefully
  2. Both equal 12Δ⊤FΔ\tfrac12\Delta^\top F\Delta up to third-order terms, so the choice of direction does not affect the local metric
  3. The first is 12Δ⊤FΔ\tfrac12\Delta^\top F\Delta and the second Δ⊤FΔ\Delta^\top F\Delta
  4. They are equal for all Δ\Delta, because the KL divergence is symmetric
Show the answer

B. Both equal 12Δ⊤FΔ\tfrac12\Delta^\top F\Delta up to third-order terms, so the choice of direction does not affect the local metric

Both vanish with zero gradient at Δ=0\Delta=0, and both have Hessian FF there, so they agree to second order. They differ at third order, which matters for large steps but not for the natural-gradient direction.

Question 2

Why is the tabular softmax natural policy gradient update independent of the state distribution dρπd^{\pi}_\rho, while the plain softmax gradient is not?

  1. Because natural policy gradient uses a uniform state distribution by definition
  2. Because the advantages already contain the factor dρπ(s)d^{\pi}_\rho(s)
  3. Because the pseudoinverse discards every state's block except the most visited one
  4. Because the gradient for state ss and the Fisher block for state ss both carry the factor dρπ(s)d^{\pi}_\rho(s), so it cancels in F†∇VF^\dagger\nabla V
Show the answer

D. Because the gradient for state ss and the Fisher block for state ss both carry the factor dρπ(s)d^{\pi}_\rho(s), so it cancels in F†∇VF^\dagger\nabla V

The gradient block is d(s)1−γ(diag⁡πs−πsπs⊤)As\frac{d(s)}{1-\gamma}(\operatorname{diag}\pi_s-\pi_s\pi_s^\top)A_s and the Fisher block is d(s)(diag⁡πs−πsπs⊤)d(s)(\operatorname{diag}\pi_s-\pi_s\pi_s^\top). Solving block by block leaves As/(1−γ)A_s/(1-\gamma) plus a constant, for every visited state, so rarely visited states are updated as aggressively as common ones.

Question 3

In tabular natural policy gradient, πt+1(a∣s)∝πt(a∣s)exp⁡(ηAπt(s,a)/(1−γ))\pi_{t+1}(a\mid s)\propto\pi_t(a\mid s)\exp\big(\eta A^{\pi_t}(s,a)/(1-\gamma)\big). What does the update become as η→∞\eta\to\infty?

  1. Policy iteration: each state puts all its probability on its greedy actions arg max⁡aAπt(s,a)\argmax_aA^{\pi_t}(s,a)
  2. Plain policy gradient with an infinite step, which diverges
  3. The uniform policy, since all exponentials blow up together
  4. Value iteration on QπtQ^{\pi_t}
Show the answer

A. Policy iteration: each state puts all its probability on its greedy actions arg max⁡aAπt(s,a)\argmax_aA^{\pi_t}(s,a)

The largest advantage dominates the exponentials, so the normalized policy concentrates on the greedy actions: exactly a policy-improvement step. Finite η\eta interpolates between a slow, smooth update and policy iteration, which is the sense in which trust-region methods are "soft" policy iteration.

Question 4

What approximation lets K-FAC invert the Fisher block of a layer with weight matrix W∈RCout×CinW\in\R^{C_{\text{out}}\times C_{\text{in}}} cheaply?

  1. It keeps only the diagonal of the Fisher matrix
  2. It replaces the Fisher matrix by the identity, as in plain gradient descent
  3. It assumes the layer's input activations and backpropagated output derivatives are uncorrelated at second order, so the block factors as E[aa⊤]⊗E[gg⊤]\E[\mathbf a\mathbf a^\top]\otimes\E[\mathbf g\mathbf g^\top] and inverts through the two small factors
  4. It computes the exact inverse by conjugate gradient at every step
Show the answer

C. It assumes the layer's input activations and backpropagated output derivatives are uncorrelated at second order, so the block factors as E[aa⊤]⊗E[gg⊤]\E[\mathbf a\mathbf a^\top]\otimes\E[\mathbf g\mathbf g^\top] and inverts through the two small factors

The exact block is E[aa⊤⊗gg⊤]\E[\mathbf a\mathbf a^\top\otimes\mathbf g\mathbf g^\top]. Factoring the expectation gives A⊗SA\otimes S, whose inverse is A−1⊗S−1A^{-1}\otimes S^{-1}, so the update is S−1(∇WJ)A−1S^{-1}(\nabla_WJ)A^{-1}: two matrices of size CinC_{\text{in}} and CoutC_{\text{out}} instead of one of size CinCoutC_{\text{in}}C_{\text{out}}. Blocks for different layers are treated as independent.

Further reading

  • S. Amari, "Natural gradient works efficiently in learning," Neural Computation 10(2), 251–276 (1998).
  • S. M. Kakade, "A natural policy gradient," NIPS 14 (2001).
  • A. Agarwal, S. M. Kakade, J. D. Lee & G. Mahajan, "On the theory of policy gradient methods: Optimality, approximation, and distribution shift," JMLR 22(98), 1–76 (2021).
  • J. Martens & R. Grosse, "Optimizing neural networks with Kronecker-factored approximate curvature," ICML (2015).
  • Y. Wu, E. Mansimov, S. Liao, R. Grosse & J. Ba, "Scalable trust-region method for deep reinforcement learning using Kronecker-factored approximation," NIPS (2017).