Policy gradient methods are a class of reinforcement learning algorithms and a sub-class of policy optimization methods. Unlike value-based methods which learn a value function to derive a policy, policy optimization methods directly learn a policy function π that selects actions without consulting a value function. For policy gradient to apply, the policy function πθ is parameterized by a differentiable parameter θ.
Overview In policy-based RL, the actor is a parameterized policy function πθ, where θ are the parameters of the actor. The actor takes as argument the state of the environment s and produces a probability distribution πθ(⋅∣s). If the action space is discrete, then ∑aπθ(a∣s)=1. If the action space is continuous, then ∫aπθ(a∣s)da=1. The goal of policy optimization is to find some θ that maximizes the expected episodic reward J(θ):J(θ)=𝔼πθ[∑t=0TγtRt|S0=s0]where γ is the discount factor, Rt is the reward at step t, s0 is the starting state, and T is the time-horizon (which can be infinite). The policy gradient is defined as ∇θJ(θ). Different policy gradient methods stochastically estimate the policy gradient in different ways. The goal of any policy gradient method is to iteratively maximize J(θ) by gradient ascent. Since the key part of any policy gradient method is the stochastic estimation of the policy gradient, they are also studied under the title of "Monte Carlo gradient estimation".
REINFORCE
Policy gradient The REINFORCE algorithm, introduced by Ronald J. Williams in 1992, was the first policy gradient method. It is based on the identity for the policy gradient∇θJ(θ)=𝔼πθ[∑t=0T∇θlnπθ(At∣St)∑t=0T(γtRt)|S0=s0] which can be improved via the "causality trick", i.e. by only weighting each action by rewards from that timestep onward,∇θJ(θ)=𝔼πθ[∑t=0T∇θlnπθ(At∣St)∑τ=tT(γτRτ)|S0=s0]
Thus, we have an unbiased estimator of the policy gradient:∇θJ(θ)≈1N∑n=1N[∑t=0T∇θlnπθ(At,n∣St,n)∑τ=tT(γτ−tRτ,n)]where the index n ranges over N rollout trajectories using the policy πθ. The score function ∇θlnπθ(At∣St) can be interpreted as the direction in the parameter space that increases the probability of taking action At in state St. The policy gradient, then, is a weighted average of all possible directions to increase the probability of taking any action in any state, but weighted by reward signals, so that if taking a certain action in a certain state is associated with high reward, then that direction would be highly reinforced, and vice versa.
Algorithm The REINFORCE algorithm is a loop:
Rollout N trajectories in the environment, using πθt as the policy function. Compute the policy gradient estimation: gi←1N∑n=1N[∑t=0T∇θtlnπθ(At,n∣St,n)∑τ=tT(γτRτ,n)] Update the policy by gradient ascent: θi+1←θi+αigi Here, αi is the learning rate at update step i.
Variance reduction REINFORCE is an on-policy algorithm, meaning that the trajectories used for the update must be sampled from the current policy πθ. This can lead to high variance in the updates, as the returns R(τ) can vary significantly between trajectories. Many variants of REINFORCE have been introduced, under the title of variance reduction.
REINFORCE with baseline A common way for reducing variance is the REINFORCE with baseline algorithm, based on the following identity:∇θJ(θ)=𝔼πθ[∑t=0T∇θlnπθ(At|St)(∑τ=tT(γτRτ)−b(St))|S0=s0]for any function b:States→ℝ. This can be proven by applying the previous lemma. The algorithm uses the modified gradient estimatorgi←1N∑n=1N[∑t=0T∇θtlnπθ(At,n|St,n)(∑τ=tT(γτRτ,n)−bi(St,n))] and the original REINFORCE algorithm is the special case where bi≡0.
Actor-critic methods
If bi is chosen well, such that bi(St)≈∑τ=tT(γτRτ)=γtVπθi(St), this could significantly decrease variance in the gradient estimation. That is, the baseline should be as close to the value function Vπθi(St) as possible, approaching the ideal of:∇θJ(θ)=𝔼πθ[∑t=0T∇θlnπθ(At|St)(∑τ=tT(γτRτ)−γtVπθ(St))|S0=s0]Note that, as the policy πθt updates, the value function Vπθi(St) updates as well, so the baseline should also be updated. One common approach is to train a separate function that estimates the value function, and use that as the baseline. This is one of the actor-critic methods, where the policy function is the actor and the value function is the critic. The Q-function Qπ can also be used as the critic, since∇θJ(θ)=Eπθ[∑0≤t≤Tγt∇θlnπθ(At|St)⋅Qπθ(St,At)|S0=s0] by a similar argument using the tower law. Subtracting the value function as a baseline, we find that the advantage function Aπ(S,A)=Qπ(S,A)−Vπ(S) can be used as the critic as well:∇θJ(θ)=Eπθ[∑0≤t≤Tγt∇θlnπθ(At|St)⋅Aπθ(St,At)|S0=s0]In summary, there are many unbiased estimators for ∇θJθ, all in the form of: ∇θJ(θ)=Eπθ[∑0≤t≤T∇θlnπθ(At|St)⋅Ψt|S0=s0] where Ψt is any linear sum of the following terms:
∑0≤τ≤T(γτRτ): never used. γt∑t≤τ≤T(γτ−tRτ): used by the REINFORCE algorithm. γt∑t≤τ≤T(γτ−tRτ)−b(St): used by the REINFORCE with baseline algorithm. γt(Rt+γVπθ(St+1)−Vπθ(St)): 1-step TD learning. γtQπθ(St,At). γtAπθ(St,At). Some more possible Ψt are as follows, with very similar proofs.
γt(Rt+γRt+1+γ2Vπθ(St+2)−Vπθ(St)): 2-step TD learning. γt(∑k=0n−1γkRt+k+γnVπθ(St+n)−Vπθ(St)): n-step TD learning. γt∑n=1∞λn−11−λ⋅(∑k=0n−1γkRt+k+γnVπθ(St+n)−Vπθ(St)): TD(λ) learning, also known as GAE (generalized advantage estimate). This is obtained by an exponentially decaying sum of the n-step TD learning ones.
Natural policy gradient
The natural policy gradient method is a variant of the policy gradient method, proposed by Sham Kakade in 2001. Unlike standard policy gradient methods, which depend on the choice of parameters θ (making updates coordinate-dependent), the natural policy gradient aims to provide a coordinate-free update, which is geometrically "natural".
Motivation Standard policy gradient updates θi+1=θi+α∇θJ(θi) solve a constrained optimization problem:{maxθi+1J(θi)+(θi+1−θi)T∇θJ(θi)‖θi+1−θi‖≤α⋅‖∇θJ(θi)‖ While the objective (linearized improvement) is geometrically meaningful, the Euclidean constraint ‖θi+1−θi‖ introduces coordinate dependence. To address this, the natural policy gradient replaces the Euclidean constraint with a Kullback–Leibler divergence (KL) constraint:{maxθi+1J(θi)+(θi+1−θi)T∇θJ(θi)D¯KL(πθi+1‖πθi)≤ϵwhere the KL divergence between two policies is averaged over the state distribution under policy πθi. That is,D¯KL(πθi+1‖πθi):=𝔼s∼πθi[DKL(πθi+1(⋅|s)‖πθi(⋅|s))] This ensures updates are invariant to invertible affine parameter transformations.
… excerpt ends here. Continue reading the full article.