Non-Stationary Bandits
Sliding window UCB, discounted UCB, change-point detection, EXP3, REXP3
Standard UCB and Thompson Sampling are built for stationary reward distributions. They accumulate observations indefinitely — N_a(t) grows monotonically. An arm with millions of accumulated observations has a confidence interval so tight it never loses the argmax, even after its reward has collapsed.
The algorithm stays frozen on a historically dominant arm long after its true mean has dropped. The failure mode is slow: it takes O(N_a) new observations to substantially move the empirical mean — that is months of data for a heavily exploited arm. The right production strategy combines two mechanisms: CUSUM-based change detection for abrupt shifts (triggers an immediate statistics reset when a change is detected) and sliding window or discounted UCB for gradual drift (continuously forgets stale observations so the mean tracks recent reality). Predictable seasonality is not non-stationarity — weekly cycles belong in contextual features, not in a forgetting mechanism.
Key points
- Standard UCB/TS failure after a change point: UCB1 and standard TS accumulate all historical observations monotonically. For a previously dominant arm whose reward drops, N_a is large (tight confidence interval), the UCB stays high (empirical mean barely moves), and the algorithm continues exploiting it. The empirical mean only shifts substantially after O(N_a) new observations — for an arm with 50,000 observations, it takes thousands of post-change pulls to notice. Regret grows linearly after the change.
- Sliding window UCB (SW-UCB): maintain only the last W observations per arm. UCB $index = μ̂_a(W) + B√(ln t / min(N_a, W)). Old observations e$ xpire automatically — after a change, the window fills with new observations in W rounds. Optimal window W ≈ √(T/K) for infrequent abrupt changes; regret = O(√(KT)). The tradeoff: a small W adapts quickly but has high variance; a large W is stable but slow to adapt.
- **Discounted UCB (D-UCB): weight observations exponentially: $μ̂_a = Σ γ^(t−s) r_s / Σ γ^(t−s) where γ ∈ (0,1).** Effective me$ mory length ≈ 1/(1−γ) rounds. Smoother than SW-UCB — old observations don't vanish abruptly but fade gradually. Behaves like an exponential moving average of rewards. γ = 0.99 gives effective memory of 100 rounds; γ = 0.999 gives 1000 rounds.
- Change-point detection + reset: run CUSUM or Page-Hinkley on each arm's reward stream. CUSUM maintains a cumulative sum statistic and signals a change when it exceeds a threshold; Page-Hinkley is the same idea applied to a running mean-deviation statistic instead of raw reward. On detection, reset that arm's statistics (N_a = 0, μ̂_a = flat prior). More principled than windowing — only forgets when change is actually detected, not continuously. Requires tuning the detection threshold: low threshold → fast detection but frequent false alarms; high threshold → fewer false alarms but slow detection.
- EXP3 (Exponential-weight algorithm for Exploration and Exploitation): the adversarial bandit algorithm. Maintains weights w_a per arm. Selects arm with probability proportional to w_a plus uniform exploration floor γ/K. Importance-weights the observed reward: x̂_{a,t} = r_t / p_{a_t,t}. Updates: w_{a_t} ← w_{a_t} × exp(γ x̂_{a_t,t} / K). Achieves E[R_T] ≤ O(√(KT ln K)) against any adversarial sequence with no distributional assumptions.
- EXP3 importance-weighted reward: x̂_{a,t} = r_t / p_{a,t} × 1(a_t = a). Unbiased: E[x̂_{a,t}] = p_{a,t} × μ_a / p_{a,t} = μ_a. The importance weighting compensates for selection probability — rare arms have their observed rewards scaled up to correct for how rarely they are pulled. Variance is O(K/γ) per arm per round — high, especially with small γ. This is the cost of the adversarial guarantee: no distributional structure means you must pay for all information gathering.
- REXP3 (Restarting EXP3): for non-stationary adversarial settings with Υ change points, run EXP3 in epochs of length T/Υ, restarting at each epoch. If Υ is unknown, use a doubling schedule: epochs of length 1, 2, 4,... The cost of not knowing Υ is only logarithmic in T — the doubling trick loses at most a log-T factor relative to knowing Υ in advance.
- Seasonality is not non-stationarity. Weekly cycles and hour-of-day patterns are predictable and recurring. Sliding window and discounted UCB handle the weekend-weekday difference by forgetting weekday observations on weekends — discarding useful data. The correct treatment: include day_of_week and hour_of_day as context features in a contextual bandit. The model learns that preferences differ predictably by time. Non-stationary algorithms are for genuine concept drift and external shocks — not for predictable patterns.
- EXP3 vs UCB for moderately non-stationary settings: EXP3 achieves O(√(KT ln K)) against adversarial sequences but O(√(KT ln K)) is worse than UCB's O(log T) for stationary settings. In practice, most production problems have stochastic structure with occasional abrupt changes — neither purely stationary nor fully adversarial. Sliding window or discounted UCB typically outperforms EXP3 because they exploit stochastic structure when present. EXP3 is the right choice when the adversary is strategic or the reward distribution is fundamentally unpredictable.
Standard UCB/TS freezes on a historically dominant arm after a change point because N_a is too large for the empirical mean to move quickly — it takes O(N_a) post-change observations to detect the drop. The right production strategy combines CUSUM-based change detection for abrupt shifts (immediate statistics reset) and sliding window or discounted UCB for gradual drift (continuous forgetting). Predictable seasonality is not non-stationarity — recurring patterns belong in contextual features where the model learns them, not in a forgetting mechanism that discards them.
Recap
- Failure mode: standard UCB/TS freezes on a once-dominant arm — large N_a means the mean barely moves after a change.
- Detection is slow: O(N_a) post-change pulls needed — thousands of pulls for an arm with 50K observations.
- Sliding window UCB: keep last W observations; window fills with fresh data in W rounds; W ≈ √(T/K).
- Discounted UCB: $μ̂_a = Σ γ^(t−s) r_s / Σ γ^(t−s)$; effective memory ≈ 1/(1−γ); smoother than SW-UCB.
- CUSUM change detection + reset: forgets only when a change is actually detected, not continuously.
- EXP3 / REXP3: adversarial O(√(KT ln K)) via importance-weighted rewards; restart in epochs for Υ change points.
- NOT this: predictable seasonality isn't drift — put day_of_week / hour_of_day in context features, don't forget the data.
Check your understanding
Q1. You're running UCB on an ad creative rotation with K=5 creatives. Creative A dominated for 3 months, but a competitor launched a similar ad and A's CTR dropped from 8% to 2% overnight. Select the two true statements about the failure and fix.
- A) With N_A ≈ 50,000 observations the confidence interval is so tight that the empirical mean barely moves, needing O(N_A) post-change pulls to notice
- B) The fix is sliding window UCB or discounted UCB for gradual drift, combined with CUSUM monitoring that resets A's stats on abrupt detection
- C) UCB actually adapts within roughly 10 rounds regardless of history, since its confidence interval always shrinks to include the new true mean fast
- D) UCB fails here purely because it structurally does not support rotating more than 3 creatives at once in a single serving pool
Q2. Explain the EXP3 importance-weighted reward estimate x̂_{a,t} = r_t / p_{a,t}. Why is it unbiased and what is the variance?
- A) It is unbiased because E[x̂_{a,t}] = p_{a,t}·μ_a/p_{a,t} = μ_a; variance is bounded by K·r_max²/γ, the cost of robustness
- B) The estimate is actually biased overall, because dividing by p_{a,t} systematically amplifies noise for any arm with low selection probability
- C) The estimate is unbiased only in the special case where every arm happens to be selected with exactly equal probability each round
- D) The variance stays O(1) regardless of p_{a,t}, since the importance weighting term exactly and completely cancels out all added variance
Q3. In a content recommendation system with weekly seasonality (weekend vs weekday user preferences differ strongly), is non-stationary bandit the right framing? What would you do differently?
- A) Yes — weekly seasonality is itself a genuine form of non-stationarity, so sliding window UCB is straightforwardly the correct algorithm here
- B) It's predictable, recurring structure, not real drift — use a contextual bandit with day_of_week and hour_of_day as features
- C) The recommendation system should simply be retrained from scratch every single day to handle weekly seasonality, without any bandit algorithm
- D) Non-stationary bandits with γ = 0.99 discounting are the right choice, since weekly cycles happen to fall within that effective memory window
Q4. REXP3 restarts EXP3 every T/Υ rounds. Each restarted run is a fresh EXP3 instance over a horizon of length T/Υ, so it inherits the O(√(K·(T/Υ)·ln K)) bound taught above. Summing this bound across all Υ epochs, what is REXP3's total regret order, and how does it compare to the informal lower bound Ω(√(ΥKT))?
- A) Summing Υ epochs of O(√(K(T/Υ) ln K)) each gives Υ·√(K(T/Υ) ln K) = O(√(ΥKT ln K)) — matching the lower bound up to the ln K factor
- B) The per-epoch bounds add linearly to O(ΥKT ln K) — quadratically worse than the lower bound, since regret bounds never combine via square roots
- C) Restarting resets regret to zero at each epoch boundary, so REXP3's total regret is just the single-epoch bound O(√(K(T/Υ) ln K)), independent of Υ
- D) REXP3's regret is unrelated to the per-epoch EXP3 bound; it is a separate O(Υ^{1/3}K^{1/3}T^{2/3}) rate that must be taken on faith
Try it interactively
ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.
Open ML Systems Lab →