pub struct Ucb1 { /* private fields */ }Expand description
A deterministic UCB1 multi-armed bandit.
Balances exploration (try arms whose value is uncertain) and exploitation
(favour the arm with the best observed reward) using the classic upper
confidence bound x̄ᵢ + c·√(ln N / nᵢ). Unpulled arms are tried first. No
randomness, so the same reward stream always yields the same decisions —
which is what makes the adaptive layer reproducible.
Implementations§
Source§impl Ucb1
impl Ucb1
Sourcepub const DEFAULT_EXPLORATION: f64 = std::f64::consts::SQRT_2
pub const DEFAULT_EXPLORATION: f64 = std::f64::consts::SQRT_2
Default exploration constant c = √2, the textbook UCB1 value.
Sourcepub fn new(num_arms: usize) -> Self
pub fn new(num_arms: usize) -> Self
Creates a bandit with num_arms arms (clamped to at least 1) and the
default exploration constant.
Sourcepub fn with_exploration(num_arms: usize, exploration: f64) -> Self
pub fn with_exploration(num_arms: usize, exploration: f64) -> Self
Creates a bandit with an explicit exploration constant c (higher = more
exploration).
Sourcepub fn pulls(&self, arm: usize) -> u64
pub fn pulls(&self, arm: usize) -> u64
Number of times arm has been pulled (0 if out of range).
Sourcepub fn select(&self) -> usize
pub fn select(&self) -> usize
Selects the next arm to try. Any never-pulled arm is chosen first (forced initial exploration); otherwise the arm with the highest 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 (incremental mean update). 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 current best arm by observed mean reward (pure exploitation), or
None until at least one arm has been pulled.
Sourcepub fn mean_reward(&self, arm: usize) -> Option<f64>
pub fn mean_reward(&self, arm: usize) -> Option<f64>
The observed mean reward for arm, or None if it hasn’t been pulled.