GammaLib 2.0.0
|
Random number generator class. More...
#include <GRan.hpp>
Public Member Functions | |
GRan (void) | |
Void constructor. | |
GRan (unsigned long long int seed) | |
Seed constructor. | |
GRan (const GRan &ran) | |
Copy constructor. | |
virtual | ~GRan (void) |
Destructor. | |
GRan & | operator= (const GRan &ran) |
Assignment operator. | |
void | clear (void) |
Clear random number generator. | |
GRan * | clone (void) const |
Clone random number generator. | |
std::string | classname (void) const |
Return class name. | |
void | seed (unsigned long long int seed) |
Set seed of random number generator. | |
unsigned long long int | seed (void) const |
Return seed value. | |
unsigned long int | int32 (void) |
Return 32-bit random unsigned integer. | |
unsigned long long int | int64 (void) |
Return 64-bit random unsigned integer. | |
double | uniform (void) |
Returns random double precision floating value in range 0 to 1. | |
double | normal (void) |
Returns normal deviates. | |
double | exp (const double &lambda) |
Returns exponential deviates. | |
double | poisson (const double &lambda) |
Returns Poisson deviates. | |
double | chisq2 (void) |
Returns Chi2 deviates for 2 degrees of freedom. | |
int | cdf (const std::vector< double > &cdf) |
Random sampling from a cumulative density function. | |
int | cdf (const GVector &cdf) |
Random sampling from a cumulative density function. | |
std::string | print (const GChatter &chatter=NORMAL) const |
Print random number generator information. | |
Public Member Functions inherited from GBase | |
virtual | ~GBase (void) |
Destructor. | |
Protected Member Functions | |
void | init_members (unsigned long long int seed=41L) |
Initialise class members. | |
void | copy_members (const GRan &ran) |
Copy class members. | |
void | free_members (void) |
Delete class members. | |
Protected Attributes | |
unsigned long long int | m_seed |
Random number generator seed. | |
unsigned long long int | m_value1 |
Value 1. | |
unsigned long long int | m_value2 |
Value 2. | |
unsigned long long int | m_value3 |
Value 3. | |
double | m_old_lambda |
Old lambda value. | |
double | m_sqrt_lambda |
sqrt(2*lambda) | |
double | m_log_lambda |
log(lambda) | |
double | m_exp_lambda |
exp(-lambda) | |
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(), and seed().
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 GVector & | cdf | ) |
int GRan::cdf | ( | const std::vector< double > & | cdf | ) |
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 uniform().
Referenced by GCTAPsf2D::mc(), GCTAPsfPerfTable::mc(), GCTAPsfVector::mc(), and GModelSpatialRadialGauss::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 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(), GRan(), 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 uniform().
Referenced by GCTAEdispPerfTable::mc(), GModelSpatialEllipticalGauss::mc(), and GModelSpectralGauss::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 gammalib::gammln(), m_exp_lambda, m_log_lambda, m_old_lambda, m_sqrt_lambda, gammalib::pi, 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(), init_members(), and seed().
|
inline |
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(), cdf(), chisq2(), exp(), GCTABackground2D::mc(), GCTABackground3D::mc(), GCTABackgroundPerfTable::mc(), GCTAEdisp2D::mc(), GCTAEdispRmf::mc(), GCTAModelAeffBackground::mc(), GCTAModelRadialGauss::mc(), GCTAModelRadialPolynom::mc(), GCTAModelRadialProfile::mc(), GCTAModelSpatial::mc(), GCTAPsf2D::mc(), GCTAPsfKing::mc(), GCTAPsfTable::mc(), GCTAResponseIrf::mc(), GModelSpatialComposite::mc(), GModelSpatialDiffuseConst::mc(), GModelSpatialDiffuseCube::mc(), GModelSpatialDiffuseMap::mc(), GModelSpatialEllipticalDisk::mc(), GModelSpatialEllipticalGeneralGauss::mc(), GModelSpatialRadialDisk::mc(), GModelSpatialRadialGauss::mc(), GModelSpatialRadialGeneralGauss::mc(), GModelSpatialRadialProfile::mc(), GModelSpatialRadialRing::mc(), GModelSpatialRadialShell::mc(), GModelSpectralBins::mc(), GModelSpectralBrokenPlaw::mc(), GModelSpectralComposite::mc(), GModelSpectralConst::mc(), GModelSpectralExpInvPlaw::mc(), GModelSpectralExpPlaw::mc(), GModelSpectralFunc::mc(), GModelSpectralLogParabola::mc(), GModelSpectralNodes::mc(), GModelSpectralPlaw::mc(), GModelSpectralPlawEnergyFlux::mc(), GModelSpectralPlawPhotonFlux::mc(), GModelSpectralSmoothBrokenPlaw::mc(), GModelSpectralSuperExpPlaw::mc(), GModelSpectralTable::mc(), GModelTemporalLightCurve::mc(), GModelTemporalPhaseCurve::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().