Skip to content
MLiS Hub
On this page

Rare Trajectory Sampling with Reinforcement Learning

Public
Note

These series of notes recreate and expand upon the work of (Rose, Mair, and Garrahan 2021)Rose, Dominic C, Jamie F Mair, and Juan P Garrahan. 2021. “A Reinforcement Learning Approach to Rare Trajectory Sampling.” New Journal of Physics 23 (1): 013013. https://doi.org/10.1088/1367-2630/abd7bd..

How can Reinforcement Learning (RL) be used to make the improbable observable? In many stochastic systems the most important events are those we almost never see. This article explores how RL can make these events commonplace, rather than searching for a needle in a haystack, by approximating the Doob transformation (Chetrite and Touchette 2015)Chetrite, Raphaël, and Hugo Touchette. 2015. “Nonequilibrium Markov Processes Conditioned on Large Deviations.” Annales Henri Poincaré 16 (9): 2005–57. https://doi.org/10.1007/s00023-014-0375-8.. By framing rare event sampling as a control problem we are able to guide the system towards producing behaviours of interest while maintaining statistical correctness.

We introduce a simple excursion problem and demonstrate how a variety of reinforcement learning methods, exact and stochastic, can be used to control the system. We introduce the KL divergence as a measurement of how well we are able to approximate the exact solution and discuss the use of approximate methods in systems where the exact solution cannot be determined analytically.

Contents

This page is the main entry point. Deeper treatments of individual topics live on their own pages, each linked from the relevant section below:

What is rare event analysis in physics

In many physical systems, behaviours of interest are associated with events that occur with very low probability under natural dynamics.

Typical examples include barrier crossing in molecular systems, nucleation during phase transitions, and intermittent bursts in turbulent flows. Similar phenomena also appear in biological contexts, such as protein folding pathways, or climate science with fluctuations causing extreme weather events.

Although these events are infrequent, they often control the long time behaviour of the system. Rare event analysis is concerned with both quantifying the probability of such events and understanding the underlying conditions leading to them.

Figure 1: A Gaussian distribution is a common example of a probability mass function. Image from The “Tail” of a Particle Size Distribution.

Rather than focusing on individual states, xx, occurring with probability P(x)P(x), we often concern ourselves with trajectories, w=(x0,x1,...,xT)w = (x_0,x_1,...,x_T) and their associated probabilities P(w)P(w). Now rather than being a single unlikely event, rare events are a sequence of events which when combined result in a rare event occurring. As the number of possible trajectories grows exponentially with TT, the space of all events quickly becomes too large to explore directly.

A natural first approach is to simulate the system using naive Monte Carlo methods and estimate probabilities empirically. However, for rare events this becomes impractical, as the number of samples required to observe even a single relevant trajectory can be prohibitively large. In the case of a simple discrete space and time random walk, a trajectory of length TT has 2T2^T unique instances, given a shared initial starting state.

Thankfully, rare trajectories are not arbitrary, and events which look rare under one set of dynamics can become typical under another. If we can find a set of modified dynamics under which these trajectories occur more frequently, we can instead sample from this new process and correct for the bias using importance sampling.

To estimate the probability of an event under some original dynamics P(w)P(w) using sampled trajectories from a modified distribution P˜(w)\tilde{P}(w) we can use:

𝔼w∼P[f(w)]=𝔼P˜[f(w)P(w)P˜(w)]. \mathbb{E}_{w \sim P}[f(w)] = \mathbb{E}_{\tilde{P}}\left[f(w)\frac{P(w)}{\tilde{P}(w)}\right].

In rare event analysis f(w)f(w) is often the indicator function, which allows this equation to recover the probability of a rare event occurring under the original dynamics.

A key requirement on the proposal distribution P˜\tilde{P} is that it must assign non-zero probability to every trajectory that has non-zero probability under the original dynamics so that the likelihood ratio P(w)P˜(w)\frac{P(w)}{\tilde{P}(w)} is well-defined (i.e. avoids division by zero). If this condition is violated, there exist trajectories that contribute to 𝔼w∼P[f(w)]\mathbb{E}_{w \sim P}[f(w)] but are never sampled under P˜\tilde{P}, leading to a biased estimator which does not converge to the true expectation. This constraint favours the approach of using modified dynamics that reweight trajectories rather than exclude them entirely.

