Online, Offline, and Continual Learning › Worked Example: Tracking a Drifting Coefficient

Michael BrenndoerferJuly 5, 20267 min read
World Models HandbookAll chapters
Part 6 of 12Learning World Models at Scale
Chapter 35Online, Offline, and Continual Learning › Worked Example: Tracking a Drifting Coefficient
Reading section 6 of 11 · Worked Example: Tracking a Drifting Coefficient · 7 minSection 6 of 11 · 7 min

Book contents

Section 6 of 11 · 7 min read

Online, Offline, and Continual Learning › Worked Example: Tracking a Drifting CoefficientOne section · Sections in this chapter6 / 11 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Let us make the tradeoffs quantitative with a scalar example we can solve on paper. Suppose the true relationship is

yt=θ⋆xt+ϵt,y_t = \theta^\star x_t + \epsilon_t,

where:

  • yty_t: the observed target at step tt
  • θ⋆\theta^\star: the true coefficient in the drifting-coefficient example
  • xtx_t: the scalar input at step tt
  • ϵt\epsilon_t: zero-mean observation noise at step tt
  • σ2\sigma^2: the variance of the observation noise ϵt\epsilon_t

with xt∼N(0,1)x_t \sim \mathcal{N}(0, 1) and ϵt∼N(0,σ2)\epsilon_t \sim \mathcal{N}(0, \sigma^2), and suppose θ⋆\theta^\star changes at some point from one value to another. We want to know how fast SGD tracks the change and how precisely it can localize the new value.

From the derivation above, the bias decays geometrically:

E[θt−θ⋆]=(1−ησx2)t(θ0−θ⋆).\mathbb{E}\big[\theta_t - \theta^\star\big] = \big(1 - \eta \sigma_x^2\big)^t \big(\theta_0 - \theta^\star\big).

where:

  • E[θt−θ⋆]\mathbb{E}[\theta_t - \theta^\star]: the expected deviation of the estimate from the true parameter after tt steps
  • θt\theta_t: the parameter estimate after tt steps
  • θ0\theta_0: the initial parameter value
  • θ⋆\theta^\star: the true parameter
  • η\eta: the fixed learning rate
  • σx2\sigma_x^2: the variance of the inputs xtx_t
  • tt: the number of steps elapsed, so ησx2\eta \sigma_x^2 is the per-step contraction factor

With σx2=1\sigma_x^2 = 1 and η=0.02\eta = 0.02, the decay rate is 0.980.98 per step. To reduce the initial error by a factor of ee takes about 1/0.02=501/0.02 = 50 steps. Here is where that number comes from. We want the smallest tt with (1−ησx2)t≤e−1(1 - \eta\sigma_x^2)^t \le e^{-1}. Taking logarithms,

tln⁡(1−ησx2)≤−1(apply ln⁡)t≥−1ln⁡(1−ησx2)(divide by the negative log)≈1ησx2(use ln⁡(1−z)≈−z for small z)\begin{aligned} t \ln(1 - \eta\sigma_x^2) &\le -1 && \text{(apply } \ln \text{)} \\ t &\ge \frac{-1}{\ln(1 - \eta\sigma_x^2)} && \text{(divide by the negative log)} \\ &\approx \frac{1}{\eta\sigma_x^2} && \text{(use } \ln(1-z) \approx -z \text{ for small } z\text{)} \end{aligned}

where:

  • tt: the number of steps
  • η\eta: the learning rate
  • σx2\sigma_x^2: the variance of the inputs xtx_t
  • zz: a small positive quantity, here z=ησx2z = \eta\sigma_x^2

With ησx2=0.02\eta\sigma_x^2 = 0.02 this gives t≈50t \approx 50 steps. That is the adaptation time.

The adaptation time is the first half of the tradeoff. It tells us how long the estimator takes to forget an old value after the world changes. The second half is the noise ball, which tells us how precisely the estimator can settle on the new value once it has arrived.

Now the noise. At stationarity, the variance satisfies

Var(θ∞)=η2σx2σ21−E[(1−ηxt2)2].\mathrm{Var}(\theta_\infty) = \frac{\eta^2 \sigma_x^2 \sigma^2}{1 - \mathbb{E}\big[(1 - \eta x_t^2)^2\big]}.

where:

  • Var(θ∞)\mathrm{Var}(\theta_\infty): the stationary variance of the estimate around the true parameter
  • θ∞\theta_\infty: the stationary parameter estimate around which the variance is measured
  • η\eta: the learning rate
  • σx2\sigma_x^2: the variance of the inputs xtx_t
  • xtx_t: the scalar input at step tt
  • σ2\sigma^2: the variance of the observation noise ϵt\epsilon_t
  • E[(1−ηxt2)2]\mathbb{E}\big[(1 - \eta x_t^2)^2\big]: the expected squared contraction factor, which appears in the denominator

