Expand description
Re-sampling functions for weighted sampling
§Example
use wheel_resample::resample;
let mut rng = rand::thread_rng();
let weights = [0.1, 0.2, 0.3, 0.8];
let population = vec![1, 2, 3, 4];
let samples = resample(&mut rng, &weights, &population);
assert_eq!(samples.len(), population.len());
// Make sure all samples are in the population
assert!(samples.iter().all(|s| population.contains(s)));Structs§
- Resample
Iterator - Resampler
- The Resampler can be turned into an Iterator to contineously pull sample indices
Functions§
- resample
- Returns a vector of weighted samples drawn from the population vector.
- resample_
idx - Returns a vector of n indices sampled according to the weights slice.