#resample #sample

wheel-resample

Library for weighted sampling

2 releases

0.1.4 Mar 19, 2020
0.1.3 Mar 19, 2020
0.1.1 Mar 19, 2020
0.1.0 Mar 19, 2020

#4 in #resample

Download history 2/week @ 2024-02-25 9/week @ 2024-03-10 56/week @ 2024-03-31

65 downloads per month

MIT/Apache

8KB
93 lines

Library for drawing weighted samples from a population

Documentation and examples can be found here https://docs.rs/wheel-resample/


lib.rs:

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)));

Dependencies

~1MB
~17K SLoC