Skip to main content

TransitionBuffer

Struct TransitionBuffer 

Source
pub struct TransitionBuffer<B: Backend, SB: SliceAccess<B>, AB: SliceAccess<B>> { /* private fields */ }
Expand description

A tensor-backed circular buffer for transitions.

Uses SliceAccess to store state and action batches in contiguous tensor storage, enabling efficient random sampling via select. The buffer lazily initializes its storage on the first push call.

Implementations§

Source§

impl<B: Backend, SB: SliceAccess<B>, AB: SliceAccess<B>> TransitionBuffer<B, SB, AB>

Source

pub fn new(capacity: usize, device: &B::Device) -> Self

Creates a new buffer. Storage is lazily allocated on the first push.

Source

pub fn push( &mut self, state: SB, next_state: SB, action: AB, reward: f32, done: bool, )

Add a transition, overwriting the oldest if full.

Source

pub fn sample(&self, batch_size: usize) -> TransitionBatch<B, SB, AB>

Sample a random batch of transitions.

Source

pub fn len(&self) -> usize

Current number of stored transitions.

Source

pub fn is_empty(&self) -> bool

Whether the buffer is empty.

Source

pub fn capacity(&self) -> usize

Buffer capacity.

Auto Trait Implementations§

§

impl<B, SB, AB> Freeze for TransitionBuffer<B, SB, AB>

§

impl<B, SB, AB> RefUnwindSafe for TransitionBuffer<B, SB, AB>

§

impl<B, SB, AB> Send for TransitionBuffer<B, SB, AB>
where SB: Send, AB: Send,

§

impl<B, SB, AB> Sync for TransitionBuffer<B, SB, AB>
where SB: Sync, AB: Sync,

§

impl<B, SB, AB> Unpin for TransitionBuffer<B, SB, AB>

§

impl<B, SB, AB> UnsafeUnpin for TransitionBuffer<B, SB, AB>

§

impl<B, SB, AB> UnwindSafe for TransitionBuffer<B, SB, AB>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.