In this article we show that minimising the KL divergence is equivalent to the standard policy gradient objective. The derivation proceeds in two steps: first computing directly, then computing and showing the two expressions coincide.
Let’s assume a standard RL loss function which sums the expected value of each trajectory at each time step: This can be re-written using the explicit form of the expectation and using that the return is the sum of the reward, . For the remainder of this article we set the discount factor so as to equally weight the reward at each time-step instead of favouring short term gains. To find the maximum value of the returns, differentiate with respect to the policy parameters, . Moving the derivative operator inwards past terms that have no dependence, Next, we can use a calculus identity known as the log derivative trick, to rewrite as… We are aiming to find some which approximates the doob dynamics such that including an environment term, ,
Differentiate with respect to ,
Substitute back into the objective and convert back into expectation form,
We now derive the gradient of the KL divergence and will show it takes the same form.
Starting from the KL divergence between the controlled trajectory distribution and a tilted target distribution,
Using the exponential reweighting form of the Doob dynamics,
As has no dependence on , and hence not on , we can move it outside the sum,
Take the gradient with respect to . Importantly, , as has no effect on the gradient. We also move the derivative operator inside the sum.
Apply product rule:
Here we can use the same log derivative identity, , as in the previous derivation to make the terms similar and allow us to combine them,
Write in expectation form:
Noting the similarities in structure between this and the loss function allows us to identify a reward,
Where is the per step contribution of the observable,and is taken to be the per timestep contribution of . Additionally, the term is dropped as constants only act as baselines and have no effect on the gradient. Using , we arrive at:
Which is the additive inverse of our policy gradient function and thus minimising the kl divergence is equivelant to maximisng the policy gradient.
The reward identified by this equivalence has two contributions. The term scores each timestep by the observable, directly incentivising trajectories that realise the rare event of interest. The log-ratio , serves as an entropy regularizer, rare-event sampling requires a policy that covers the full distribution of trajectories leading to the event. Penalising deviation from the unbiased dynamics achieves this, and (as shown above) doing so is precisely equivalent to minimising the KL divergence to the Doob distribution.
← Back to the main article: The KL divergence