CiFEr
|
Normal cumulative sampler. More...
Go to the source code of this file.
Data Structures | |
struct | cfe_normal_cumulative |
Typedefs | |
typedef struct cfe_normal_cumulative | cfe_normal_cumulative |
Functions | |
void | cfe_normal_cumulative_init (cfe_normal_cumulative *s, mpf_t sigma, size_t n, bool two_sided) |
void | cfe_normal_cumulative_free (cfe_normal_cumulative *s) |
void | cfe_normal_cumulative_sample (mpz_t res, cfe_normal_cumulative *s) |
void | cfe_normal_cumulative_precompute (cfe_normal_cumulative *s) |
size_t | cfe_locate_int (mpz_t sample, size_t start, size_t end, cfe_vec *v, mpz_t middle_value) |
void | cfe_normal_cumulative_sample_vec (cfe_vec *res, cfe_normal_cumulative *s) |
void | cfe_normal_cumulative_sample_mat (cfe_mat *res, cfe_normal_cumulative *s) |
Normal cumulative sampler.
typedef struct cfe_normal_cumulative cfe_normal_cumulative |
cfe_normal_cumulative samples random values from the cumulative normal (Gaussian) probability distribution, centered on 0. This sampler is the fastest, but is limited only to cases when sigma is not too big, due to the sizes of the precomputed tables. Note that the sampler offers arbitrary precision but the implementation is not constant time.
void cfe_normal_cumulative_init | ( | cfe_normal_cumulative * | s, |
mpf_t | sigma, | ||
size_t | n, | ||
bool | two_sided | ||
) |
Initializes an instance of cfe_normal_cumulative sampler. It assumes mean = 0. Values are precomputed when this function is called, so that normal_cumulative_sample merely returns a precomputed value.
s | A pointer to an uninitialized struct representing the sampler |
sigma | Standard deviation |
n | Precision parameter |
two_sided | Boolean defining if we limit only to non-negative integers |
void cfe_normal_cumulative_free | ( | cfe_normal_cumulative * | s | ) |
Frees the memory occupied by the struct members. It does not free memory occupied by the struct itself.
s | A pointer to an instance of the sampler (initialized cfe_normal_cumulative struct) |
void cfe_normal_cumulative_sample | ( | mpz_t | res, |
cfe_normal_cumulative * | s | ||
) |
Samples discrete cumulative distribution with precomputed values.
res | The random number (result value will be stored here) |
s | A pointer to an instance of the sampler (initialized cfe_normal_cumulative struct) |
void cfe_normal_cumulative_precompute | ( | cfe_normal_cumulative * | s | ) |
Precomputes the values for sampling. This can be used only if sigma is not too big.
s | A pointer to an instance of the sampler (initialized cfe_normal_cumulative struct) |
size_t cfe_locate_int | ( | mpz_t | sample, |
size_t | start, | ||
size_t | end, | ||
cfe_vec * | v, | ||
mpz_t | middle_value | ||
) |
Given a random value from an interval and a cumulative distribution of mpz_t values, it returns a sample distributed accordingly using binary search
sample | Target integer |
start | Start index |
end | End index |
v | Vector of values |
middle_value | Temporary placeholder for value comparison (to avoid unnecessary memory allocations) |
void cfe_normal_cumulative_sample_vec | ( | cfe_vec * | res, |
cfe_normal_cumulative * | s | ||
) |
Sets the elements of a vector to random numbers with the normal_cumulative sampler.
void cfe_normal_cumulative_sample_mat | ( | cfe_mat * | res, |
cfe_normal_cumulative * | s | ||
) |
Sets the elements of a matrix to random numbers with the normal_cumulative sampler.