|
ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
|
Discrete uniform random integer generator over [min, max]. More...
#include <Uniform.hpp>
Public Member Functions | |
| Uniform (int min, int max) | |
| Construct a uniform integer generator over [min, max]. | |
| std::vector< int > | distinct (int count, RNG &rng) |
| Sample without replacement from [min, max]. | |
| std::vector< int > | operator() (int count, RNG &rng) const |
| Generate multiple uniform random integers (with replacement). | |
| int | operator() (RNG &rng) const |
| Generate a single uniform random integer in [min, max]. | |
Discrete uniform random integer generator over [min, max].
All random integers are produced via Lemire's nearly-divisionless method, which replaces the classical modulo reduction with a multiply-and-shift, falling back to rejection sampling only when needed to eliminate bias. This is both faster and provably unbiased.
The distinct() method builds on this by performing a Fisher-Yates (Knuth) shuffle to sample without replacement — the foundation of bootstrap sampling and random variable selection in forests.
| ppforest2::stats::Uniform::Uniform | ( | int | min, |
| int | max ) |
Construct a uniform integer generator over [min, max].
| min | Inclusive lower bound (must be ≥ 0). |
| max | Inclusive upper bound (must be ≥ min). |
| std::vector< int > ppforest2::stats::Uniform::distinct | ( | int | count, |
| RNG & | rng ) |
Sample without replacement from [min, max].
Implements the Fisher-Yates (Knuth) shuffle: fills a vector with [min, max], shuffles it using gen_lemire() for each swap, and returns the first count elements. The result is a uniformly distributed subset of size count with no repeats.
This is the method used by DRUniformStrategy and bootstrap sampling, ensuring reproducible variable selection across platforms.
| count | Number of distinct integers to draw (≤ range size). |
| rng | Random number generator (pcg32). |
count distinct integers from [min, max]. | std::vector< int > ppforest2::stats::Uniform::operator() | ( | int | count, |
| RNG & | rng ) const |
Generate multiple uniform random integers (with replacement).
| count | Number of samples to generate. |
| rng | Random number generator (pcg32). |
count i.i.d. integers from [min, max]. | int ppforest2::stats::Uniform::operator() | ( | RNG & | rng | ) | const |
Generate a single uniform random integer in [min, max].
| rng | Random number generator (pcg32). |