pub struct Ucb1 { /* private fields */ }Available on crate feature
bandit only.Expand description
UCB1 multi-armed bandit.
Selects arms using the upper confidence bound formula, which automatically
balances exploration and exploitation. Unpulled arms are always selected
first. Rewards passed to Bandit::update must be normalized to [0, 1].
§Examples
use rill_ml::bandit::{Bandit, Ucb1, Ucb1Config};
use rand::SeedableRng;
use rand_chacha::ChaCha8Rng;
let mut rng = ChaCha8Rng::seed_from_u64(0);
let mut bandit = Ucb1::new(3, Ucb1Config::default()).unwrap();
let arm = bandit.select(&mut rng).unwrap();
bandit.update(arm, 1.0).unwrap();
assert_eq!(bandit.samples_seen(), 1);Implementations§
Source§impl Ucb1
impl Ucb1
Sourcepub fn new(arm_count: usize, config: Ucb1Config) -> Result<Self, RillError>
pub fn new(arm_count: usize, config: Ucb1Config) -> Result<Self, RillError>
Create a new UCB1 bandit.
§Errors
Returns RillError::InvalidArmCount if arm_count is zero.
Returns RillError::InvalidParameter if exploration_constant is not
finite and positive.
Sourcepub fn total_rewards(&self) -> &[f64]
pub fn total_rewards(&self) -> &[f64]
Per-arm total rewards (diagnostic).
Trait Implementations§
Source§impl Bandit for Ucb1
impl Bandit for Ucb1
Source§fn samples_seen(&self) -> u64
fn samples_seen(&self) -> u64
How many total samples (arm pulls) the bandit has observed.
Source§fn select(&self, rng: &mut impl Rng) -> Result<usize, RillError>
fn select(&self, rng: &mut impl Rng) -> Result<usize, RillError>
Select an arm using the provided RNG for exploration. Read more
Auto Trait Implementations§
impl Freeze for Ucb1
impl RefUnwindSafe for Ucb1
impl Send for Ucb1
impl Sync for Ucb1
impl Unpin for Ucb1
impl UnsafeUnpin for Ucb1
impl UnwindSafe for Ucb1
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more