pub struct Demonstrations { /* private fields */ }Expand description
A fixed dataset of expert (observation, action) pairs for supervised
imitation learning.
Observations are stored as a single flat row-major Vec<f32> of shape
[len, obs_dim]; the discrete expert action for example i lives at
actions[i]. The dataset is immutable once constructed and serves
host-side minibatches by index via Demonstrations::batch.
Implementations§
Source§impl Demonstrations
impl Demonstrations
Sourcepub fn new(obs: Vec<f32>, actions: Vec<i64>, obs_dim: usize) -> Result<Self>
pub fn new(obs: Vec<f32>, actions: Vec<i64>, obs_dim: usize) -> Result<Self>
Build a dataset from a flat observation buffer and a parallel action vector.
obs must be row-major of length len * obs_dim and actions must
have length len, where len is inferred from actions. Returns an
Err if the lengths are inconsistent or obs_dim is zero.
§Arguments
obs- Flat row-major observations of shape[len, obs_dim].actions- Expert action index per example.obs_dim- Dimensionality of a single observation.
Sourcepub fn batch<B: Backend>(
&self,
indices: &[usize],
device: &B::Device,
) -> (Tensor<B, 2>, Tensor<B, 1, Int>)
pub fn batch<B: Backend>( &self, indices: &[usize], device: &B::Device, ) -> (Tensor<B, 2>, Tensor<B, 1, Int>)
Gather the given example indices into a minibatch of tensors.
Returns (obs, actions) where obs has shape [k, obs_dim] and
actions has shape [k], with k = indices.len(). Gathering is done
host-side; the resulting tensors are plain inputs/labels with no
gradient tracking concerns.
§Panics
Panics if any index is out of bounds (>= len).
§Arguments
indices- Example indices to gather into the minibatch.device- Backend device the tensors are allocated on.
Trait Implementations§
Source§impl Clone for Demonstrations
impl Clone for Demonstrations
Source§fn clone(&self) -> Demonstrations
fn clone(&self) -> Demonstrations
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for Demonstrations
impl RefUnwindSafe for Demonstrations
impl Send for Demonstrations
impl Sync for Demonstrations
impl Unpin for Demonstrations
impl UnsafeUnpin for Demonstrations
impl UnwindSafe for Demonstrations
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more