pub struct SlidingWindowUcb1 { /* private fields */ }Expand description
A sliding-window UCB1 bandit for non-stationary rewards.
Plain Ucb1 assumes the reward distribution never changes, so its
confidence bound shrinks as 1/√n forever and old samples pin the estimate
— which is wrong for a game session, where the best layout in a quiet scene
is not the best in a crowded one. This variant scores each arm over only its
most recent window rewards (a per-arm ring buffer), so it keeps adapting
when the workload shifts. It is still fully deterministic (no RNG), matching
the reproducibility the adaptive layer requires.
(Garivier & Moulines, On Upper-Confidence Bound Policies for Non-Stationary Bandit Problems, 2011 — the SW-UCB construction.)
Implementations§
Source§impl SlidingWindowUcb1
impl SlidingWindowUcb1
Sourcepub fn new(num_arms: usize, window: usize) -> Self
pub fn new(num_arms: usize, window: usize) -> Self
Creates a bandit with num_arms arms (min 1), each scored over its last
window rewards (min 1), using the default exploration constant √2.
Sourcepub fn with_exploration(
num_arms: usize,
window: usize,
exploration: f64,
) -> Self
pub fn with_exploration( num_arms: usize, window: usize, exploration: f64, ) -> Self
Creates a bandit with an explicit exploration constant c.
Sourcepub fn samples(&self, arm: usize) -> usize
pub fn samples(&self, arm: usize) -> usize
How many rewards are currently retained for arm (capped at the window).
Sourcepub fn select(&self) -> usize
pub fn select(&self) -> usize
Selects the next arm: any arm with an empty window first (forced exploration), otherwise the highest windowed UCB score.
Sourcepub fn record(&mut self, arm: usize, reward: f64)
pub fn record(&mut self, arm: usize, reward: f64)
Records a reward for arm into its window (evicting the oldest once
full). Out-of-range arms and non-finite rewards are ignored.
Sourcepub fn best_arm(&self) -> Option<usize>
pub fn best_arm(&self) -> Option<usize>
The best arm by current windowed mean (pure exploitation), or None
until at least one arm has a reward.
Sourcepub fn mean_reward(&self, arm: usize) -> Option<f64>
pub fn mean_reward(&self, arm: usize) -> Option<f64>
The current windowed mean reward for arm, or None if its window is
empty.
Trait Implementations§
Source§impl Clone for SlidingWindowUcb1
impl Clone for SlidingWindowUcb1
Source§fn clone(&self) -> SlidingWindowUcb1
fn clone(&self) -> SlidingWindowUcb1
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more