ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
ppforest2::stats::Normal Class Reference

Normal (Gaussian) random number generator. More...

#include <Normal.hpp>

Public Member Functions

 Normal (float mean, float std_dev)
 Construct a Normal generator.
 
std::vector< float > operator() (int count, RNG &rng)
 Generate multiple normal variates.
 
float operator() (RNG &rng)
 Generate a single normal variate via the Box-Muller transform.
 

Detailed Description

Normal (Gaussian) random number generator.

Generates samples from N(mean, std_dev²) using the Box-Muller transform. Each call to the RNG produces a pair of independent standard normal variates; the second is cached and returned on the next invocation, so roughly half of the calls avoid the expensive trigonometric computation.

Uniform inputs are generated internally at 53-bit precision (see gen_unif01()), matching the significand width of IEEE 754 double-precision floats.

Constructor & Destructor Documentation

◆ Normal()

ppforest2::stats::Normal::Normal ( float mean,
float std_dev )

Construct a Normal generator.

Parameters
meanDistribution mean.
std_devDistribution standard deviation.

Member Function Documentation

◆ operator()() [1/2]

std::vector< float > ppforest2::stats::Normal::operator() ( int count,
RNG & rng )

Generate multiple normal variates.

Parameters
countNumber of samples to generate.
rngRandom number generator (pcg32).
Returns
Vector of count samples from N(mean, std_dev²).

◆ operator()() [2/2]

float ppforest2::stats::Normal::operator() ( RNG & rng)

Generate a single normal variate via the Box-Muller transform.

Draws two independent uniform variates U1, U2 ∈ (0, 1) and computes a pair of standard normal variates:

Z1 = √(−2 ln U1) · cos(2π U2) Z2 = √(−2 ln U1) · sin(2π U2)

Returns Z1 (after denormalization) and caches Z2 for the next call. When a cached value is available it is returned directly without generating new uniform inputs.

Parameters
rngRandom number generator (pcg32).
Returns
A sample from N(mean, std_dev²).

The documentation for this class was generated from the following file: