Trait ReplayBufferBase

Source
pub trait ReplayBufferBase {
    type Config: Clone;
    type Batch;

    // Required methods
    fn build(config: &Self::Config) -> Self;
    fn batch(&mut self, size: usize) -> Result<Self::Batch>;
    fn update_priority(
        &mut self,
        ixs: &Option<Vec<usize>>,
        td_err: &Option<Vec<f32>>,
    );
}
Expand description

Interface for replay buffers that generate batches for training.

This trait provides functionality for sampling batches of experiences for training agents. It is independent of ExperienceBufferBase and focuses solely on the batch generation process.

§Associated Types

  • Config - Configuration parameters for the buffer
  • Batch - The type of batch generated for training

Required Associated Types§

Source

type Config: Clone

Configuration parameters for the replay buffer.

This type must implement Clone to support building multiple instances with the same configuration.

Source

type Batch

The type of batch generated for training.

This is typically a collection of experiences that can be used directly for training an agent.

Required Methods§

Source

fn build(config: &Self::Config) -> Self

Builds a new replay buffer from the given configuration.

§Arguments
  • config - The configuration parameters
§Returns

A new instance of the replay buffer

Source

fn batch(&mut self, size: usize) -> Result<Self::Batch>

Constructs a batch of experiences for training.

This method samples experiences from the buffer and returns them in a format suitable for training.

§Arguments
  • size - The number of experiences to include in the batch
§Returns

A batch of experiences or an error if sampling failed

Source

fn update_priority( &mut self, ixs: &Option<Vec<usize>>, td_err: &Option<Vec<f32>>, )

Updates the priorities of experiences in the buffer.

This method is used in prioritized experience replay to adjust the sampling probabilities of experiences based on their TD errors.

§Arguments
  • ixs - Optional indices of experiences to update
  • td_err - Optional TD errors for the experiences
§Note

This method is optional and may be moved to a separate trait in future versions to better support non-prioritized replay buffers.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§