glotzmath::RandomNumberGenerator Class Reference

Defines an interface for Random Number Generators (RNGs) used in Glotzilla. More...

#include <RandomNumberGenerator.h>

Inheritance diagram for glotzmath::RandomNumberGenerator:

glotzmath::StdLibErand48

List of all members.

Public Types

enum  { STDLIBERAND48, NUMBER_OF_CALLS }

Public Member Functions

 RandomNumberGenerator ()
 Default constructor.
virtual ~RandomNumberGenerator ()
 Default destructor.
virtual
RandomNumberGenerator
Clone ()=0
 Intelligent clone.
virtual void PrintSeed (std::ostream &)=0
 Prints the seed to a stream.
virtual glotz_flt GetUniformFloat ()=0
 Generates floats from a uniform distribution (0, 1).
int GetUniformInt (int, int)
 Generates integers from a bounded uniform distribution.
glotz_flt GetUniformFloat (glotz_flt, glotz_flt)
 Generates floats from uniform distribution between two bounds.
glotz_flt GetGaussianFloat ()
 Generates floats from a standard Gaussian distribution.
glotz_flt GetGaussianFloat (glotz_flt, glotz_flt)
 Generates floats from a modified Gaussian distribution.
glotz_flt GetExponentialFloat (glotz_flt)
 Generates floats from an exponential distribution.
glotz_flt GetCauchyFloat ()
 Generates floats from a Cauchy distribution.
glotz_vec GetUniformVector ()
 Generates a float vector uniformly distributed between (0, 1).
glotz_vec GetUniformVector (glotz_flt, glotz_flt)
 Generates a float vector from a bounded uniform distribution.
glotz_vec GetGaussianVector ()
 Generates a float vector from a standard Gaussian distribution.
glotz_vec GetGaussianVector (glotz_flt, glotz_flt)
 Generates a float vector from a modified Gaussian distribution.
glotz_vec GetExponentialVector (glotz_flt)
 Generates a float vector from a exponential distribution.
glotz_vec GetCauchyVector ()
 Generates a float vector from a Cauchy distribution.
glotz_quat GetUniformQuaternion ()
 Generates a float quaternion from a uniform distribution.
glotz_quat GetUniformQuaternion (glotz_flt, glotz_flt)
 Generates a float quaternion from bounded unifrom distribution.
virtual void PrintRestartData (std::ostream &)
 Prints restart data.
virtual void ScanRestartData (std::istream &)
 Scans restart data.

Static Public Member Functions

static
RandomNumberGenerator
ParseRestartData (std::istream &)
 Allocates a RNG object from restart data.
static void InitializeRestartMap ()
 Forms the restart map.

Static Public Attributes

static std::map
< std::string, int > 
sRestartMap
 Map of key restart data variable identifiers.

Protected Member Functions

void Marsaglia (glotz_flt &, glotz_flt &)
 Implementation of the Marsaglia algorithm.

Private Attributes

bool mMarsagliaPairIsCurrent
 True is we have an extra Marsaglia random number.
glotz_flt mMarsagliaFloatA
 First Marsaglia random number.
glotz_flt mMarsagliaFloatB
 Second Marsaglia random number.


Detailed Description

Defines an interface for Random Number Generators (RNGs) used in Glotzilla.

Note:
Replaces previous definition of RandomNumberGenerator
Author:
Tony Sheh
Sampling floating point numbers (floats) from many distribution is an important part of Monte Carlo and Molecular Dynamics codes. Given an RNG that gives back floats from a uniform distribution in (0.0, 1.0), it is possible to generate all other distributions

Member Enumeration Documentation

anonymous enum

Enumerator:
STDLIBERAND48 
NUMBER_OF_CALLS 


Constructor & Destructor Documentation

glotzmath::RandomNumberGenerator::RandomNumberGenerator (  ) 

Default constructor.

glotzmath::RandomNumberGenerator::~RandomNumberGenerator (  )  [virtual]

Default destructor.


Member Function Documentation

virtual RandomNumberGenerator* glotzmath::RandomNumberGenerator::Clone (  )  [pure virtual]

Intelligent clone.

Implemented in glotzmath::StdLibErand48.

virtual void glotzmath::RandomNumberGenerator::PrintSeed ( std::ostream &   )  [pure virtual]

Prints the seed to a stream.

Implemented in glotzmath::StdLibErand48.

virtual glotz_flt glotzmath::RandomNumberGenerator::GetUniformFloat (  )  [pure virtual]

Generates floats from a uniform distribution (0, 1).

Implemented in glotzmath::StdLibErand48.

int glotzmath::RandomNumberGenerator::GetUniformInt ( int  min,
int  max 
) [inline]

Generates integers from a bounded uniform distribution.

Parameters:
min is the lower bound of the uniform distribution
max is the upper bound of the uniform distribution
Returns:
an integer sampled from a bounded uniform distribution

glotz_flt glotzmath::RandomNumberGenerator::GetUniformFloat ( glotz_flt  min,
glotz_flt  max 
) [inline]

Generates floats from uniform distribution between two bounds.

Parameters:
min is the lower bound of the uniform distribution
max is the upper bound of the uniform distribution
Returns:
a float sampled from a bounded uniform distribution (min, max)

glotz_flt glotzmath::RandomNumberGenerator::GetGaussianFloat (  )  [inline]

