ExRandom  3.0
exrandom::unit_normal_distribution< RealType > Class Template Reference

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

#include <exrandom/unit_normal_distribution.hpp>

Classes

struct  param_type
 Parameter type for unit_normal_distribution. More...
 

Public Types

typedef RealType result_type
 

Public Member Functions

 unit_normal_distribution ()
 
 unit_normal_distribution (const param_type &)
 
void reset ()
 
param_type param () const
 
void param (const param_type &)
 
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 &)
 

Friends

bool operator== (const unit_normal_distribution< RealType > &, const unit_normal_distribution< RealType > &)
 
bool operator!= (const unit_normal_distribution< RealType > &, const unit_normal_distribution< RealType > &)
 
std::ostream & operator<< (std::ostream &os, const unit_normal_distribution< RealType > &)
 
std::istream & operator>> (std::istream &is, unit_normal_distribution &)
 

Related Functions

(Note that these are not member functions.)

#define EXRANDOM_USE_KAHN
 

Detailed Description

template<typename RealType = double>
class exrandom::unit_normal_distribution< RealType >

Sample exactly from the unit normal distribution.

This samples from the unit normal distribution P(x) = exp(− x2/2) / √(2π). This is a replacement for std::normal_distribution (with no parameters). It is equivalent to sampling a real number exactly from the distribution and rounding it to a floating point number. This implements Algorithm N with improvements due to Du et al. (2020).

Template Parameters
RealTypethe floating point type of the resulting deviates. This can include various multi-precision floating point types; see u_rand::value of details.

This is a wrapper for unit_normal_dist to turn it into a C++11 style random distribution. If the radix of RealType is 2 (the usual case), then the base for unit_normal_dist is set to 232; otherwise (e.g., RealType is a decimal system), the base is set to the radix.

If the macro EXRANDOM_USE_KAHN is set to 1, then unit_normal_kahn is used instead (with the base set to the radix for RealType). Because this introduces a slight bias, this is not recommended.

Template Parameters
RealTypethe floating point type of the resulting deviates.
Examples
chisq_test.cpp, compare_times.cpp, exrandom_test.cpp, mpfr_times.cpp, multiprec_test.cpp, sample_distributions.cpp, and simple_normal.cpp.

Definition at line 61 of file unit_normal_distribution.hpp.

Member Typedef Documentation

◆ result_type

template<typename RealType = double>
typedef RealType exrandom::unit_normal_distribution< RealType >::result_type

The type of the range of the distribution.

Definition at line 66 of file unit_normal_distribution.hpp.

Constructor & Destructor Documentation

◆ unit_normal_distribution() [1/2]

template<typename RealType = double>
exrandom::unit_normal_distribution< RealType >::unit_normal_distribution ( )
inlineexplicit

Constructs a normal distribution.

Definition at line 82 of file unit_normal_distribution.hpp.

◆ unit_normal_distribution() [2/2]

template<typename RealType = double>
exrandom::unit_normal_distribution< RealType >::unit_normal_distribution ( const param_type )
inlineexplicit

Constructs a normal distribution with a parameter.

The parameter is ignored because it has no state.

Definition at line 90 of file unit_normal_distribution.hpp.

Member Function Documentation

◆ reset()

template<typename RealType = double>
void exrandom::unit_normal_distribution< RealType >::reset ( )
inline

Resets the distribution state.

Definition at line 96 of file unit_normal_distribution.hpp.

◆ param() [1/2]

template<typename RealType = double>
param_type exrandom::unit_normal_distribution< RealType >::param ( ) const
inline
Returns
the parameter set of the distribution.

Definition at line 101 of file unit_normal_distribution.hpp.

◆ param() [2/2]

template<typename RealType = double>
void exrandom::unit_normal_distribution< RealType >::param ( const param_type )
inline

Sets the parameter set of the distribution.

The function does not because a param_type has no state.

Definition at line 108 of file unit_normal_distribution.hpp.

◆ min()

template<typename RealType = double>
result_type exrandom::unit_normal_distribution< RealType >::min ( ) const
inline
Returns
the greatest lower bound value of the distribution.

Definition at line 113 of file unit_normal_distribution.hpp.

◆ max()

template<typename RealType = double>
result_type exrandom::unit_normal_distribution< RealType >::max ( ) const
inline
Returns
the least upper bound value of the distribution.

Definition at line 119 of file unit_normal_distribution.hpp.

◆ operator()() [1/2]

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

Definition at line 127 of file unit_normal_distribution.hpp.

◆ operator()() [2/2]

template<typename RealType = double>
template<typename Generator >
result_type exrandom::unit_normal_distribution< RealType >::operator() ( Generator &  g,
const param_type  
)
inline
Template Parameters
Generatorthe type of g.
Parameters
gthe random generator engine.
Returns
a normal deviate.

Definition at line 136 of file unit_normal_distribution.hpp.

Friends And Related Function Documentation

◆ operator==

template<typename RealType = double>
bool operator== ( const unit_normal_distribution< RealType > &  ,
const unit_normal_distribution< RealType > &   
)
friend

Compare two unit_normal_distributions.

Returns
true.

Definition at line 144 of file unit_normal_distribution.hpp.

◆ operator!=

template<typename RealType = double>
bool operator!= ( const unit_normal_distribution< RealType > &  ,
const unit_normal_distribution< RealType > &   
)
friend

Contrast two unit_normal_distributions.

Returns
false.

Definition at line 153 of file unit_normal_distribution.hpp.

◆ operator<<

template<typename RealType = double>
std::ostream& operator<< ( std::ostream &  os,
const unit_normal_distribution< RealType > &   
)
friend

Inserts a unit_normal_distribution random number distribution into the output stream os.

Parameters
osan output stream.
Returns
os.

This function does nothing because this distribution has no state.

Definition at line 167 of file unit_normal_distribution.hpp.

◆ operator>>

template<typename RealType = double>
std::istream& operator>> ( std::istream &  is,
unit_normal_distribution< RealType > &   
)
friend

Extracts a unit_normal_distribution random number distribution from the input stream is.

Parameters
isan input stream.
Returns
is.

This function does nothing because this distribution has no state.

Definition at line 180 of file unit_normal_distribution.hpp.

◆ EXRANDOM_USE_KAHN

template<typename RealType = double>
#define EXRANDOM_USE_KAHN
related

Should exrandom::unit_normal_distribution use exrandom::unit_normal_kahn instead of exrandom::unit_normal_dist as the underlying distribution. Because the output of exrandom::unit_normal_kahn is slightly biased, EXRANDOM_USE_KAHN should be set to 0.

Definition at line 21 of file unit_normal_distribution.hpp.


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