forked from rust-random/rand
-
Notifications
You must be signed in to change notification settings - Fork 2
Closed
Labels
Description
This part of rand has needed work for a while, and hasn't had much love recently, excepting the excellent work on seq::sample* by @vitiral.
WeightedChoice is a distribution for sampling one item from a slice, with weights. The current API only accepts a slice (reference) and clones objects when sampling.
The seq module has functions to:
- sample a set number of items from an iterator of unknown length, returning some of the iterated items
- sample a set number of items from a slice, returning clones of the items
- sample a set number of items from a slice, returning references into the original slice
Issues to solve:
- Is this sufficiently generic/flexible? Do we cover all expected functionality?
- Is the code succinct?
- Is the documentation sufficient?
- Why are
WeightedChoiceandseq::*in completely separate modules, the first as a distribution the second as simple functions? - Is there excess functionality which arguably doesn't belong in
rand?
References:
- implementation of
seq::* - seq optimisation: investigate using sample_iter instead of sample_indicies_inplace rust-random/rand#203 [opt]: investigate using sample_iter instead of sample_indicies_inplace
samplewith random ordering rust-random/rand#169 [alg]: sampling with randomised ordering- investigate generic
sample_indiciesrust-random/rand#202 [API]: investigate genericsample_indicies WeightedChoiceis hard to use with borrow checker rust-random/rand#142 [API]:WeightedChoiceis hard to use with borrow checker- Consider adding an owned version of WeightedChoice rust-random/rand#90 [API]: Consider adding an owned version of WeightedChoice
- Add an owned variant of WeightedChoice. rust-random/rand#152 [API PR]: Add an owned variant of WeightedChoice
- Merging Rust Random Choice rust-random/rand#110 [API+alg]:
RandomChoiceimpl - Consider pruning gen_weighted_bool rust-random/rand#47 [API]: Consider pruning gen_weighted_bool
- Add Rng::pick method rust-random/rand#198 [API+alg PR]: Add
Rng::pick/Choose - Missing runtime in WeightedChoice rust-random/rand#116 [doc]: no doc for algorithm complexity
- Partial refactoring I did in this branch: API doc (makes
WeightedChoiceowning, addsChoose, some reorganisation)
I'm going to say nothing is fixed at this point. In theory it would be nice not to break the new seq code.
schneiderfelipe