Kokkos compatible method to draw from specific probability distribution.
More...
|
| template<FloatingPointType F> |
| KOKKOS_INLINE_FUNCTION F | erfinv (F x) |
| | Computes an approximation of the inverse error function.
|
| template<FloatingPointType F> |
| KOKKOS_INLINE_FUNCTION F | norminv (F p, F mean, F stddev) |
| | Computes the inverse CDF (probit function) of a normal distribution.
|
| template<FloatingPointType F> |
| KOKKOS_INLINE_FUNCTION F | std_normal_pdf (F x) |
| | Computes the standard normal probability density function (PDF).
|
| template<FloatingPointType F> |
| KOKKOS_INLINE_FUNCTION F | std_normal_cdf (F x) |
| | Computes the standard normal cumulative distribution function (CDF).
|
Kokkos compatible method to draw from specific probability distribution.
◆ erfinv()
| KOKKOS_INLINE_FUNCTION F MC::Distributions::erfinv |
( |
F | x | ) |
|
Computes an approximation of the inverse error function.
This function approximates the inverse error function erfinv(x) using Winitzki’s method (from A. Soranzo, E. Epure), which provides a simple and computationally efficient formula based on logarithms and square roots.
- Template Parameters
-
- Parameters
-
| x | Input value in the range [-1, 1]. |
- Returns
- Approximate value of erfinv(x).`.
- Note
- This implementation is not highly optimized for GPUs. For a more accurate and efficient implementation, see: https://people.maths.ox.ac.uk/gilesm/codes/erfinv/gems.pdf. See also bramowitz and Stegun method (Handbook of Mathematical Functions, formula 7.1.26)
- Warning
- This approximation is not valid for extreme values |x| close to 1.
◆ norminv()
| KOKKOS_INLINE_FUNCTION F MC::Distributions::norminv |
( |
F | p, |
|
|
F | mean, |
|
|
F | stddev ) |
Computes the inverse CDF (probit function) of a normal distribution.
This function returns the quantile function of a normal distribution with mean mean and standard deviation stddev, given a probability p.
- Template Parameters
-
- Parameters
-
| p | Probability value in the range (0,1). |
| mean | Mean of the normal distribution. |
| stddev | Standard deviation of the normal distribution. |
- Returns
- The corresponding value x such that P(X ≤ x) = p for X ~ N(mean,
stddev).
- Note
- This implementation uses the inverse error function erfinv(x) for accuracy and efficiency. Extreme values may be clamped for stability.
- Warning
- p must be strictly in (0,1), otherwise the result is undefined.
◆ std_normal_cdf()
| KOKKOS_INLINE_FUNCTION F MC::Distributions::std_normal_cdf |
( |
F | x | ) |
|
Computes the standard normal cumulative distribution function (CDF).
The standard normal CDF is given by:
\[ \Phi(x) = \frac{1}{2} \left( 1 + \operatorname{erf} \left(
\frac{x}{\sqrt{2}} \right) \right)
\]
- Template Parameters
-
- Parameters
-
- Returns
- Value of the standard normal CDF at x, which is P(X ≤ x) for X ~ N(0,1).
◆ std_normal_pdf()
| KOKKOS_INLINE_FUNCTION F MC::Distributions::std_normal_pdf |
( |
F | x | ) |
|
Computes the standard normal probability density function (PDF).
The standard normal PDF is given by:
\[ \phi(x) = \frac{1}{\sqrt{2\pi}} e^{-x^2 / 2}
\]
- Template Parameters
-
- Parameters
-
- Returns
- Value of the standard normal PDF at x.
- Note
- This function is numerically stable.