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 typeP
- The step processor type
Implementations§
Source§impl<E, P> Sampler<E, P>where
E: Env,
P: StepProcessor<E>,
impl<E, P> Sampler<E, P>where
E: Env,
P: StepProcessor<E>,
Sourcepub fn sample_and_push<R, R_>(
&mut self,
agent: &mut Box<dyn Agent<E, R>>,
buffer: &mut R_,
) -> Result<Record>where
R: ExperienceBufferBase<Item = P::Output> + ReplayBufferBase,
R_: ExperienceBufferBase<Item = R::Item>,
pub fn sample_and_push<R, R_>(
&mut self,
agent: &mut Box<dyn Agent<E, R>>,
buffer: &mut R_,
) -> Result<Record>where
R: ExperienceBufferBase<Item = P::Output> + ReplayBufferBase,
R_: ExperienceBufferBase<Item = R::Item>,
Samples an experience and pushes it to the replay buffer.
This method:
- Resets the environment if needed
- Samples an action from the agent
- Applies the action to the environment
- Processes the resulting step
- Stores the experience in the replay buffer
§Arguments
agent
- The agent to sample actions frombuffer
- 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>
impl<E, P> RefUnwindSafe for Sampler<E, P>
impl<E, P> Send for Sampler<E, P>
impl<E, P> Sync for Sampler<E, P>
impl<E, P> Unpin for Sampler<E, P>
impl<E, P> UnwindSafe for Sampler<E, P>
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