Struct burn::data::dataset::transform::SamplerDataset

pub struct SamplerDataset<D, I> { /* private fields */ }
Expand description

Sample items from a dataset.

This is an convenient way of modeling a dataset as a probability distribution of a fixed size. You have multiple options to instantiate the dataset sampler.

  • With replacement (Default): This is the most efficient way of using the sampler because no state is required to keep indices that have been selected.

  • Without replacement: This has a similar effect to using a shuffled dataset, but with more flexibility since you can set the dataset to an arbitrary size. Once every item has been used, a new cycle is created with a new random suffle.

Implementations§

§

impl<D, I> SamplerDataset<D, I>
where D: Dataset<I>, I: Send + Sync,

pub fn new(dataset: D, size: usize) -> SamplerDataset<D, I>

Creates a new sampler dataset with replacement.

pub fn with_replacement(dataset: D, size: usize) -> SamplerDataset<D, I>

Creates a new sampler dataset with replacement.

pub fn without_replacement(dataset: D, size: usize) -> SamplerDataset<D, I>

Creates a new sampler dataset without replacement.

Trait Implementations§

§

impl<D, I> Dataset<I> for SamplerDataset<D, I>
where D: Dataset<I>, I: Send + Sync,

§

fn get(&self, index: usize) -> Option<I>

Gets the item at the given index.
§

fn len(&self) -> usize

Gets the number of items in the dataset.
§

fn is_empty(&self) -> bool

Checks if the dataset is empty.
§

fn iter(&self) -> DatasetIterator<'_, I>
where Self: Sized,

Returns an iterator over the dataset.

Auto Trait Implementations§

§

impl<D, I> !Freeze for SamplerDataset<D, I>

§

impl<D, I> RefUnwindSafe for SamplerDataset<D, I>

§

impl<D, I> Send for SamplerDataset<D, I>
where D: Send, I: Send,

§

impl<D, I> Sync for SamplerDataset<D, I>
where D: Sync, I: Sync,

§

impl<D, I> Unpin for SamplerDataset<D, I>
where D: Unpin, I: Unpin,

§

impl<D, I> UnwindSafe for SamplerDataset<D, I>
where D: UnwindSafe, I: UnwindSafe,

Blanket Implementations§

§

impl<T> Adaptor<()> for T

§

fn adapt(&self)

Adapt the type to be passed to a metric.
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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

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

§

fn vzip(self) -> V

§

impl<I, T> Window<I> for T
where T: Dataset<I> + ?Sized,

§

fn window(&self, current: usize, size: NonZero<usize>) -> Option<Vec<I>>

Creates a window of a collection. Read more
§

impl<I, T> Windows<I> for T
where T: Dataset<I>,

§

fn windows(&self, size: usize) -> WindowsIterator<'_, I>

Is empty if the Dataset is shorter than size.

§Panics

Panics if size is 0.

§Examples
use crate::burn_dataset::{
   transform::{Windows, WindowsDataset},
   Dataset, InMemDataset,
};

let items = [1, 2, 3, 4].to_vec();
let dataset = InMemDataset::new(items.clone());

for window in dataset.windows(2) {
 // do sth with window
}
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,