Struct Sampler

Source
pub struct Sampler<E, P>
where E: Env, P: StepProcessor<E>,
{ /* private fields */ }
Expand description

Manages the sampling of experiences from the environment.

This struct handles the interaction between the agent and environment, processes the resulting experiences, and stores them in a replay buffer. It also tracks various metrics about the sampling process.

§Type Parameters

  • E - The environment type
  • P - The step processor type

Implementations§

Source§

impl<E, P> Sampler<E, P>
where E: Env, P: StepProcessor<E>,

Source

pub fn new(env: E, step_processor: P) -> Self

Creates a new sampler with the given environment and step processor.

§Arguments
  • env - The environment to sample from
  • step_processor - The processor for converting steps into transitions
§Returns

A new Sampler instance

Source

pub fn sample_and_push<R, R_>( &mut self, agent: &mut Box<dyn Agent<E, R>>, buffer: &mut R_, ) -> Result<Record>

Samples an experience and pushes it to the replay buffer.

This method:

  1. Resets the environment if needed
  2. Samples an action from the agent
  3. Applies the action to the environment
  4. Processes the resulting step
  5. Stores the experience in the replay buffer
§Arguments
  • agent - The agent to sample actions from
  • buffer - The replay buffer to store experiences in
§Returns

A Record containing metrics about the sampling process

§Errors

Returns an error if:

  • The environment fails to reset
  • The environment step fails
  • The replay buffer operation fails

Auto Trait Implementations§

§

impl<E, P> Freeze for Sampler<E, P>
where E: Freeze, P: Freeze, <E as Env>::Obs: Freeze,

§

impl<E, P> RefUnwindSafe for Sampler<E, P>

§

impl<E, P> Send for Sampler<E, P>
where E: Send, P: Send, <E as Env>::Obs: Send,

§

impl<E, P> Sync for Sampler<E, P>
where E: Sync, P: Sync, <E as Env>::Obs: Sync,

§

impl<E, P> Unpin for Sampler<E, P>
where E: Unpin, P: Unpin, <E as Env>::Obs: Unpin,

§

impl<E, P> UnwindSafe for Sampler<E, P>
where E: UnwindSafe, P: UnwindSafe, <E as Env>::Obs: UnwindSafe,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V