Struct SamplerDataset
pub struct SamplerDataset<D, I> { /* private fields */ }Expand description
Sample items from a dataset.
This is a 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<O>(dataset: D, options: O) -> SamplerDataset<D, I>where
O: Into<SamplerDatasetOptions>,
pub fn new<O>(dataset: D, options: O) -> SamplerDataset<D, I>where
O: Into<SamplerDatasetOptions>,
Creates a new sampler dataset with replacement.
When the sample size is less than or equal to the source dataset size, data will be sampled without replacement from the source dataset in a uniformly shuffled order.
When the sample size is greater than the source dataset size, the entire source dataset will be sampled once for every multiple of the size ratios; with the remaining samples taken without replacement uniformly from the source. All samples will be returned uniformly shuffled.
§Arguments
dataset: the dataset to wrap.options: the options to configure the sampler dataset.
§Examples
use burn_dataset::transform::{
SamplerDataset,
SamplerDatasetOptions,
};
// Examples below assuming `dataset.len()` = `10`.
// sample size: 5
// WithReplacement
// rng: StdRng::from_os_rng()
SamplerDataset::new(dataset, 5);
// sample size: 10 (source)
// WithReplacement
// rng: StdRng::from_os_rng()
SamplerDataset::new(dataset, SamplerDatasetOptions::default());
// sample size: 15
// WithoutReplacement
// rng: StdRng::seed_from_u64(42)
SamplerDataset::new(
dataset,
SamplerDatasetOptions::default()
.with_size(1.5)
.without_replacement()
.with_rng(42),
);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.
§Arguments
dataset: the dataset to wrap.size: the effective size of the sampled dataset.
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.
When the sample size is less than or equal to the source dataset size, data will be sampled without replacement from the source dataset in a uniformly shuffled order.
When the sample size is greater than the source dataset size, the entire source dataset will be sampled once for every multiple of the size ratios; with the remaining samples taken without replacement uniformly from the source. All samples will be returned uniformly shuffled.
§Arguments
dataset: the dataset to wrap.size: the effective size of the sampled dataset.
pub fn is_with_replacement(&self) -> bool
pub fn is_with_replacement(&self) -> bool
Determines if the sampler is using the “with replacement” strategy.
§Returns
true: If the sampler is configured to sample with replacement.false: If the sampler is configured to sample without replacement.
Trait Implementations§
§impl<D, I> Dataset<I> for SamplerDataset<D, I>
impl<D, I> Dataset<I> for SamplerDataset<D, I>
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
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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<I, T> Windows<I> for Twhere
T: Dataset<I>,
impl<I, T> Windows<I> for Twhere
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
}