pub struct EpsilonGreedy { /* private fields */ }Available on crate feature
bandit only.Expand description
Epsilon-Greedy multi-armed bandit.
With probability epsilon, selects a random arm; otherwise selects the
arm with the highest observed mean reward. Supports optional epsilon decay.
§Examples
use rill_ml::bandit::{Bandit, EpsilonGreedy, EpsilonGreedyConfig};
use rand::SeedableRng;
use rand_chacha::ChaCha8Rng;
let mut rng = ChaCha8Rng::seed_from_u64(0);
let mut bandit = EpsilonGreedy::new(3, EpsilonGreedyConfig::default()).unwrap();
let arm = bandit.select(&mut rng).unwrap();
bandit.update(arm, 1.0).unwrap();
assert_eq!(bandit.samples_seen(), 1);Implementations§
Source§impl EpsilonGreedy
impl EpsilonGreedy
Sourcepub fn new(
arm_count: usize,
config: EpsilonGreedyConfig,
) -> Result<Self, RillError>
pub fn new( arm_count: usize, config: EpsilonGreedyConfig, ) -> Result<Self, RillError>
Create a new epsilon-greedy bandit.
§Errors
Returns RillError::InvalidArmCount if arm_count is zero.
Returns RillError::InvalidEpsilon if epsilon is not in [0, 1].
Returns RillError::InvalidParameter if decay is not in (0, 1].
Sourcepub const fn current_epsilon(&self) -> f64
pub const fn current_epsilon(&self) -> f64
The current (possibly decayed) epsilon value.
Sourcepub fn total_rewards(&self) -> &[f64]
pub fn total_rewards(&self) -> &[f64]
Per-arm total rewards (diagnostic).
Trait Implementations§
Source§impl Bandit for EpsilonGreedy
impl Bandit for EpsilonGreedy
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
Source§impl Clone for EpsilonGreedy
impl Clone for EpsilonGreedy
Source§fn clone(&self) -> EpsilonGreedy
fn clone(&self) -> EpsilonGreedy
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for EpsilonGreedy
impl RefUnwindSafe for EpsilonGreedy
impl Send for EpsilonGreedy
impl Sync for EpsilonGreedy
impl Unpin for EpsilonGreedy
impl UnsafeUnpin for EpsilonGreedy
impl UnwindSafe for EpsilonGreedy
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