A simple intro to Doob dynamics

The Doob transformation of a system modifies its dynamics by introducing a drift force which biases trajectories towards those resulting in the desired event. Under these transformed dynamics, trajectories which were rare under the original process become typical (Chetrite and Touchette 2015)Chetrite, Raphaël, and Hugo Touchette. 2015. “Nonequilibrium Markov Processes Conditioned on Large Deviations.” Annales Henri Poincaré 16 (9): 2005–57. https://doi.org/10.1007/s00023-014-0375-8..

Sampling from these dynamics, often referred to as tilted dynamics, is statistically equivalent to sampling from a catalogue of rare events, post-selected from the original dynamics, P(w)P(w) according to some condition. Here we define the distribution of trajectories created by the Doob dynamics (or post-selection):

P˜(w)=1ZP(w)esO(w), \tilde{P}(w) = \frac{1}{Z} \, P(w)\, e^{sO(w)},

where O(w)O(w) can be any function that maps to a scalar, but which biases the tilted dynamics to produce trajectories with a given mean 𝔼w∼P˜[O(w)]\underset{w \sim \tilde{P}}{\mathbb{E}}\left [ O(w) \right ]. The exact mean targeted is controlled by conjugate parameter ss.

The actual Doob dynamics is given by the Markovian decomposition of P˜\tilde{P}:

P˜(w)=d(x0)∏tp˜doob(xt+1|w0...t), \tilde{P}(w) = d(x_0) \prod_t \tilde{p}_\text{doob}(x_{t+1}|w_{0\ldots t}),

where d(x0)d(x_0) specifies some initial distribution over the initial state x0x_0. In general, the local Doob dynamics may need to depend on the entire history of the trajectory, but in many cases this can be simplified to a reduced Markovian state that contains all the information necessary for the dynamics.

Unfortunately there are many cases where discovering the true Doob dynamics of the system can be difficult or even impossible. Transferable approaches to approximating the Doob dynamics therefore is a useful area of research allowing the study of events which have previously been unfeasibly rare. Modern RL techniques allow a great opportunity to approximate solutions to these problems.

How does reinforcement learning help with this

Reinforcement Learning (RL) is often used in control problems, where the goal is to learn a set of actions that leads to desirable behaviour. Perhaps the most famous examples of this are game-playing agents such as AlphaGo and AlphaZero, which learned to play board games at a superhuman level purely through self-play and reward signals for winning. RL is also used in domains such as self-driving cars being taught to drive by receiving ‘rewards’ for good driving (Aside: self-driving cars also use many other machine learning techniques such as CNNs for object recognition and LSTM for predicting future vehicle movement, Medium/machine-learning-in-self-driving-cars ). This same concept can be used to ‘learn’ the Doob dynamics of a system by crafting a reward function that mimics the desired rare event.

In RL, an agent interacts with an environment aiming to maximise some reward from it. In the discrete time case an agent observes some state ss and selects an action aa according to a policy π(a|s)\pi(a|s). This action provides it with some reward rr and updates the state s′s'. Over time a successful agent will learn to perform some action which maximises the return GG (the sum, sometimes discounted, of future rewards).

Important

In RL, rather than using trajectory notation w=(x0,x1,...,xT)w = (x_0,x_1,...,x_T) we can say that a trajectory can be defined as w=(s0,a0,s1,a1,...aT,sT)w=(s_0,a_0,s_1,a_1,...a_T,s_T) where xt=(st,at)x_t = (s_t, a_t) and π(at​∣st​)=π(xt(a)∣xt(s))=π(xt(a)​∣w0:t−1​)π(a_t​∣s_t​) = \pi(x_t^{(a)} \mid x_t^{(s)}) = π(x_t^{(a)}​∣w_{0:t-1}​). We make use of these interchangeably here.

Figure 2: The reinforcement learning cycle. Image from KDnuggets

The central goal of RL is to maximise the total cumulative reward an agent receives over time. Every goal can be encoded with one or more corresponding reward signals such that if an agent maximises those rewards over time, it achieves the desired behaviour.