Replacing the random contraction by its mean gives the moment-closure approximation E[(1−ηxt2)2]≈(1−ησx2)2\mathbb{E}\big[(1 - \eta x_t^2)^2\big] \approx (1 - \eta\sigma_x^2)^2. Under that approximation,

Var(θ∞)=η2σx2σ21−(1−ησx2)2=η σ22−η σx2(expand the denominator)≈η σ22(small η)\begin{aligned} \mathrm{Var}(\theta_\infty) &= \frac{\eta^2 \sigma_x^2 \sigma^2}{1 - (1 - \eta\sigma_x^2)^2} \\ &= \frac{\eta\,\sigma^2}{2 - \eta\,\sigma_x^2} && \text{(expand the denominator)} \\ &\approx \frac{\eta\,\sigma^2}{2} && \text{(small } \eta \text{)} \end{aligned}

where:

  • Var(θ∞)\mathrm{Var}(\theta_\infty): the stationary variance of the estimate around the true parameter
  • θ∞\theta_\infty: the stationary parameter estimate around which the variance is measured
  • η\eta: the learning rate
  • σx2\sigma_x^2: the variance of the inputs
  • σ2\sigma^2: the variance of the observation noise ϵt\epsilon_t

This is the noise ball: the residual fluctuation of the estimate around the true value. Its radius is

Var(θ∞)≈η σ22.\sqrt{\mathrm{Var}(\theta_\infty)} \approx \sqrt{\frac{\eta\,\sigma^2}{2}}.

where:

  • Var(θ∞)\sqrt{\mathrm{Var}(\theta_\infty)}: the standard deviation of the stationary estimate fluctuation, also called the noise ball radius
  • Var(θ∞)\mathrm{Var}(\theta_\infty): the stationary variance of the estimate around the true parameter
  • θ∞\theta_\infty: the stationary parameter estimate around which the variance is measured
  • η\eta: the learning rate
  • σ2\sigma^2: the observation noise variance

With η=0.02\eta = 0.02 and σ=0.05\sigma = 0.05, the approximate stationary standard deviation is about 0.0050.005. That is the scale of an instantaneous stationary fluctuation, not a hard detection limit: averaging or sequential tests can detect smaller persistent shifts. A change of 0.30.3 is much larger, and the roughly 50-step e-folding time means the estimate moves substantially toward it over tens of steps rather than settling immediately.

The tradeoff is now explicit. Increasing η\eta shortens the adaptation time and enlarges the noise ball. Decreasing η\eta does the reverse. There is no setting that makes both small; you are choosing where on the curve to sit. This is the same tradeoff that a replay buffer expresses in sample units, and the same tradeoff that a forgetting factor expresses as a discount rate. All three are parametrizations of a single decision about how much history to retain.

The figure below makes that frontier visible. Each point on the curve corresponds to one learning rate, with the adaptation time on the horizontal axis and the noise ball radius on the vertical axis.

In[5]:
Code
import numpy as np

sigma_x_sq = 1.0
sigma_noise = 0.05
eta_grid = np.linspace(0.002, 0.2, 200)

adaptation_time = -1.0 / np.log1p(-eta_grid * sigma_x_sq)
noise_ball_radius = np.sqrt(eta_grid * sigma_noise**2 / 2.0)

marked_eta = np.array([0.005, 0.02, 0.05, 0.1])
marked_time = -1.0 / np.log1p(-marked_eta * sigma_x_sq)
marked_radius = np.sqrt(marked_eta * sigma_noise**2 / 2.0)
marked_labels = [rf"$\eta={e}$" for e in marked_eta]
Out[6]:
Visualization
Curve showing adaptation time versus noise ball radius as learning rate varies.
The memory-noise frontier traced out by varying the learning rate, with input variance one and noise standard deviation 0.05. Each point corresponds to a different learning rate, with adaptation time on the horizontal axis and noise ball radius on the vertical axis. Reducing the noise ball requires reducing the learning rate, which lengthens adaptation time, showing that no setting makes both quantities small at once.

One more observation from the variance formula. The noise ball shrinks only as η\sqrt{\eta}, so halving the residual fluctuation requires quartering the learning rate, which quadruples the adaptation time. The returns to precision are poor. If you need a precise estimate, gradient descent with a fixed learning rate is the wrong tool; you want a method that reduces its effective step size as evidence accumulates, which is exactly what RLS does until it is given a forgetting factor.

The worked example also shows why the choice of learning rate depends on the scale of the change you expect. If the true coefficient changes by 0.3, a learning rate of 0.02 tracks it quickly. If the true coefficient changes by 0.003, that same learning rate cannot distinguish the change from noise. A practical system should therefore relate its learning rate to the smallest change it needs to detect and the fastest change it needs to track. Those two requirements pull in opposite directions, and the resolution is usually to use a larger learning rate for adaptation and a smaller one for fine-tuning, or to use a method that adapts the learning rate itself.