Skip to content
MLiS Hub
On this page

Rare Trajectory Sampling with Reinforcement Learning

One step optimal solution

While our comparison metric (improvement relative to the unbiased solution) showed substantial improvement, it is ultimately unclear how much improvement constitutes a ‘good’ approximation of the exact solution, this will also vary from problem to problem, with larger problems (presumably) requiring a larger reduction in relative KL divergence. In our case we are able to qualitatively confirm a good solution by comparing heatmaps of the two solutions, however this will not always be possible depending on the nature of the problem.

An initial proposal is to compare against a local solution, such as the optimal solution for a one-step problem, which could provide a good baseline to measure against.

Derivation

Starting with the value function:

Vπ(s)=∑aπ(a|s)[λo(s,a)−log⁡π(a|s)p(a|s)+γVπ(s′)] V_\pi(s) = \sum_a \pi(a|s)\left[\lambda o(s,a) - \log\frac{\pi(a|s)}{p(a|s)} + \gamma V_\pi(s')\right]

we aim to find π∗(a|s)\pi^*(a|s) under the condition γ=0\gamma = 0 (i.e. only looking at the immediate reward), to do this we will maximise Vπ(s)V_\pi(s) subject to the constraint ∑aπ(a|s)=1\sum_a \pi(a|s) = 1.

With γ=0\gamma = 0, the (discounted) value function becomes

Vπ(s)=∑aπ(a|s)[λo(s,a)−log⁡π(a|s)p(a|s)]. V_\pi(s) = \sum_a \pi(a|s)\left[\lambda o(s,a) - \log\frac{\pi(a|s)}{p(a|s)}\right].

We form the Lagrangian to enforce normalisation of π(⋅|s)\pi(\cdot|s), with multiplier μ\mu:

ℒ︀(π,μ)=∑aπ(a|s)[λo(s,a)−log⁡π(a|s)p(a|s)]+μ(1−∑aπ(a|s)). \mathcal{L}(\pi,\mu) = \sum_a \pi(a|s)\left[\lambda o(s,a) - \log\frac{\pi(a|s)}{p(a|s)}\right] + \mu\left(1 - \sum_a \pi(a|s)\right).

We can maximise by differentiating with respect to a single π(a|s)\pi(a|s) and using ∂∂π[πlog⁡(π/p)]=log⁡(π/p)+1\frac{\partial}{\partial \pi}\big[\pi\log(\pi/p)\big] = \log(\pi/p) + 1:

∂ℒ︀∂π(a|s)=λo(s,a)−log⁡π(a|s)p(a|s)−1−μ=0 \frac{\partial \mathcal{L}}{\partial \pi(a|s)} = \lambda o(s,a) - \log\frac{\pi(a|s)}{p(a|s)} - 1 - \mu = 0

Solving for π(a|s)\pi(a|s):

π(a|s)=p(a|s)e−μ+λo(s,a). \pi(a|s) = p(a|s)\,\,e^{-\mu + \lambda o(s,a)}.

Using our constraint:

1=∑aπ(a|s)=∑ap(a|s)e−μ+λo(s,a)⟹e−μ=1∑ap(a|s)eλo(s,a)=1Z(s) 1 = \sum_a \pi(a|s) = \sum_a p(a|s)\,\,e^{-\mu + \lambda o(s,a)} \Longrightarrow e^{-\mu} = \frac{1}{\sum_a p(a|s)\,\,e^{\lambda o(s,a)}} = \frac{1}{Z(s)}

This gives the one-step optimal policy:

π∗(a|s)=1Z(s)p(a|s)eλo(s,a) \pi^*(a|s) = \frac{1}{Z(s)}\,p(a|s)\,e^{ \lambda o(s,a)}

Results and Discussion

Figure 1: log - linear graph showing the final KL divergence between our learned and exact dynamics as in Fig.4 of the main section , in orange we also display the KL divergence between our local optimal policy and the unbiased policy

We see that while the locally optimal policy represents some small increase in information relative to the unbiased problem, this is still relatively small, and all trained problems comfortably surpass this by multiple orders of magnitude — meaning that for this problem, clearing this benchmark is not a difficult bar for a successfully trained policy to meet.

Figure 2: State visitation probability heatmap under the locally optimal policy

The heatmap helps explain why. The locally optimal solution is able to remain positive at all timesteps. However, beyond that, the probability density appears to diffuse as time goes on rather than follow any other constraints.

Thinking about the reward landscape we have built for this problem (as a reminder, this consists of a fixed constant negative reward at negative position and a quadratically scaling penalty for deviating from x=0x=0 at t=Tt=T), while this is a richer reward landscape than one which only rewards the successful realisation of an excursion trajectory, it is still a sparse reward landscape, with the majority of the space giving no signal as to which states should be visited. In non-terminal states where no transition towards or away from receiving a negative penalty is possible, both options are equally favoured and therefore simply recover the unbiased policy, without any signal as to which action leads to the highest chance of future reward.

All this is not to say that this solution is useless. Even for sparse problems like this, we gain an additional benchmark that we can expect all trained solutions to clear as a minimum. However, this becomes a more relevant benchmark for problems with richer reward landscapes. Take, for example, the problem of biasing an LLM towards some per-token metric. Picking the token that maximises this metric at each step is a greedy, one-step strategy — and it will likely miss rarer completions that unlock higher scores later in the sequence (assuming the metric is a function of x1:tx_{1:t} rather than simply xtx_t). In a setting like this, the one-step benchmark becomes a much more informative benchmark for training.