The KL divergence

The forward Kullback-Leibler Divergence (KL-Divergence) is a measure of how one distribution p(w)p(w) differs from another p˜(w)\tilde{p}(w) over the same probability space ww. The KL divergence can be understood as measuring how spread out pp is relative to the spread of p˜\tilde{p}. If DKL(p‖p˜)=0D_{\mathrm{KL}}(p \,\|\, \tilde{p}) = 0 then p(w)p(w) and p˜(w)\tilde{p}(w) represent the same distribution. This can be written as: DKL(p‖p˜)=∑w∈𝒯︀p(w)logp(w)p˜(w)=𝔼w∼p[log⁡p(w)p˜(w)]=−𝔼w∼p[log⁡p˜(w)]+𝔼w∼p[log⁡p(w)]. \begin{aligned} D_{\mathrm{KL}}(p \,\|\, \tilde{p}) &= \sum_{w \in \mathcal{T}} p(w)\, \log \frac{p(w)}{\tilde{p}(w)} \\ &= \mathbb{E}_{w \sim p} \left[ \log \frac{p(w)}{\tilde{p}(w)} \right] \\ &= - \mathbb{E}_{w \sim p} \left[ \log \tilde{p}(w) \right] + \mathbb{E}_{w \sim p} \left[ \log p(w) \right]. \end{aligned}

Note

Whenever we use log⁡x\log x, we refer to the natural logarithm of xx.

The central motivation behind this project is that minimising the KL divergence and maximising the returns of a vanilla policy gradient algorithm can be made mathematically equivalent. We prove this in the KL divergence derivation. The key result is that for a policy gradient algorithm of form:

∇θL(θ)=𝔼w∼pπθ[G(w)∑t∇θlog⁡pπθ(at∣st)] \nabla_\theta L(\theta) = \mathbb{E}_{w \sim p_{\pi_\theta}}\left[ G(w)\, \sum_t \nabla_\theta \log p_{\pi_\theta}(a_t \mid s_t) \right]

We can learn dynamics which approach those of some Doob transformed dynamics for a given system by defining G(w)G(w) to be

G(w)=∑tRt=∑tso(wt)−log⁡pπθ(at∣st)p(at∣st), G(w) = \sum_t R_t = \sum_ts o(w_t) - \log \frac{p_{\pi_\theta}(a_t \mid s_t)}{p(a_t \mid s_t)},

where so(wt)s o(w_t) is the per timestep version of the observable such that ∑tso(wt)=sO(w)\sum_t s o(w_t) = sO(w) and pπθ(at∣st)p(at∣st)\frac{p_{\pi_\theta}(a_t \mid s_t)}{p(a_t \mid s_t)} is the ratio between the biased and unbiased dynamics.

We can re-write this as the per transition reward being written as Rt=so(wt)−log⁡pπθ(at∣st)p(at∣st). R_t = s o(w_t) - \log \frac{p_{\pi_\theta}(a_t \mid s_t)}{p(a_t \mid s_t)}. We should note that in this format, the reward landscape is no longer fixed, but changes with the current policy. Additionally, the choice of observable affects the Markovian nature of the problem, as it could in general, be a function of the history, and not just the current state.

The case of the Random Walker

We work throughout with a discrete random walk on a finite grid: a walker starts at the origin x=0x = 0 at t=0t = 0 and takes TT steps, each either up or down by one unit with equal probability. The state of the system at any moment is the pair

s=(x,t),x∈{−T,...,T},t∈{0,...,T}, s = (x, t), \qquad x \in \{-T, \ldots, T\}, \quad t \in \{0, \ldots, T\},

and the walker always begins at s0=(0,0)s_0 = (0, 0). A random walk excursion is a trajectory conditioned to return to the origin at t=Tt = T; the probability of any single excursion under the unbiased walk is (1/2)T(1/2)^T, so excursions become exponentially rare as the horizon grows. Because the grid is finite, exact solutions can be computed and used as a benchmark for the RL methods considered here.

For the full problem specification, see The Toy Problem.

Crafting a reward function

