Skip to content
MLiS Hub
On this page

Rare Trajectory Sampling with Reinforcement Learning

Reinforcement Learning: Key Methods

The Value Function and the QQ-Function

The central quantity in RL is the value function, vπ(s)v_\pi(s), which measures how good it is to be in a state ss under a policy π\pi. Formally, it is the expected discounted return of all trajectories ω\omega starting from ss,

vπ(s)=𝔼ω∼π∣S0=s[G(ω)],G(ω)=∑t=0T−1γtRt, v_\pi(s) = \mathbb{E}_{\omega \sim \pi \mid S_0 = s}\left[G(\omega)\right], \qquad G(\omega) = \sum_{t=0}^{T-1} \gamma^t R_t,(1)

where γ\gamma is the discount factor introduced in the Reward Function and RtR_t is the reward received at time tt. The expectation averages over the randomness in both the policy and the environment. Crucially, the value function is always defined relative to a specific policy, it measures the quality of π\pi, not of the state in isolation.

A closely related object is the state-action value function, or QQ-function, qπ(s,a)q_\pi(s, a), which measures the expected return from taking a specific action aa in state ss and then following π\pi thereafter,

qπ(s,a)=𝔼[r(s′,s,a)+γvπ(s′)]. q_\pi(s, a) = \mathbb{E}\left[r(s', s, a) + \gamma v_\pi(s')\right].(2)

The QQ-function is practically useful because it allows a policy to be improved locally: if qπ(s,a)>vπ(s)q_\pi(s, a) > v_\pi(s) for some action a≠π(s)a \neq \pi(s), then switching to aa in state ss is guaranteed to improve the policy. Both vπv_\pi and qπq_\pi satisfy recursive relations known as the Bellman equations, which express the value of a state in terms of the values of its successors,

vπ(s)=∑a∈𝒜︀π(a|s)[r(s′,s,a)+γvπ(s′)]. v_\pi(s) = \sum_{a \in \mathcal{A}} \pi(a|s) \left[r(s', s, a) + \gamma v_\pi(s')\right].(3)

The Bellman equations are the foundation of nearly all RL algorithms. The goal of RL, finding the optimal policy π∗\pi^*, can be stated compactly as,

π∗=arg⁡maxπvπ(s)for all s. \pi^* = \underset{\pi}{\arg\max} \; v_\pi(s) \quad \text{for all } s.(4)

Dynamic Programming

If the dynamics of the environment, the transition probabilities p(s′,r∣s,a)p(s', r \mid s, a), are fully known, the Bellman equations become a system of simultaneous linear equations, one per state, that can in principle be solved exactly. Dynamic programming (DP) exploits this structure.

The standard approach is value iteration: initialise V(s)=0V(s) = 0 for all states and repeatedly apply the Bellman update,

V(k+1)(s)=∑a∈𝒜︀π(a|s)[r(s′,s,a)+γV(k)(s′)]for all s, V^{(k+1)}(s) = \sum_{a \in \mathcal{A}} \pi(a|s) \left[r(s', s, a) + \gamma V^{(k)}(s')\right] \quad \text{for all } s,(5)

until successive iterations differ by less than a chosen threshold. This is guaranteed to converge to the true value function. Once the value function is known, the policy can be improved by acting greedily with respect to the QQ-function, and the two steps, evaluation and improvement, can be alternated in what is called policy iteration.

Dynamic programming is exact and efficient relative to the size of the policy space (polynomial in the number of states and actions, compared to the exponential number of policies), but it has a critical limitation: it requires a complete model of the environment and must sweep over every state at every iteration. For large state spaces this quickly becomes infeasible. The excursion problem has a state space of (2T+1)×(T+1)(2T+1) \times (T+1), manageable for small TT, but the approach does not generalise.

QQ-Learning

When a model of the environment is unavailable, DP cannot be applied directly. QQ-learning sidesteps this by learning the optimal QQ-function through experience, interacting with the environment and updating estimates from observed transitions.

The core update rule is,

Q(St,At)←(1−α)Q(St,At)+α[Rt+γmaxa′⁡Q(St+1,a′)], Q(S_t, A_t) \leftarrow (1-\alpha)\, Q(S_t, A_t) + \alpha \left[R_t + \gamma \max_{a'} Q(S_{t+1}, a')\right],(6)

where α\alpha is a learning rate. At each step, the current QQ-estimate for the taken action is nudged towards the observed reward plus the best estimated future value from the next state. Crucially, the max\max in Equation 6 means QQ-learning targets the optimal policy regardless of which policy generated the data, it is off-policy.

QQ-learning has theoretical guarantees of convergence to the optimal QQ-function given infinite experience and a decaying learning rate. However, it inherits a fundamental difficulty: it still requires visiting and maintaining estimates for every state-action pair. In large or continuous state spaces, this is intractable without additional function approximation.

Why not use QQ-learning for the excursion problem?

QQ-learning learns a value function and derives a policy from it implicitly. For the excursion problem, the target is not just any policy that achieves the excursion, it is the specific distribution over trajectories given by the Doob dynamics. A value-based method has no natural way to represent or optimise for a distribution as its objective. Policy gradient methods, which directly parameterise and optimise the policy, are far better suited to this goal.

Towards Policy Gradients

Both DP and QQ-learning are value-based: they learn a value function first and derive a policy from it. An alternative family of methods directly parameterise the policy as πθ(a|s)\pi_\theta(a|s) and optimise θ\theta by gradient ascent on the expected return. These are policy gradient methods.

The VV and QQ functions introduced here reappear throughout: Vπ(s)V_\pi(s) is the quantity whose derivative drives the tabular parameter updates, and Qπθ(s,a)Q_{\pi_\theta}(s, a) is approximated by the reward-to-go χ(ω)t\chi(\omega)_t in the Monte Carlo gradient estimates.


← Back to the main article: RL Algorithms