pub struct ExperienceBuffer {
pub states: Vec<GameState>,
pub actions: Vec<Action>,
pub rewards: Vec<f32>,
pub capacity: usize,
}Expand description
Buffer for storing experience tuples for learning.
Fields§
§states: Vec<GameState>§actions: Vec<Action>§rewards: Vec<f32>§capacity: usizeImplementations§
Source§impl ExperienceBuffer
impl ExperienceBuffer
pub fn new(capacity: usize) -> Self
pub fn push(&mut self, state: GameState, action: Action, reward: f32)
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn sample_indices(&self, batch_size: usize, rng_seed: u64) -> Vec<usize>
pub fn sample_indices(&self, batch_size: usize, rng_seed: u64) -> Vec<usize>
Sample a random mini-batch of indices.
Sourcepub fn compute_returns(&self, gamma: f32) -> Vec<f32>
pub fn compute_returns(&self, gamma: f32) -> Vec<f32>
Compute discounted returns from the reward sequence.
pub fn clear(&mut self)
Sourcepub fn mean_reward(&self) -> f32
pub fn mean_reward(&self) -> f32
Mean reward across all stored experiences.
Auto Trait Implementations§
impl Freeze for ExperienceBuffer
impl RefUnwindSafe for ExperienceBuffer
impl Send for ExperienceBuffer
impl Sync for ExperienceBuffer
impl Unpin for ExperienceBuffer
impl UnsafeUnpin for ExperienceBuffer
impl UnwindSafe for ExperienceBuffer
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.