ExRandom  3.0
exrandom::discrete_normal_distribution Class Reference

Sample exactly from the discrete normal distribution. More...

#include <exrandom/discrete_normal_distribution.hpp>

Classes

struct  param_type
 Parameter type for discrete_normal_distribution. More...
 

Public Types

typedef int result_type
 

Public Member Functions

 discrete_normal_distribution ()
 
 discrete_normal_distribution (const param_type &p)
 
 discrete_normal_distribution (int mu, int sigma)
 
 discrete_normal_distribution (int mu_num, int sigma_num, int den)
 
 discrete_normal_distribution (int mu_num, int mu_den, int sigma_num, int sigma_den)
 
void reset ()
 
result_type mu_num () const
 
result_type mu_den () const
 
result_type sigma_num () const
 
result_type sigma_den () const
 
param_type param () const
 
void param (const param_type &param)
 
result_type min () const
 
result_type max () const
 
template<typename Generator >
result_type operator() (Generator &g)
 
template<typename Generator >
result_type operator() (Generator &g, const param_type &p)
 

Friends

bool operator== (const discrete_normal_distribution &d1, const discrete_normal_distribution &d2)
 
bool operator!= (const discrete_normal_distribution &d1, const discrete_normal_distribution &d2)
 
std::ostream & operator<< (std::ostream &os, const discrete_normal_distribution &x)
 
std::istream & operator>> (std::istream &is, discrete_normal_distribution &x)
 

Detailed Description

Sample exactly from the discrete normal distribution.

This samples from the discrete normal distribution Pi ∝ exp[− ((i − μ)/σ)2/2], where μ and σ > 0 are specified as rational numbers (the ratio of two ints). This implements Algorithm D with improvements due to Du et al. (2020).

This is a wrapper for discrete_normal_dist to turn it into a C++11 style random distribution. The base for discrete_normal_dist is set to 216.

Examples
chisq_test.cpp, compare_times.cpp, exrandom_test.cpp, sample_distributions.cpp, and simple_discrete_normal.cpp.

Definition at line 33 of file discrete_normal_distribution.hpp.

Member Typedef Documentation

◆ result_type

The type of the range of the distribution.

Definition at line 40 of file discrete_normal_distribution.hpp.

Constructor & Destructor Documentation

◆ discrete_normal_distribution() [1/5]

exrandom::discrete_normal_distribution::discrete_normal_distribution ( )
inlineexplicit

The default constructor.

Sets μ = 0 and σ = 1

Definition at line 102 of file discrete_normal_distribution.hpp.

◆ discrete_normal_distribution() [2/5]

exrandom::discrete_normal_distribution::discrete_normal_distribution ( const param_type p)
inlineexplicit

Construct from a param_type.

Parameters
p

Definition at line 109 of file discrete_normal_distribution.hpp.

◆ discrete_normal_distribution() [3/5]

exrandom::discrete_normal_distribution::discrete_normal_distribution ( int  mu,
int  sigma 
)
inlineexplicit

Construct with integer parameters.

Parameters
muthe value of μ.
sigmathe value of σ.

Sets μ = mu and σ = sigma.

Definition at line 120 of file discrete_normal_distribution.hpp.

◆ discrete_normal_distribution() [4/5]

exrandom::discrete_normal_distribution::discrete_normal_distribution ( int  mu_num,
int  sigma_num,
int  den 
)
inlineexplicit

Construct with parameters with a common denominator.

Parameters
mu_numthe numerator of μ.
sigma_numthe numerator of σ.
denthe common denominator.

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

Definition at line 134 of file discrete_normal_distribution.hpp.

◆ discrete_normal_distribution() [5/5]

exrandom::discrete_normal_distribution::discrete_normal_distribution ( int  mu_num,
int  mu_den,
int  sigma_num,
int  sigma_den 
)
inlineexplicit

Construct from the individual parameters.

Parameters
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 149 of file discrete_normal_distribution.hpp.

