pub struct EpsilonGreedy { /* private fields */ }Expand description
Epsilon-greedy multi-armed bandit.
With probability epsilon, selects a uniformly random arm (exploration).
Otherwise, selects the arm with the highest estimated value (exploitation),
breaking ties by lowest index.
When constructed with EpsilonGreedy::with_decay, epsilon decays
exponentially as initial_epsilon * decay^t after each update, where t
is the total number of pulls so far.
§Example
use irithyll::bandits::{Bandit, EpsilonGreedy};
let mut bandit = EpsilonGreedy::new(3, 0.1);
for _ in 0..100 {
let arm = bandit.select_arm();
let reward = if arm == 0 { 1.0 } else { 0.0 };
bandit.update(arm, reward);
}
assert!(bandit.arm_values()[0] > bandit.arm_values()[1]);Implementations§
Source§impl EpsilonGreedy
impl EpsilonGreedy
Sourcepub fn new(n_arms: usize, epsilon: f64) -> Self
pub fn new(n_arms: usize, epsilon: f64) -> Self
Create an epsilon-greedy bandit with fixed epsilon and default seed (42).
Sourcepub fn with_seed(n_arms: usize, epsilon: f64, seed: u64) -> Self
pub fn with_seed(n_arms: usize, epsilon: f64, seed: u64) -> Self
Create an epsilon-greedy bandit with a custom RNG seed.
Sourcepub fn with_decay(n_arms: usize, epsilon: f64, decay: f64) -> Self
pub fn with_decay(n_arms: usize, epsilon: f64, decay: f64) -> Self
Create an epsilon-greedy bandit with exponential epsilon decay.
After each update, epsilon becomes initial_epsilon * decay^t where
t is the total number of pulls. A typical decay value is 0.999.
Sourcepub fn current_epsilon(&self) -> f64
pub fn current_epsilon(&self) -> f64
Current epsilon value (may differ from initial if decay is active).
Trait Implementations§
Source§impl Bandit for EpsilonGreedy
impl Bandit for EpsilonGreedy
Source§fn select_arm(&mut self) -> usize
fn select_arm(&mut self) -> usize
Source§fn update(&mut self, arm: usize, reward: f64)
fn update(&mut self, arm: usize, reward: f64)
Source§fn arm_values(&self) -> &[f64]
fn arm_values(&self) -> &[f64]
Source§fn arm_counts(&self) -> &[u64]
fn arm_counts(&self) -> &[u64]
Source§impl Clone for EpsilonGreedy
impl Clone for EpsilonGreedy
Source§fn clone(&self) -> EpsilonGreedy
fn clone(&self) -> EpsilonGreedy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more