Chapter 9 Policy Gradient Methods
Chapter 9 Policy Gradient Methods
In all previous chapters, all the methods are value-based methods. The difference between value-based and policy-based methods lies in their approach. Value-based methods generate policies implicitly and indirectly. The algorithm itself does not directly maintain a policy function. Instead, it solves for the value (state or action value) based on model-free or model-based methods. It greedily (or uses an epsilon-greedy approach) determines the action by maximizing the value function at each step (e.g., ), thereby deriving the policy from the value. In contrast, policy-based methods directly represent the policy as a parameterized function , where is a parameter vector (instead of previous tabular representation). The probability distribution of the policy is obtained by directly optimizing the parameter .
In this chapter, we will introduce the policy gradient methods.
Metrics
When represented as a table, a policy is defined as optimal if it can maximize every state value. When represented by a function, a policy is defined as optimal if it can maximize certain scalar metrics. We can optimize the metrics through gradient descent/ascent method to find the optimal parameters.
We have two types of metrics for defining optimal policies.
Average state value
The first metric is the average state value or simply called the average value. It is defined as:
where is the weight of state . It satisfies for any and . Therefore, we can interpret as a probability distribution of .
Then, the metric can be written as:
For distribution ? we have two cases.The first and simplest case is that is independent of the policy . In this case, we specifically denote as and as to indicate that** the distribution is independent of the policy**. One case is to treat all the states equally important and select . Another case is when we are only interested in a specific state (e.g., the agent always starts from ). In this case, we can design
Another case is that is dependent on policy , In this case, it is common to select as , which is the stationary distribution under we talked in the last chapter.
As its name suggests, is a weighted average of the state values. Different values of lead to different values of . Our ultimate goal is to find an optimal policy (or equivalently an optimal ) to maximize .
There are also two equivalent expressions of average state value:
We can understand this equation easily by knowing that represents the "expected future cumulative discount return". The math behind this is:
The metric can also be rewritten as the inner product of two vectors:
Then, we have
This expression will be useful when we analyze its gradient.
Average reward
The second metric is the average one-step reward or simply called the average reward. In particular, it is defined as
where is the stationary distribution and
is the expectation of the immediate rewards. Here, , which represents the expected reward when taking action at state .
There are also two important equivalent expressions of :
Suppose that the agent collects rewards by following a given policy . A common metric that readers may often see in the literature is:
Regarding : , we can understan it by represents the "expected future cumulative discounted return". Here we can understand by: it represents the "average expected return per step after the system reaches steady state". Intuitively, this can be understood as follows: in undiscounted (i.e., ) or infinitely long timeframes, if we directly calculate , this value is likely to diverge to infinity (if the reward per step is positive). To measure whether a strategy is good or bad under such long-term or infinite timeframes, we cannot compare two infinityes. Therefore, we divide the total reward by the number of time steps , and then find the limit of . This is actually calculating the time average. According to the ergodic theorem of Markov chains, when time is long enough, the frequency of state visits will converge to a stationary distribution . Therefore, the "time average" in the limit is equal to the "spatial average" (i.e., the expected reward of each state multiplied by the stationary probability of that state ). This is the physical meaning of .
Similarly, the average reward can also be written as the inner product of two vectors. In particular, let
Then, it is clear that:
This expression will be useful when we derive its gradient.
When the value metric is weighted by the same policy's stationary distribution, , it is proportional to for fixed :
For proof, note that and , where and satisfy the Bellman equation . Multiplying on both sides of the Bellman equation yields
This uses . It does not generally hold for the fixed-start metric with arbitrary . The starting-state objective and long-run average reward should therefore not be treated as interchangeable.
Gradients of the metrics
Given the metrics introduced in the last section, we can use gradient-based methods to maximize them. To do that, we need to first calculate the gradients of these metrics. The most important theoretical result in this chapter is the following theorem.
Theorem 9.1 (Policy gradient theorem).
To state one precise discounted version, let be independent of and use the normalized objective , with . Define its normalized discounted state-occupancy distribution:
Terminal states can be extended as zero-reward absorbing states. For a differentiable policy and an environment independent of , under the usual regularity assumptions, the gradient is
Here and is the policy gradient with respect to its parameters. For the unnormalized objective , multiply the right-hand side by ; this constant can be absorbed into the learning rate. The normalization leaves the maximizing policy unchanged. Average-reward and policy-dependent state-weighting objectives require their own gradient analysis; they cannot be substituted into this theorem without changing its assumptions.
Moreover, (1) has a compact form expressed in terms of expectation:
where is the natural logarithm. The proof is given below. By the definition of expectation, (1) can be rewritten as:
Furthermore, the gradient of is:
It follows that:
This is the log derivative trick. Substituting (4) into (3) gives:
Monte Carlo policy gradient (REINFORCE)
With the gradient presented before, The gradient-ascent algorithm for maximizing is:
where is a constant learning rate. Since the true gradient in (5) is unknown, we can replace the true gradient with a stochastic gradient to obtain the following algorithm:
where is an approximation of . If is obtained by Monte Carlo estimation, the algorithm is called REINFORCE or Monte Carlo policy gradient, which is one of earliest and simplest policy gradient algorithms.The algorithm in (6) is important since many other policy gradient algorithms can be obtained by extending it.
Since , we can rewrite (6) as:
which can be further written concisely as:
We have two interpretations about REINFORCE:
- For a single sample and a sufficiently small step, the sign of determines the local direction of change in the sampled action's probability:
If , the first-order change increases when its gradient is nonzero.
If , the first-order change decreases that probability when its gradient is nonzero. A zero coefficient or zero gradient gives no change from this sample.
This follows from a local Taylor approximation:
When is sufficiently small, it follows from the Taylor expansion that
This is a local interpretation, not a guarantee of monotonic probability changes for large updates, mixed minibatches, or shared parameters that affect many states.
- A stochastic policy provides exploration opportunities, but the factor alone does not imply an enormous update for a rare action. Its accompanying derivative also depends on the probability. For softmax logits z,
which is bounded. A favorable sampled action can be reinforced, but a low-probability useful action may rarely be discovered at all. Entropy regularization, initialization, state coverage, and exploration design remain important; REINFORCE does not automatically guarantee a good exploration-exploitation balance.
Moreover, since (6) uses samples to approximate the true gradient in (5), it is important to understand how the samples should be obtained.
- How to sample ?
For the discounted objective specified above, S is weighted by the normalized discounted occupancy , not an arbitrary uniform or stationary distribution. Equivalently, an episodic estimator for the unnormalized start-state objective sums over time. Sampling conventions and time weights must agree with the stated objective.
- How to sample ?
Actions are sampled from the policy being evaluated. A straightforward on-policy implementation collects episodes under a fixed policy, computes their returns, accumulates the corresponding policy-gradient estimates at those same parameters, and then updates the policy. All time steps in an episode can contribute. If parameters are changed repeatedly while reusing that data, later updates no longer use samples from the current policy; they require an appropriate correction or surrogate treatment rather than being exact on-policy gradient estimates. The textbook illustration below should be read with this sampling qualification.

