|
Celeritas 0.7+0c5d30b
|
Sample from a normal distribution. More...
#include <NormalDistribution.hh>
Public Types | |
Type aliases | |
| using | real_type = RealType |
| using | result_type = real_type |
| using | RecordT = NormalDistributionRecord |
Public Member Functions | |
| NormalDistribution (real_type mean, real_type stddev) | |
| Construct with mean and standard deviation. | |
| NormalDistribution (real_type mean) | |
| Construct with unit deviation. | |
| NormalDistribution (RecordT const &record) | |
| NormalDistribution () | |
| Construct with unit deviation and zero mean. | |
| template<class Generator > | |
| result_type | operator() (Generator &rng) |
| template<class Generator > | |
| auto | operator() (Generator &rng) -> result_type |
| Sample a random number according to the distribution. | |
Sample from a normal distribution.
The normal (Gaussian) distribution is
\[ p(x) = \exp\!\left( -\frac{(x - \mu)^{2}}{2\sigma^{2}} \right) \]
with mean \(\mu\) and standard deviation \(\sigma\).
This implementation uses the Box-Muller transform to generate pairs of independent, normally distributed random numbers, and returns them one at a time. Two random numbers uniformly distributed on [0, 1] are mapped to two independent, standard, normally distributed samples using the relations:
\[ x_1 = \sqrt{-2 \ln \xi_1} \cos(2 \pi \xi_2) x_2 = \sqrt{-2 \ln \xi_1} \sin(2 \pi \xi_2) \]