Optimising the policy directly
- : a trajectory, one whole run through the environment.
- : its total return.
The objective is the expected return, and the parameters being optimised are the policy's own rather than a value function's.
That is the policy gradient theorem, and it is remarkable because the environment's dynamics do not appear in it.
The log-derivative trick
The gradient of an expectation over a distribution that itself depends on is not an expectation of a gradient, which is the obstacle.
Taking the logarithm turns the product over timesteps into a sum, and the transition terms do not depend on , so they differentiate to zero.
Only the policy's own log probabilities survive, which is why the method works without a model of the environment.
What the update actually does
Increase the log probability of actions that were followed by a high return, decrease it for those that were not, in proportion to the return.
If all returns are positive, every action's probability is pushed up, and learning happens only through the differences in magnitude, which is slow and noisy.
The baseline, which is not optional
Subtracting any function of the state leaves the gradient unbiased, because the expected score function is zero.
Using the state value as the baseline turns the weight into the advantage: how much better this action was than the average from that state.
That single change cuts the variance by orders of magnitude, and a learned is the critic in an actor-critic method.
One update, in order
- Run the current policy to collect a batch of trajectories.
- Compute the return from each timestep onward, not the whole episode's return.
- Subtract the baseline to get advantages, and normalise them across the batch.
- Take the gradient of the log probabilities weighted by those advantages.
- Step, and discard the data, because it was collected under the old policy.
Step five is the expensive part. Policy gradients are on-policy, so every batch is used once, which is why they need far more environment interaction than Q-learning.
An entropy bonus is usually added, because a policy that becomes deterministic early stops exploring and cannot recover.