Re-sampling functions for weighted sampling
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)));
The Resampler can be turned into an Iterator to contineously pull sample indices
Returns a vector of weighted samples drawn from the population vector.
Returns a vector of n indices sampled according to the weights slice.