|
Celeritas 0.7.0-dev.196+develop.8d0d9047c
|
Sample from a normal distribution. More...
#include <NormalDistribution.hh>
Public Types | |
Type aliases | |
| using | real_type = RealType |
| using | result_type = real_type |
Public Member Functions | |
| CELER_FUNCTION | NormalDistribution (real_type mean, real_type stddev) |
| Construct with mean and standard deviation. | |
| CELER_FUNCTION | NormalDistribution (real_type mean) |
| Construct with unit deviation. | |
| CELER_FUNCTION | NormalDistribution () |
| Construct with unit deviation and zero mean. | |
| CELER_FUNCTION | NormalDistribution (NormalDistribution const &other) |
| Initialize with parameters but not spare values. | |
| CELER_FUNCTION | NormalDistribution (NormalDistribution &&other) noexcept |
| Reset spare value of other distribution. | |
| CELER_FUNCTION NormalDistribution & | operator= (NormalDistribution const &) |
| Keep spare value but change distribution. | |
| CELER_FUNCTION NormalDistribution & | operator= (NormalDistribution &&) noexcept |
| Possibly use spare value, change distribution. | |
| template<class Generator > | |
| CELER_FUNCTION result_type | operator() (Generator &rng) |
| template<class Generator > | |
| CELER_FUNCTION 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) \]