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

Normal double sampler. More...

Go to the source code of this file.

Data Structures

struct  cfe_normal_double
 

Typedefs

typedef struct cfe_normal_double cfe_normal_double
 

Functions

cfe_error cfe_normal_double_init (cfe_normal_double *s, mpf_t sigma, size_t n, mpf_t first_sigma)
 
void cfe_normal_double_free (cfe_normal_double *s)
 
void cfe_normal_double_sample (mpz_t res, cfe_normal_double *s)
 
void cfe_normal_double_sample_vec (cfe_vec *res, cfe_normal_double *s)
 
void cfe_normal_double_sample_mat (cfe_mat *res, cfe_normal_double *s)
 

Detailed Description

Normal double sampler.

Typedef Documentation

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

Function Documentation

◆ 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
sA pointer to an uninitialized struct representing the sampler
sigmaStandard deviation
nPrecision parameter
first_sigmaStandard deviation for the cumulative sampler
Returns

◆ cfe_normal_double_free()

void cfe_normal_double_free ( cfe_normal_double *  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_double struct)

◆ cfe_normal_double_sample()

void cfe_normal_double_sample ( mpz_t  res,
cfe_normal_double *  s 
)

Samples according to discrete Gauss distribution using normal_double and second sampling.

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

◆ cfe_normal_double_sample_vec()

void cfe_normal_double_sample_vec ( cfe_vec *  res,
cfe_normal_double *  s 
)

Sets the elements of the vector to random numbers with the normal_double sampler.

◆ cfe_normal_double_sample_mat()

void cfe_normal_double_sample_mat ( cfe_mat *  res,
cfe_normal_double *  s 
)

Sets the elements of a matrix to random numbers with the normal_double sampler.