ExRandom  3.0
exrandom::discrete_normal_dist< digit_gen > Class Template Reference

Partially sample exactly from the discrete normal distribution. More...

#include <exrandom/discrete_normal_dist.hpp>

Classes

struct  param_type
 Hold the parameters of discrete_normal_dist. More...
 

Public Member Functions

 discrete_normal_dist (digit_gen &D)
 
 discrete_normal_dist (digit_gen &D, const param_type &p)
 
 discrete_normal_dist (digit_gen &D, int mu, int sigma)
 
 discrete_normal_dist (digit_gen &D, int mu_num, int sigma_num, int den)
 
 discrete_normal_dist (digit_gen &D, int mu_num, int mu_den, int sigma_num, int sigma_den)
 
int mu_num () const
 
int mu_den () const
 
int sigma_num () const
 
int sigma_den () const
 
template<typename Generator >
void generate (Generator &g, i_rand< digit_gen > &j)
 
template<typename Generator >
int operator() (Generator &g)
 
digit_gen & digit_generator () const
 
const param_typeparam () const
 
void init (const param_type &param)
 

Detailed Description

template<typename digit_gen>
class exrandom::discrete_normal_dist< digit_gen >

Partially sample exactly from the discrete normal distribution.

This samples from the discrete normal distribution Pi ∝ exp[− ((i − μ)/σ)2/2]. This implements Algorithm D with improvements due to Du et al. (2020).

Template Parameters
digit_genthe type of digit generator.

This class allows a i_rand to be returned via the discrete_normal_dist::generate member function or an int result via the discrete_normal_dist::operator()() member function.

See discrete_normal_distribution for a simpler interface to sampling discrete normal deviates. (But, you can't obtain an i_rand with this class.)

Examples
discrete_count_bits.cpp, and sample_discrete_normal.cpp.

Definition at line 40 of file discrete_normal_dist.hpp.

Constructor & Destructor Documentation

◆ discrete_normal_dist() [1/5]

template<typename digit_gen>
exrandom::discrete_normal_dist< digit_gen >::discrete_normal_dist ( digit_gen &  D)
inline

The default constructor.

Parameters
Da reference to the digit generator to be used.

Sets μ = 0 and σ = 1.

Definition at line 179 of file discrete_normal_dist.hpp.

◆ discrete_normal_dist() [2/5]

template<typename digit_gen>
exrandom::discrete_normal_dist< digit_gen >::discrete_normal_dist ( digit_gen &  D,
const param_type p 
)
inline

Construct from a param_type.

Parameters
Da reference to the digit generator to be used.
pthe param_type.

Definition at line 189 of file discrete_normal_dist.hpp.

◆ discrete_normal_dist() [3/5]

template<typename digit_gen>
exrandom::discrete_normal_dist< digit_gen >::discrete_normal_dist ( digit_gen &  D,
int  mu,
int  sigma 
)
inline

Construct with integer parameters.

Parameters
Da reference to the digit generator to be used.
muthe value of μ.
sigmathe value of σ.

Sets μ = mu and σ = sigma.

Definition at line 202 of file discrete_normal_dist.hpp.

◆ discrete_normal_dist() [4/5]

template<typename digit_gen>
exrandom::discrete_normal_dist< digit_gen >::discrete_normal_dist ( digit_gen &  D,
int  mu_num,
int  sigma_num,
int  den 
)
inline

Construct with parameters with a common denominator.

Parameters
Da reference to the digit generator to be used.
mu_numthe numerator of μ.
sigma_numthe numerator of σ.
denthe common denominator.

Sets μ = mu_num / den and σ = sigma_num / den.

Definition at line 216 of file discrete_normal_dist.hpp.

◆ discrete_normal_dist() [5/5]

template<typename digit_gen>
exrandom::discrete_normal_dist< digit_gen >::discrete_normal_dist ( digit_gen &  D,
int  mu_num,
int  mu_den,
int  sigma_num,
int  sigma_den 
)
inline

Construct from the individual parameters.

Parameters
Da reference to the digit generator to be used.
mu_numthe numerator of μ.
mu_denthe denominator of μ.
sigma_numthe numerator of σ.
sigma_denthe denominator of σ.

Sets μ = mu_num / mu_den and σ = sigma_num / sigma_den.

Definition at line 232 of file discrete_normal_dist.hpp.

Member Function Documentation

◆ mu_num()

template<typename digit_gen>
int exrandom::discrete_normal_dist< digit_gen >::mu_num ( ) const
inline
Returns
the numerator of μ.

Definition at line 242 of file discrete_normal_dist.hpp.

◆ mu_den()

template<typename digit_gen>
int exrandom::discrete_normal_dist< digit_gen >::mu_den ( ) const
inline
Returns
the denominator of μ.

Definition at line 246 of file discrete_normal_dist.hpp.

◆ sigma_num()

template<typename digit_gen>
int exrandom::discrete_normal_dist< digit_gen >::sigma_num ( ) const
inline
Returns
the numerator of σ.

Definition at line 250 of file discrete_normal_dist.hpp.

◆ sigma_den()

template<typename digit_gen>
int exrandom::discrete_normal_dist< digit_gen >::sigma_den ( ) const
inline
Returns
the denominator of σ.

Definition at line 254 of file discrete_normal_dist.hpp.

◆ generate()

template<typename digit_gen>
template<typename Generator >
void exrandom::discrete_normal_dist< digit_gen >::generate ( Generator &  g,
i_rand< digit_gen > &  j 
)
inline

Return a deviate as a i_rand.

Template Parameters
Generatorthe type of g.
Parameters
gthe random generator engine.
jthe i_rand to set.

Definition at line 264 of file discrete_normal_dist.hpp.

◆ operator()()

template<typename digit_gen>
template<typename Generator >
int exrandom::discrete_normal_dist< digit_gen >::operator() ( Generator &  g)
inline

Return a deviate.

Template Parameters
Generatorthe type of g.
Parameters
gthe random generator engine.
Returns
the random deviate.

Definition at line 317 of file discrete_normal_dist.hpp.

◆ digit_generator()

template<typename digit_gen>
digit_gen& exrandom::discrete_normal_dist< digit_gen >::digit_generator ( ) const
inline
Returns
a reference to the digit generator used in the constructor.

Definition at line 324 of file discrete_normal_dist.hpp.

◆ param()

template<typename digit_gen>
const param_type& exrandom::discrete_normal_dist< digit_gen >::param ( ) const
inline
Returns
the parameters.

Definition at line 328 of file discrete_normal_dist.hpp.

◆ init()

template<typename digit_gen>
void exrandom::discrete_normal_dist< digit_gen >::init ( const param_type param)
inline

Set new parameters.

Parameters
paramthe new parameters.

Definition at line 334 of file discrete_normal_dist.hpp.


The documentation for this class was generated from the following file: