Rust Random Choice
Chooses samples randomly by their weights/probabilities.
Advantages
- There is a good diversity for the case that all weights are equally distributed (in contrast to the roulette wheel selection algorithm)
- Blazingly fast: O(n) (Roulette wheel selection algorithm: O(n * log n))
- Memory Usage: O(n)
- The sum of the weights don't have to be 1.0, but must not overflow
This algorithm is based on the stochastic universal sampling algorithm.
Applications
- Evolutionary algorithms: Choose the n fittest populations by their fitness fi
- Monte Carlo Localization: Resampling of n particles by their weight w
Usage
Add this to your Cargo.toml
:
[]
= "*"
Examples
Default Way
extern crate random_choice;
use random_choice;
With Custom Seed
extern crate rand;
extern crate random_choice;
use RandomChoice;
use SeedableRng;