Struct 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>
impl<D, I> SamplerDataset<D, I>
pub fn new(dataset:
D, size: usize)
-> SamplerDataset<D,
I>
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>
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>
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>
impl<D, I> Dataset<I> for SamplerDataset<D, I>
§
fn iter(&self) -> DatasetIterator<'_,
I> ⓘ
where
Self: Sized,
fn iter(&self) -> DatasetIterator<'_,
I> ⓘ
where
Self: Sized,
Auto Trait Implementations§
impl<D, I> !Freeze for SamplerDataset<D, I>
impl<D, I> RefUnwindSafe for SamplerDataset<D,
I>where
D: RefUnwindSafe,
I: RefUnwindSafe,
impl<D, I> Send for SamplerDataset<D, I>
impl<D, I> Sync for SamplerDataset<D, I>
impl<D, I> Unpin for SamplerDataset<D, I>
impl<D, I> UnwindSafe for SamplerDataset<D,
I>where
D: UnwindSafe,
I: UnwindSafe,
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
§
impl<T> Instrument for T
impl<T> Instrument for T
§
fn instrument(self, span: Span) ->
Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§
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
more
Source§
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
§
impl<T> Pointable for T
impl<T> Pointable for T
§
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§
impl<I, T> Windows<I> for T
where
T: Dataset<I>,
impl<I, T> Windows<I> for T
where
T: Dataset<I>,
§
fn windows(&self, size: usize)
-> WindowsIterator<'_,
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
}