The KL derivation fixed the reward form directly: it is the unique per-step reward for which maximising the RL objective is equivalent to minimising the KL divergence against the Doob distribution,

r(s,a,s′)=W(s′,s,a)−ln⁡πθ(a|s)P0(a|s), r(s, a, s') = W(s', s, a) - \ln \frac{\pi_\theta(a|s)}{P_0(a|s)},

where P0(a|s)=12P_0(a|s) = \tfrac{1}{2} is the baseline uniform walk and WW is a terminal penalty shaped to peak at xT=0x_T = 0 (e.g. W(xT)=−xT2W(x_T) = -x_T^2). The two terms have distinct roles: WW encodes the excursion condition, while the log-ratio penalises the policy for deviating from the reference dynamics. Without the log-ratio, a purely terminal signal causes the policy to collapse to determinism, once any returning trajectory is found, gradient pressure concentrates all probability mass onto it, destroying the distributional character needed to approximate the Doob dynamics.

For the full derivation of the reward structure and objective, see Crafting a Reward Function.

RL Algorithms

Two complementary approaches are used to optimise the policy via gradient ascent on the expected return. The tabular method stores an independent parameter at each grid state, updated locally from sampled trajectories, exact and interpretable, but unable to generalise across states. The neural network method replaces the lookup table with a feedforward network whose shared weights couple every state, enabling generalisation to grid sizes and trajectory lengths not seen during training.

Both share the same fundamental update rule. At each iteration, NN trajectories are sampled under the current policy and used to estimate the policy gradient,

θ←θ+α⋅1N∑i=1N∑tχt(ωi)∇θln⁡πθ(at∣st), \theta \leftarrow \theta + \alpha \cdot \frac{1}{N}\sum_{i=1}^{N}\sum_{t} \chi_t(\omega_i)\,\nabla_\theta \ln\pi_\theta(a_t \mid s_t),

where α\alpha is the learning rate and χt(ωi)\chi_t(\omega_i) is the reward-to-go from step tt of trajectory ωi\omega_i, the cumulative future return the agent actually received. In pseudocode, one gradient update step is:

# Inputs: policy πθ, learning rate α, batch size N

while !converged
    # 1. Roll out N trajectories under the current policy
    ω = [sample_trajectory(πθ) for i in 1:N]

    # 2. Reward-to-go at every step of every trajectory
    χ = [[sum(r(s, a) for (s, a) in ωᵢ[t:end]) for t in 1:length(ωᵢ)]
         for ωᵢ in ω]

    # 3. Estimate the policy gradient
    g = (1 / N) * sum(χ[i][t] * ∇θ(log(πθ(a, s)))
                      for (i, ωᵢ) in enumerate(ω)
                      for (t, (s, a)) in enumerate(ωᵢ))

    # 4. Gradient ascent step
    θ += α * g
end

Value-based methods, dynamic programming and QQ-learning, are also surveyed. Both illuminate why policy gradient methods are the natural choice here: learning a distribution over trajectories, rather than a single optimal path, requires directly parameterising the policy itself.

For the full treatment of all methods, see RL Methods and Policy Gradient Methods.

Finding an exact solution

For this specific problem, the optimal policy can be computed without any gradient steps. Setting dV/dθs=0dV/d\theta_s = 0 yields a clean closed form: the optimal parameter at each state is simply

θs=β(s,↑)−β(s,↓),β(s,a)=W(s′,s,a)+γV(s′), \theta_s = \beta(s, \uparrow) - \beta(s, \downarrow), \qquad \beta(s,a) = W(s',s,a) + \gamma V(s'),

the difference in expected future reward between stepping up and stepping down. The optimal value function takes the log-sum-exp form

Vs=log⁡(eβ↑+eβ↓)−log⁡2, V_s = \log\!\bigl(e^{\beta_\uparrow} + e^{\beta_\downarrow}\bigr) - \log 2,

which can be evaluated stably via the standard log-sum-exp trick. Together these two expressions support a single backwards induction sweep over the grid, starting from known terminal boundary values and propagating back to t=0t = 0, yielding a ground-truth policy in 𝒪︀(|S|)\mathcal{O}(|S|) time. This exact solution serves as the fixed reference against which all RL methods are evaluated and is reference to as ERBI (Exact Results from Backwards Induction).