Member Function Documentation

◆ reset()

void exrandom::discrete_normal_distribution::reset ( )
inline

Resets the distribution state.

Definition at line 157 of file discrete_normal_distribution.hpp.

◆ mu_num()

result_type exrandom::discrete_normal_distribution::mu_num ( ) const
inline
Returns
the numerator of μ.
Examples
simple_discrete_normal.cpp.

Definition at line 162 of file discrete_normal_distribution.hpp.

◆ mu_den()

result_type exrandom::discrete_normal_distribution::mu_den ( ) const
inline
Returns
the denominator of μ.
Examples
simple_discrete_normal.cpp.

Definition at line 166 of file discrete_normal_distribution.hpp.

◆ sigma_num()

result_type exrandom::discrete_normal_distribution::sigma_num ( ) const
inline
Returns
the numerator of σ.
Examples
simple_discrete_normal.cpp.

Definition at line 170 of file discrete_normal_distribution.hpp.

◆ sigma_den()

result_type exrandom::discrete_normal_distribution::sigma_den ( ) const
inline
Returns
the denominator of σ.
Examples
simple_discrete_normal.cpp.

Definition at line 174 of file discrete_normal_distribution.hpp.

◆ param() [1/2]

param_type exrandom::discrete_normal_distribution::param ( ) const
inline
Returns
the parameter set of the distribution.

Definition at line 179 of file discrete_normal_distribution.hpp.

◆ param() [2/2]

void exrandom::discrete_normal_distribution::param ( const param_type param)
inline

Sets the parameter set of the distribution.

Parameters
paramThe new parameter set of the distribution.

Definition at line 185 of file discrete_normal_distribution.hpp.

◆ min()

result_type exrandom::discrete_normal_distribution::min ( ) const
inline
Returns
the greatest lower bound value of the distribution.

Definition at line 191 of file discrete_normal_distribution.hpp.

◆ max()

result_type exrandom::discrete_normal_distribution::max ( ) const
inline
Returns
the least upper bound value of the distribution.

Definition at line 197 of file discrete_normal_distribution.hpp.

◆ operator()() [1/2]

template<typename Generator >
result_type exrandom::discrete_normal_distribution::operator() ( Generator &  g)
inline
Template Parameters
Generatorthe type of g.
Parameters
gthe random generator engine.
Returns
a discrete normal deviate.

Definition at line 206 of file discrete_normal_distribution.hpp.

◆ operator()() [2/2]

template<typename Generator >
result_type exrandom::discrete_normal_distribution::operator() ( Generator &  g,
const param_type p 
)
inline
Template Parameters
Generatorthe type of g.
Parameters
gthe random generator engine.
pa parameter set.
Returns
a discrete normal deviate using the specified parameters.

Definition at line 216 of file discrete_normal_distribution.hpp.

Friends And Related Function Documentation

◆ operator==

bool operator== ( const discrete_normal_distribution d1,
const discrete_normal_distribution d2 
)
friend
Returns
true if two normal distributions have the same parameters.

Definition at line 225 of file discrete_normal_distribution.hpp.

◆ operator!=

bool operator!= ( const discrete_normal_distribution d1,
const discrete_normal_distribution d2 
)
friend
Returns
false if two normal distributions have the same parameters.

Definition at line 233 of file discrete_normal_distribution.hpp.

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const discrete_normal_distribution x 
)
friend

Inserts a discrete_normal_distribution random number distribution x into the output stream os.

Parameters
osan output stream.
xa discrete_normal_distribution random number distribution.
Returns
os.

Definition at line 246 of file discrete_normal_distribution.hpp.

◆ operator>>

std::istream& operator>> ( std::istream &  is,
discrete_normal_distribution x 
)
friend

Extracts a discrete_normal_distribution random number distribution x from the input stream is.

Parameters
isan input stream.
xa discrete_normal_distribution random number generator engine.
Returns
is.

Definition at line 258 of file discrete_normal_distribution.hpp.


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