Struct Sampler

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

Encapsulates sampling steps. Specifically it does the followint steps:

  1. Samples an action from the Agent, apply to the Env and takes Step.
  2. Convert Step into a transition (typically a batch) with StepProcessor.
  3. Pushes the trainsition to ReplayBufferBase.
  4. Count episode length and pushes to Record.

TODO: being able to set interval_env_record

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 sampler.

Source

pub fn sample_and_push<A, R, R_>( &mut self, agent: &mut A, buffer: &mut R_, ) -> Result<Record>
where A: Agent<E, R>, R: ExperienceBufferBase<Item = P::Output> + ReplayBufferBase, R_: ExperienceBufferBase<Item = R::Item>,

Samples transitions and pushes them into the replay buffer.

The replay buffer R_, to which samples will be pushed, has to accept Item that are the same with Agent::R.

Source

pub fn fps(&mut self) -> f32

Returns frames (environment steps) per second, then resets the internal counter.

A frame involves taking action, applying it to the environment, producing transition, and pushing it into the replay buffer.

Source

pub fn reset_fps_counter(&mut self)

Reset stats for computing FPS.

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