GammaLib
2.1.0.dev
|
Random number generator class. More...
#include <GRan.hpp>
Public Member Functions | |
GRan (void) | |
Void constructor. More... | |
GRan (unsigned long long int seed) | |
Seed constructor. More... | |
GRan (const GRan &ran) | |
Copy constructor. More... | |
virtual | ~GRan (void) |
Destructor. More... | |
GRan & | operator= (const GRan &ran) |
Assignment operator. More... | |
void | clear (void) |
Clear random number generator. More... | |
GRan * | clone (void) const |
Clone random number generator. More... | |
std::string | classname (void) const |
Return class name. More... | |
void | seed (unsigned long long int seed) |
Set seed of random number generator. More... | |
unsigned long long int | seed (void) const |
Return seed value. More... | |
unsigned long int | int32 (void) |
Return 32-bit random unsigned integer. More... | |
unsigned long long int | int64 (void) |
Return 64-bit random unsigned integer. More... | |
double | uniform (void) |
Returns random double precision floating value in range 0 to 1. More... | |
double | normal (void) |
Returns normal deviates. More... | |
double | exp (const double &lambda) |
Returns exponential deviates. More... | |
double | poisson (const double &lambda) |
Returns Poisson deviates. More... | |
double | chisq2 (void) |
Returns Chi2 deviates for 2 degrees of freedom. More... | |
int | cdf (const std::vector< double > &cdf) |
Random sampling from a cumulative density function. More... | |
int | cdf (const GVector &cdf) |
Random sampling from a cumulative density function. More... | |
std::string | print (const GChatter &chatter=NORMAL) const |
Print random number generator information. More... | |
Public Member Functions inherited from GBase | |
virtual | ~GBase (void) |
Destructor. More... | |
Protected Member Functions | |
void | init_members (unsigned long long int seed=41L) |
Initialise class members. More... | |
void | copy_members (const GRan &ran) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
Protected Attributes | |
unsigned long long int | m_seed |
Random number generator seed. More... | |
unsigned long long int | m_value1 |
Value 1. More... | |
unsigned long long int | m_value2 |
Value 2. More... | |
unsigned long long int | m_value3 |
Value 3. More... | |
double | m_old_lambda |
Old lambda value. More... | |
double | m_sqrt_lambda |
sqrt(2*lambda) More... | |
double | m_log_lambda |
log(lambda) More... | |
double | m_exp_lambda |
exp(-lambda) More... | |
Random number generator class.
This class implements a random number generator.
GRan::GRan | ( | void | ) |
Void constructor.
Definition at line 57 of file GRan.cpp.
References init_members().
Referenced by clone().
GRan::GRan | ( | unsigned long long int | seed | ) |
Seed constructor.
[in] | seed | Random number generator seed. |
Definition at line 72 of file GRan.cpp.
References init_members().
GRan::GRan | ( | const GRan & | ran | ) |
Copy constructor.
[in] | ran | Random number generator. |
Definition at line 87 of file GRan.cpp.
References copy_members(), and init_members().
|
virtual |
int GRan::cdf | ( | const std::vector< double > & | cdf | ) |
int GRan::cdf | ( | const GVector & | cdf | ) |
Random sampling from a cumulative density function.
[in] | cdf | Vector containing cumulative density function |
Definition at line 421 of file GRan.cpp.
References GVector::size(), and uniform().
double GRan::chisq2 | ( | void | ) |
Returns Chi2 deviates for 2 degrees of freedom.
Returns exponential deviates from the probability distribution
\[p(x) = \frac{1}{2\pi} x \exp( -\frac{1}{2} x^2 )\]
This method can be used to simulate the random radial offset of a measured source position from the true source position, assuming an azimuthally symmetric 2D Gaussian probability distribution.
Definition at line 370 of file GRan.cpp.
References log(), sqrt(), and uniform().
Referenced by GCTAPsfPerfTable::mc(), GCTAPsfVector::mc(), GModelSpatialRadialGauss::mc(), and GCTAPsf2D::mc().
|
inlinevirtual |
|
virtual |
Clear random number generator.
This method properly resets the object to an initial state using the default seed.
Implements GBase.
Definition at line 158 of file GRan.cpp.
References free_members(), and init_members().
|
virtual |
|
protected |
Copy class members.
[in] | ran | Random number generator. |
Definition at line 513 of file GRan.cpp.
References m_exp_lambda, m_log_lambda, m_old_lambda, m_seed, m_sqrt_lambda, m_value1, m_value2, and m_value3.
Referenced by GRan(), and operator=().
double GRan::exp | ( | const double & | lambda | ) |
Returns exponential deviates.
[in] | lambda | Mean rate. |
Returns exponential deviates from the probability distribution
\[p(x) = \lambda \exp( -\lambda x )\]
where \(\lambda\) is the parameter of the distribution. This method may be used to simulate the occurence time of an event, where \(\lambda\) is the mean event rate. Convsersely, \(1/\lambda\) is the mean waiting time between events.
Definition at line 291 of file GRan.cpp.
References log(), and uniform().
Referenced by GModelTemporalConst::mc(), and GModelTemporalPhaseCurve::mc().
|
protected |
|
protected |
Initialise class members.
Definition at line 484 of file GRan.cpp.
References int64(), m_exp_lambda, m_log_lambda, m_old_lambda, m_seed, m_sqrt_lambda, m_value1, m_value2, m_value3, and seed().
Referenced by clear(), GRan(), operator=(), and seed().
unsigned long int GRan::int32 | ( | void | ) |
unsigned long long int GRan::int64 | ( | void | ) |
double GRan::normal | ( | void | ) |
Returns normal deviates.
Method Used: Box-Muller transform, outlined here: http://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform
Code from: http://www.design.caltech.edu/erik/Misc/Gaussian.html
Definition at line 257 of file GRan.cpp.
References log(), sqrt(), and uniform().
Referenced by GModelSpatialEllipticalGauss::mc(), GModelSpectralGauss::mc(), and GCTAEdispPerfTable::mc().
Assignment operator.
[in] | ran | Random number generator. |
Definition at line 125 of file GRan.cpp.
References copy_members(), free_members(), and init_members().
double GRan::poisson | ( | const double & | lambda | ) |
Returns Poisson deviates.
[in] | lambda | Expectation value. |
Returns Poisson deviates for an expectation value.
This method may be used to simulate the number of events in case that a given mean number of events is expected.
Definition at line 316 of file GRan.cpp.
References exp(), gammalib::gammln(), log(), m_exp_lambda, m_log_lambda, m_old_lambda, m_sqrt_lambda, gammalib::pi, sqrt(), tan(), and uniform().
Referenced by GModelTemporalLightCurve::mc().
Print random number generator information.
[in] | chatter | Chattiness (defaults to NORMAL). |
Implements GBase.
Definition at line 451 of file GRan.cpp.
References m_seed, m_value1, m_value2, m_value3, gammalib::parformat(), SILENT, and gammalib::str().
void GRan::seed | ( | unsigned long long int | seed | ) |
Set seed of random number generator.
[in] | seed | Random number generator seed. |
This method properly resets the object to an initial state using the specified seed.
Definition at line 190 of file GRan.cpp.
References free_members(), and init_members().
|
inline |
Return seed value.
Definition at line 111 of file GRan.hpp.
References m_seed.
Referenced by init_members().
double GRan::uniform | ( | void | ) |
Returns random double precision floating value in range 0 to 1.
Definition at line 242 of file GRan.cpp.
References int64().
Referenced by cdf(), chisq2(), exp(), GModelSpatialComposite::mc(), GModelSpatialDiffuseConst::mc(), GCTABackgroundPerfTable::mc(), GModelSpatialRadialProfile::mc(), GCTAModelAeffBackground::mc(), GModelSpatialDiffuseMap::mc(), GCTABackground3D::mc(), GCTABackground2D::mc(), GModelSpectralComposite::mc(), GModelSpatialRadialGauss::mc(), GModelSpatialRadialDisk::mc(), GModelSpatialRadialGeneralGauss::mc(), GModelSpatialRadialRing::mc(), GCTAModelRadialGauss::mc(), GCTAModelRadialPolynom::mc(), GCTAPsf2D::mc(), GCTAPsfKing::mc(), GCTAPsfTable::mc(), GCTAModelRadialProfile::mc(), GModelSpatialEllipticalDisk::mc(), GModelSpectralBins::mc(), GModelSpatialEllipticalGeneralGauss::mc(), GModelSpatialDiffuseCube::mc(), GModelSpectralTable::mc(), GCTAModelSpatial::mc(), GModelTemporalLightCurve::mc(), GModelSpectralConst::mc(), GCTAEdispRmf::mc(), GModelSpectralFunc::mc(), GModelSpatialRadialShell::mc(), GModelSpectralPlaw::mc(), GModelSpectralExpPlaw::mc(), GModelSpectralLogParabola::mc(), GModelSpectralBrokenPlaw::mc(), GCTAResponseIrf::mc(), GModelSpectralExpInvPlaw::mc(), GModelSpectralSuperExpPlaw::mc(), GModelTemporalPhaseCurve::mc(), GModelSpectralPlawEnergyFlux::mc(), GModelSpectralPlawPhotonFlux::mc(), GModelSpectralNodes::mc(), GModelSpectralSmoothBrokenPlaw::mc(), GCTAEdisp2D::mc(), normal(), and poisson().
|
protected |
exp(-lambda)
Definition at line 89 of file GRan.hpp.
Referenced by copy_members(), init_members(), and poisson().
|
protected |
log(lambda)
Definition at line 88 of file GRan.hpp.
Referenced by copy_members(), init_members(), and poisson().
|
protected |
Old lambda value.
Definition at line 86 of file GRan.hpp.
Referenced by copy_members(), init_members(), and poisson().
|
protected |
Random number generator seed.
Definition at line 80 of file GRan.hpp.
Referenced by copy_members(), init_members(), print(), and seed().
|
protected |
sqrt(2*lambda)
Definition at line 87 of file GRan.hpp.
Referenced by copy_members(), init_members(), and poisson().
|
protected |
Value 1.
Definition at line 81 of file GRan.hpp.
Referenced by copy_members(), init_members(), int64(), and print().
|
protected |
Value 2.
Definition at line 82 of file GRan.hpp.
Referenced by copy_members(), init_members(), int64(), and print().
|
protected |
Value 3.
Definition at line 83 of file GRan.hpp.
Referenced by copy_members(), init_members(), int64(), and print().