All Lessons

Off-Policy Learning with Importance Ratios

Data collected by one policy can estimate expectations under another policy only after correcting the action distribution. This lesson derives importance ratios, support requirements, variance growth, and clipping bias.

AI Narration Press play to listen
0  / 6 paragraphs
Click any paragraph to jump · Scroll freely without breaking narration

Suppose stored actions were sampled by a behavior policy $\mu(a\mid s)$, but the desired expectation is under a target policy $\pi(a\mid s)$. Directly averaging the stored data answers the behavior-policy question, not the target-policy question. Off-policy correction changes each sample's contribution according to how much more or less likely the target policy would have selected it.

For one state-action sample, the importance ratio is $$\rho_t=\frac{\pi(a_t\mid s_t)}{\mu(a_t\mid s_t)}.$$ For a function $f$, the identity $\mathbb{E}_{a\sim\mu}[\rho f(a)]=\mathbb{E}_{a\sim\pi}[f(a)]$ follows by canceling $\mu$ inside the sum or integral. This requires $\mu(a\mid s)>0$ whenever $\pi(a\mid s)>0$.

A ratio above one amplifies an action that the target policy favors more than the behavior policy; a ratio below one suppresses it. Ratios are not rewards and should not be interpreted as action quality. Their expectation under the behavior policy is one when support is valid and probabilities are exact, which provides a useful implementation check.

For a multi-step trajectory, exact correction may involve a product $\prod_{k=t}^{t+n-1}\rho_k$. Products can become extremely small or large, causing severe variance even when each individual ratio appears moderate. Long horizons and nearly deterministic policies make this worse. Log-ratios help numerical stability but do not remove statistical variance.

Clipping uses $\bar\rho_t=\min(c,\rho_t)$ or a bounded interval to control extreme weights. This reduces variance but introduces bias because the weighted expectation is no longer exactly the target expectation. Self-normalizing weights creates another biased but often lower-variance estimator. The tradeoff should be measured rather than hidden inside an implementation constant.

Log ratio distributions, maximum weights, effective sample size, and the fraction of clipped samples. Effective sample size can be summarized as $(\sum_i w_i)^2/\sum_i w_i^2$. A replay buffer may contain many transitions but very little usable target-policy information when a few weights dominate. No correction can recover actions that the behavior policy never sampled.