CiFEr
Data Structures | Typedefs | Functions
normal_cumulative.h File Reference

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)
 

Detailed Description

Normal cumulative sampler.

Typedef Documentation

◆ 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.

Function Documentation

◆ cfe_normal_cumulative_init()

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.

Parameters
sA pointer to an uninitialized struct representing the sampler
sigmaStandard deviation
nPrecision parameter
two_sidedBoolean defining if we limit only to non-negative integers

◆ cfe_normal_cumulative_free()

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.

Parameters
sA pointer to an instance of the sampler (initialized cfe_normal_cumulative struct)

◆ cfe_normal_cumulative_sample()

void cfe_normal_cumulative_sample ( mpz_t  res,
cfe_normal_cumulative s 
)

Samples discrete cumulative distribution with precomputed values.

Parameters
resThe random number (result value will be stored here)
sA pointer to an instance of the sampler (initialized cfe_normal_cumulative struct)

◆ cfe_normal_cumulative_precompute()

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.

Parameters
sA pointer to an instance of the sampler (initialized cfe_normal_cumulative struct)

◆ cfe_locate_int()

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

Parameters
sampleTarget integer
startStart index
endEnd index
vVector of values
middle_valueTemporary placeholder for value comparison (to avoid unnecessary memory allocations)
Returns
index of target integer

◆ cfe_normal_cumulative_sample_vec()

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.

◆ cfe_normal_cumulative_sample_mat()

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.