Generates floats from a standard Gaussian distribution.

Returns:
a floating point number randomly sampled from a Gaussian distribution with mean 0, std. dev of 1.
This algorithm calls Marsaglia() to generate a pair of Marsaglia random variables, mMarsagliaFloatA and mMarsagliaFloatB. The switch, mMarsagliaPairIsCurrent switches so that on alternating calls, the function will either 1) generate the Marsaglia pair and return mMarsagliaFloatA or 2) return mMarsagliaFloatB.

glotz_flt glotzmath::RandomNumberGenerator::GetGaussianFloat ( glotz_flt  mean,
glotz_flt  sqrtVariance 
) [inline]

Generates floats from a modified Gaussian distribution.

Parameters:
mean is the mean of the desired Gaussian distribution to sample from
sqrtVariance is the square root of the variance of the desired Gaussian distribution
Returns:
a floating point random variable sampled from a modified Gaussian distribution
A Gaussian of arbitrary mean and variance can be computed by scaling (multiplying) by the sqrt(variance) and shifting (adding) the new mean.

glotz_flt glotzmath::RandomNumberGenerator::GetExponentialFloat ( glotz_flt  lambda  )  [inline]

Generates floats from an exponential distribution.

Parameters:
lambda is the power of the exponential
Returns:
a floating point number sampled from an exponential distribution

glotz_flt glotzmath::RandomNumberGenerator::GetCauchyFloat (  )  [inline]

Generates floats from a Cauchy distribution.

Returns:
a floating point number sampled from a Cauchy distribution

glotz_vec glotzmath::RandomNumberGenerator::GetUniformVector (  )  [inline]

Generates a float vector uniformly distributed between (0, 1).

Returns:
a vector of floats sampled from a uniform distribution (0, 1)

glotz_vec glotzmath::RandomNumberGenerator::GetUniformVector ( glotz_flt  min,
glotz_flt  max 
) [inline]

Generates a float vector from a bounded uniform distribution.

Parameters:
min is the lower bound of the uniform distribution
max is the upper bound of the uniform distribution
Returns:
a vector of floats smapled from a bounded uniform distribution (min, max)

glotz_vec glotzmath::RandomNumberGenerator::GetGaussianVector (  )  [inline]

Generates a float vector from a standard Gaussian distribution.

Calls RandomNumberGenerator::GetGaussianFloat().

Returns:
a vector of floats sampled from a standard Gaussian distribution

glotz_vec glotzmath::RandomNumberGenerator::GetGaussianVector ( glotz_flt  mean,
glotz_flt  sqrtVar 
) [inline]

Generates a float vector from a modified Gaussian distribution.

glotz_vec glotzmath::RandomNumberGenerator::GetExponentialVector ( glotz_flt  lambda  )  [inline]

Generates a float vector from a exponential distribution.

Parameters:
lambda is the power of the exponential
Returns:
a floating point number sampled from an exponential distribution

glotz_vec glotzmath::RandomNumberGenerator::GetCauchyVector (  )  [inline]

Generates a float vector from a Cauchy distribution.

Returns:
a vector of flaots sampled from a Cauchy distribution

glotz_quat glotzmath::RandomNumberGenerator::GetUniformQuaternion (  )  [inline]

Generates a float quaternion from a uniform distribution.

Returns:
a quaternion with components chosen from a uniform distribution [0, 1)

glotz_quat glotzmath::RandomNumberGenerator::GetUniformQuaternion ( glotz_flt  min,
glotz_flt  max 
) [inline]

Generates a float quaternion from bounded unifrom distribution.

Returns:
a quaternion with components chosen from a uniform distribution [min, max)

RandomNumberGenerator * glotzmath::RandomNumberGenerator::ParseRestartData ( std::istream &  is  )  [static]

Allocates a RNG object from restart data.

void glotzmath::RandomNumberGenerator::PrintRestartData ( std::ostream &  os  )  [virtual]

Prints restart data.

Reimplemented in glotzmath::StdLibErand48.

void glotzmath::RandomNumberGenerator::ScanRestartData ( std::istream &  is  )  [virtual]

Scans restart data.

Reimplemented in glotzmath::StdLibErand48.

void glotzmath::RandomNumberGenerator::InitializeRestartMap (  )  [static]

Forms the restart map.

void glotzmath::RandomNumberGenerator::Marsaglia ( glotz_flt x1,
glotz_flt x2 
) [inline, protected]

Implementation of the Marsaglia algorithm.

Generates two Gaussian random variables using the Marsaglia algorithm.

Parameters:
x1 is a reference to a floating point number
x2 is a reference to a (different) floating point number


Member Data Documentation

std::map< std::string, int > glotzmath::RandomNumberGenerator::sRestartMap [static]

Map of key restart data variable identifiers.

bool glotzmath::RandomNumberGenerator::mMarsagliaPairIsCurrent [private]

True is we have an extra Marsaglia random number.

glotz_flt glotzmath::RandomNumberGenerator::mMarsagliaFloatA [private]

First Marsaglia random number.

glotz_flt glotzmath::RandomNumberGenerator::mMarsagliaFloatB [private]

Second Marsaglia random number.


The documentation for this class was generated from the following files:
Generated on Tue Feb 24 20:53:40 2009 by  doxygen 1.5.3