For the full derivation and numerical implementation, see Finding an Exact Solution.

Note

A very similar approach can be used to efficiently implement the KL divergence calculation between two policies, without having to sum over all unique trajectories.

Our Findings

With the neural network policy trained, and the exact solution computed via backwards induction, we can now evaluate how well each approach recovers the true excursion dynamics. This section presents the results in four parts: first an analysis of how naive input parameters effect the KL divergence, followed by a spatial map of policy errors across the grid, then a visitation-weighted view that prioritises the errors that matter most. Finally, we present an analysis of how the choice of input features affects neural network performance.

Figure 3: log - log graph showing the evolution of the KL divergence between our learned and exact dynamics with respect to time using the simple input features x, t, and T. The graph is normalised by dividing each trajectory length by its initial KL divergence between a random trajectory and the exact one. Each datapoint is averaged over 10 runs.

Plotting the average KL divergence with respect to time shows the relative improvement in proximity to the desired dynamics. We can see shorter systems more successfully approach the true dynamics however all systems even those that are out of distribution do achieve a substantial increase compared to the initial random policies.

Figure 4: log - linear graph showing the final KL divergence between our learned and exact dynamics using the simple input features x, t, and T. The graph is normalised by dividing each trajectory length by its initial KL divergence between a random trajectory and the exact one. Each datapoint is averaged over 10 runs.

Looking at the final KL divergence gives a clearer picture of the pattern, much shorter trajectories have the lowest KL divergence, with this increasing slowly at first and then more rapidly once outside the in-distribution limit of T=100T=100. We explore the reasons for this and suggest some improvements in the remainder of the results section.

Policy Error Heatmaps

The most direct measure of policy quality is the pointwise error between the learned policy πθ(a|s)\pi_\theta(a|s) and the exact solution π∗(a|s)\pi^*(a|s) at each state on the grid. Since both policies are parameterised by a single scalar (the logit θs\theta_s or its neural network equivalent z(s)z(s)), the error at each state can be summarised as,

ε(s)=|πθ(↑|s)−π∗(↑|s)|, \varepsilon(s) = \left| \pi_\theta(\uparrow | s) - \pi^*(\uparrow | s) \right|,(1)

plotted as a heatmap over the (2T+1)×(T+1)(2T+1) \times (T+1) grid with position xx on the vertical axis and time tt on the horizontal.

Figure 5: Heatmap of ε(s)\varepsilon(s) over the grid for the best NN policy versus the ERBI exact solution. Colour scale from dark purple (zero error) to dark red (maximum error ~0.05).

The heatmap reveals that errors are far from uniformly distributed. Four distinct regions of elevated error emerged across different training sessions (not all visible above), each for a related deterministic reason:

  • Start of trajectory (t≈0t \approx 0, small xx). At the very beginning of the walk the excursion has not yet had time to build up any positive displacement. The exact policy places near-certain probability on the upward step to escape the origin boundary, but the entropy regularisation in the reward penalises certainty, so the network cannot fully reproduce these near-deterministic probabilities. The result is a visible band of error emanating from the lower-left corner.

  • End of trajectory (t≈Tt \approx T, all reachable xx). Near the terminal time the excursion must return to the origin, and the exact policy again becomes strongly deterministic: a walker at x=kx = k steps t=T−kt = T - k away must step down with near-certainty. The same entropy–determinism tension produces the prominent high-error diagonal ridge along the right edge of the triangle.

  • The x=0x = 0 boundary (lower edge of the triangle). States on the x=0x = 0 line are absorbing in the sense that a downward step would violate the non-negativity constraint and the policy must assign zero probability to ↓\downarrow. This is another near-deterministic constraint that the entropy-regularised objective pushes against, producing the visible horizontal band of error along the bottom edge throughout most of the time horizon.

  • Descending diagonal from t≈T/2t \approx T/2 to TT. Along this line, states are squeezed: a walker that has climbed high must descend quickly to reach the origin by time TT, forcing the policy toward certainty well before the terminal step. This constraint tightens progressively along the diagonal, and the heatmap confirms this band as the region of peak error (darkest red).

