Normal double sampler.
More...
Go to the source code of this file.
◆ cfe_normal_double
Samples random values from the normal (Gaussian) probability distribution, centered on 0. This sampler works in a way that first samples from a normal_cumulative with some small sigma and then using another sampling from uniform distribution creates a candidate for the output, which is accepted or rejected with certain probability. Note that the sampler offers arbitrary precision but the implementation is not constant time.
◆ cfe_normal_double_init()
cfe_error cfe_normal_double_init |
( |
cfe_normal_double * |
s, |
|
|
mpf_t |
sigma, |
|
|
size_t |
n, |
|
|
mpf_t |
first_sigma |
|
) |
| |
Initializes an instance of cfe_normal_double sampler. It assumes mean = 0. Values are precomputed when this function is called, so that normal_double_sample merely returns a precomputed value. sigma should be a multiple of first_sigma. Increasing first_sigma a bit speeds up the algorithm but increases the size of the precomputed values.
- Parameters
-
s | A pointer to an uninitialized struct representing the sampler |
sigma | Standard deviation |
n | Precision parameter |
first_sigma | Standard deviation for the cumulative sampler |
- Returns
◆ cfe_normal_double_free()
Frees the memory occupied by the struct members. It does not free memory occupied by the struct itself.
- Parameters
-
◆ cfe_normal_double_sample()
Samples according to discrete Gauss distribution using normal_double and second sampling.
- Parameters
-
res | The random number (result value will be stored here) |
s | A pointer to an instance of the sampler (initialized cfe_normal_double struct) |
◆ cfe_normal_double_sample_vec()
Sets the elements of the vector to random numbers with the normal_double sampler.
◆ cfe_normal_double_sample_mat()
Sets the elements of a matrix to random numbers with the normal_double sampler.