pub struct WeightedRandomSampler { /* private fields */ }Expand description
Weighted random sampler: draws num_samples indices with probability proportional to weights.
Useful for imbalanced datasets where minority classes should be oversampled.
Implementations§
Source§impl WeightedRandomSampler
impl WeightedRandomSampler
Sourcepub fn new(
weights: Vec<f64>,
num_samples: usize,
seed: u64,
) -> Result<Self, ModelError>
pub fn new( weights: Vec<f64>, num_samples: usize, seed: u64, ) -> Result<Self, ModelError>
Creates a new weighted sampler.
weights: per-sample weight (higher = more likely to be sampled).
num_samples: how many indices to draw per epoch.
seed: deterministic random seed.
Sourcepub fn indices(&self) -> Vec<usize>
pub fn indices(&self) -> Vec<usize>
Draw num_samples indices with replacement, proportional to weights.
Sourcepub fn num_samples(&self) -> usize
pub fn num_samples(&self) -> usize
Number of samples drawn per epoch.
Trait Implementations§
Source§impl Clone for WeightedRandomSampler
impl Clone for WeightedRandomSampler
Source§fn clone(&self) -> WeightedRandomSampler
fn clone(&self) -> WeightedRandomSampler
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for WeightedRandomSampler
impl RefUnwindSafe for WeightedRandomSampler
impl Send for WeightedRandomSampler
impl Sync for WeightedRandomSampler
impl Unpin for WeightedRandomSampler
impl UnsafeUnpin for WeightedRandomSampler
impl UnwindSafe for WeightedRandomSampler
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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 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>
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