In all four cases the root cause is the same: the exact policy π∗\pi^* is forced toward 0 or 1 by hard combinatorial constraints, while the entropy-regularised training objective actively discourages such certainty. The interior of the grid, where both actions remain genuinely viable throughout the walk, is learned with much lower error.

Visitation and Visitation-Weighted Error

The pointwise error heatmap treats all states equally, but not all states are equally relevant. A large error at a state the walker almost never visits has little practical consequence; a small error at a highly visited state can meaningfully distort the trajectory distribution. To account for this, we weight errors by a state visitation probability ρπ(s)\rho_\pi(s), computed via a single forward pass through the lattice: starting from ρ(x=0,t=0)=1\rho(x{=}0, t{=}0) = 1, the probability mass is propagated forward at each step using the action probabilities of the policy under evaluation,

ρ(x,t+1)=ρ(x−1,t)π(↑∣x−1,t)+ρ(x+1,t)π(↓∣x+1,t). \rho(x, t+1) = \rho(x-1,\, t)\,\pi(\uparrow \mid x-1, t) \;+\; \rho(x+1,\, t)\,\pi(\downarrow \mid x+1, t).(2)

This gives ρπ(x,t)=Pπ(Xt=x)\rho_\pi(x, t) = P_\pi(X_t = x), the marginal probability of being at position xx at time tt under policy π\pi.

Figure 6: State visitation probability ρπθ(x,t)\rho_{\pi_\theta}(x, t) under the best NN policy.
Figure 7: State visitation probability ρπ∗(x,t)\rho_{\pi^*}(x, t) under the ERBI exact policy.

Both visitation distributions are arc-shaped, as expected for excursion trajectories: probability mass rises through positive xx in the first half and descends in the second, forming a concentrated band through the lower centre of the grid. The two distributions are visually near-identical, which itself confirms the NN policy is a close approximation to the exact solution in terms of the trajectories it actually generates.

To produce a balanced weighting that does not favour either policy, the visitation-weighted error uses the pointwise average of the two visitation distributions,

ρ¯(s)=12(ρπθ(s)+ρπ∗(s)), \bar{\rho}(s) = \tfrac{1}{2}\bigl(\rho_{\pi_\theta}(s) + \rho_{\pi^*}(s)\bigr),(3)

and the weighted error at each state is then,

ε˜(s)=ρ¯(s)⋅ε(s). \tilde{\varepsilon}(s) = \bar{\rho}(s) \cdot \varepsilon(s).(4)

Figure 8: Visitation-weighted error ε˜(s)\tilde{\varepsilon}(s) across the grid. The colour scale peaks around 10−310^{-3}, far below the raw error peaks in Figure 5, confirming that the worst pointwise errors occur in sparsely visited regions.

The weighted error map confirms that the prominent boundary errors identified in Section 9.1 are largely benign in practice. The x=0x = 0 boundary and the terminal diagonal carry high pointwise error but very low visitation probability, so their contribution to ε˜\tilde{\varepsilon} is small. The residual weighted error is concentrated in a narrow arc at low xx through the middle of the grid, reflecting the small but non-negligible errors in the most-visited region.

Measuring Returns via Averaged Backwards Induction

The heatmaps above measure policy quality in probability space, but the most direct check is simply whether the trained policy achieves returns close to the theoretical optimum. During training, the return GG is tracked after every epoch and the weights achieving the highest GG are saved. After training, the optimal return G∗G^* is recovered from the exact ERBI solution for comparison.

Figure 9: Training returns over 50,000 epochs. The shaded blue region shows the per-epoch return; the solid blue line is the return smoothed with a rolling window of w=500w = 500 epochs to reveal the underlying trend; the dashed red line is the mean optimal G∗G^* from the ERBI exact solution. The best weights (GG closest to G∗G^*) are saved throughout training.

