pub struct NStepBuffer { /* private fields */ }Expand description
Circular accumulator for n-step returns.
Implementations§
Source§impl NStepBuffer
impl NStepBuffer
Sourcepub fn new(n: usize, gamma: f32) -> Self
pub fn new(n: usize, gamma: f32) -> Self
Create an n-step buffer.
n— number of steps to accumulate.gamma— discount factor γ ∈ (0, 1].
§Panics
Panics if n == 0.
Sourcepub fn push(
&mut self,
obs: impl Into<Vec<f32>>,
action: impl Into<Vec<f32>>,
reward: f32,
next_obs: impl Into<Vec<f32>>,
done: bool,
) -> Option<NStepTransition>
pub fn push( &mut self, obs: impl Into<Vec<f32>>, action: impl Into<Vec<f32>>, reward: f32, next_obs: impl Into<Vec<f32>>, done: bool, ) -> Option<NStepTransition>
Push a (obs, action, reward, next_obs, done) step.
Returns Some(NStepTransition) once n steps have been accumulated
(or immediately on terminal). Returns None while the buffer is still
filling up.
Sourcepub fn flush(&mut self) -> Vec<NStepTransition>
pub fn flush(&mut self) -> Vec<NStepTransition>
Flush any remaining steps in the buffer (for end-of-episode cleanup).
Returns all remaining n-step transitions.
Sourcepub fn try_get(&self) -> RlResult<NStepTransition>
pub fn try_get(&self) -> RlResult<NStepTransition>
Attempt to produce an n-step transition from the current state.
§Errors
RlError::NStepIncompleteif fewer thannsteps have been accumulated.
Trait Implementations§
Source§impl Clone for NStepBuffer
impl Clone for NStepBuffer
Source§fn clone(&self) -> NStepBuffer
fn clone(&self) -> NStepBuffer
Returns a duplicate of the value. Read more
1.0.0 · 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 NStepBuffer
impl RefUnwindSafe for NStepBuffer
impl Send for NStepBuffer
impl Sync for NStepBuffer
impl Unpin for NStepBuffer
impl UnsafeUnpin for NStepBuffer
impl UnwindSafe for NStepBuffer
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