As shown in Figure 9, the network recovers quickly from the large negative returns at initialisation and converges toward G∗G^* over the course of training. The raw per-epoch returns are highly variable, so a rolling average over w=500w = 500 consecutive epochs is overlaid to expose the learning trend without this noise. The best saved weights achieve G=−5.987G = -5.987 against the mean optimum G∗=−5.824G^* = -5.824, a gap of roughly 0.160.16. This residual shortfall is consistent with the entropy regularisation: the trained policy cannot exactly reproduce the near-deterministic boundary actions, so it sacrifices a small amount of return in exchange for the smoother, more generalisable behaviour seen in the interior of the grid.

Input Feature Selection

Note

The features displayed in this section are not necessarily an accurate representation of the features used during training, but rather are used to visualise and explain a core concept of neural network design.

The neural network policy takes the state (x,t)(x, t) as input and must generalise across the full grid. A natural question is: which input representation leads to the most stable and accurate training? The raw coordinates xx and tt grow with TT, meaning that a network trained on walks of length TT will see inputs in a different range than one trained on T′≠TT' \neq T. This can cause training instability and poor generalisation.

To investigate this, we compare several candidate input features, for example, the raw coordinates (x,t)(x, t), the normalised coordinates (x/T,t/T)(x/T, t/T), and combinations thereof, by training the network under each representation and tracking the learned logits at a fixed reference state s0s_0 as a function of walk length TT.

Figure 10: Feature values at the reference state (x,t)=(0.3T,0.5T)(x, t) = (0.3T,\, 0.5T) as a function of walk length TT. The shaded region marks the training range. Unbounded features such as x/(T−t)x/(T-t) oscillate heavily for small TT and only stabilise well beyond the training window, whereas bounded features such as t/Tt/T remain constant by construction.

The results motivate the use of bounded, normalised input features. When raw coordinates are used, the network’s inputs grow without bound as TT increases, and the logits at fixed states can vary erratically, the network has not learned a representation that transfers across scales. Normalising by TT ensures that the input to the network always lies in [−1,1]×[0,1][-1, 1] \times [0, 1] regardless of walk length, and the logits at fixed relative positions vary smoothly and predictably. This is a practical illustration of a general principle designing neural networks: input features should be scaled so that the network operates in a consistent numerical regime across the range of problems it will encounter.

Conclusion

Rare event analysis deals with low probability phenomena across stochastic systems, where infrequent events often dominate outcomes. We present RL as a viable strategy for the analysis of these phenomena, demonstrating its capabilities using a suite of methods. By rewarding entropy via a KL-style term we are able to reproduce a distribution of results appropriate for further analysis of the system.

Specifically we have demonstrated the effectiveness of policy gradient methods at approximating the Doob transform, with the KL divergence against our exact solution dropping at least four orders of magnitude from the randomly initialised policy on in distribution samples. Even on out of distribution samples we achieved reasonable results, with a drop of over three orders of magnitude, demonstrating the generalisability of neural network based approaches. We also confirm that the returns approach optimal and plot the visitation policies and their respective errors, showing our success from an RL perspective. We highlight simple improvements to this such as input scaling which can be a powerful tool to improve generalisability on problems of this nature.

Extensions

We have explored a comparison to the one-step optimal solution.

Future Work

A longer-term direction is to apply symbolic regression to the policies learned by both the tabular and neural network approaches. Symbolic regression searches the space of mathematical expressions to find a compact closed-form function that fits a dataset, in this case, the learned policy parameters θs\theta_s as a function of position xx and time tt. For the excursion problem the exact Doob hh-transform is known, so a symbolic regression fit to the learned tabular policy could be directly compared against the analytical solution and assessed for structural agreement. In systems where the exact Doob dynamics are not available, symbolic regression applied to a trained policy could offer a route to human-interpretable approximations of the hh-transform, potentially revealing the governing physical structure of the rare event in a form that is portable beyond the specific RL training setup.

Chetrite, Raphaël, and Hugo Touchette. 2015. “Nonequilibrium Markov Processes Conditioned on Large Deviations.” Annales Henri Poincaré 16 (9): 2005–57. https://doi.org/10.1007/s00023-014-0375-8.
Rose, Dominic C, Jamie F Mair, and Juan P Garrahan. 2021. “A Reinforcement Learning Approach to Rare Trajectory Sampling.” New Journal of Physics 23 (1): 013013. https://doi.org/10.1088/1367-2630/abd7bd.

Pages