Chaste Release::3.1
|
#include <RandomNumberGenerator.hpp>
Public Member Functions | |
double | StandardNormalRandomDeviate () |
double | NormalRandomDeviate (double mean, double sd) |
double | ranf () |
unsigned | randMod (unsigned base) |
template<class T > | |
void | Shuffle (std::vector< boost::shared_ptr< T > > &rValues) |
void | Shuffle (unsigned num, std::vector< unsigned > &rValues) |
void | Reseed (int seed) |
Static Public Member Functions | |
static RandomNumberGenerator * | Instance () |
static void | Destroy () |
Protected Member Functions | |
RandomNumberGenerator () | |
Private Member Functions | |
template<class Archive > | |
void | save (Archive &archive, const unsigned int version) const |
template<class Archive > | |
void | load (Archive &archive, const unsigned int version) |
Private Attributes | |
int | mSeed |
long unsigned | mTimesCalled |
double | mWorkingMem1 |
double | mWorkingMem2 |
double | mWorkingMemW |
double | mRandNum2 |
bool | mUseLastNum |
Static Private Attributes | |
static RandomNumberGenerator * | mpInstance = NULL |
Friends | |
class | boost::serialization::access |
A special singleton class allowing one to generate different types of random number in a globally consistent way.
Definition at line 49 of file RandomNumberGenerator.hpp.
RandomNumberGenerator::RandomNumberGenerator | ( | ) | [protected] |
Protected constructor. Use Instance() to access the random number generator.
Definition at line 47 of file RandomNumberGenerator.cpp.
References mpInstance, and mSeed.
Referenced by Instance().
void RandomNumberGenerator::Destroy | ( | ) | [static] |
Destroy the current instance of the random number generator. The next call to Instance will create a new instance and re-seed. This method *must* be called before program exit, to avoid a memory leak.
Definition at line 69 of file RandomNumberGenerator.cpp.
References mpInstance.
Referenced by AbstractCellBasedTestSuite::tearDown().
RandomNumberGenerator * RandomNumberGenerator::Instance | ( | ) | [static] |
Return a pointer to the random number generator object. The object is created the first time this method is called.
Definition at line 60 of file RandomNumberGenerator.cpp.
References mpInstance, and RandomNumberGenerator().
Referenced by AbstractCellBasedSimulation< ELEMENT_DIM, SPACE_DIM >::AbstractCellBasedSimulation(), MultipleCaBasedCellPopulation< DIM >::AddCell(), DiffusionForce< DIM >::AddForceContribution(), CryptSimulation2d::CalculateCellDivisionVector(), CryptSimulation1d::CalculateCellDivisionVector(), OffLatticeSimulation< ELEMENT_DIM, SPACE_DIM >::CalculateCellDivisionVector(), RandomCellKiller< DIM >::CheckAndLabelSingleCellForApoptosis(), CryptCellsGenerator< CELL_CYCLE_MODEL >::Generate(), CellsGenerator< CELL_CYCLE_MODEL, DIM >::GenerateBasicRandom(), StochasticWntCellCycleModel::GenerateStochasticG2Duration(), StochasticOxygenBasedCellCycleModel::GenerateStochasticG2Duration(), HoneycombMeshGenerator::GetCircularMesh(), CryptStatistics::GetCryptSection(), CryptProjectionStatistics::GetCryptSection(), VertexMesh< ELEMENT_DIM, SPACE_DIM >::GetShortAxisOfElement(), CryptSimulationBoundaryCondition< DIM >::ImposeBoundaryCondition(), DistributedTetrahedralMesh< ELEMENT_DIM, SPACE_DIM >::ParMetisLibraryNodeAndElementPartitioning(), TetrahedralMesh< ELEMENT_DIM, SPACE_DIM >::PermuteNodes(), StochasticWntCellCycleModel::serialize(), SimpleWntCellCycleModel::serialize(), AbstractCellBasedSimulation< DIM >::serialize(), RandomCellKiller< DIM >::serialize(), StochasticOxygenBasedCellCycleModel::serialize(), StochasticDurationGenerationBasedCellCycleModel::serialize(), StochasticDurationCellCycleModel::serialize(), SimpleWntCellCycleModel::SetG1Duration(), StochasticDurationGenerationBasedCellCycleModel::SetG1Duration(), StochasticDurationCellCycleModel::SetG1Duration(), AbstractCellBasedTestSuite::setUp(), Shuffle(), PottsBasedCellPopulation< DIM >::UpdateCellLocations(), MultipleCaBasedCellPopulation< DIM >::UpdateCellLocations(), SimpleOxygenBasedCellCycleModel::UpdateHypoxicDuration(), and MultipleCaBasedCellPopulation< DIM >::WriteVtkResultsToFile().
void RandomNumberGenerator::load | ( | Archive & | archive, |
const unsigned int | version | ||
) | [inline, private] |
Load the RandomNumberGenerator and its member variables.
archive | the archive |
version | the current version of this class |
Reimplemented from SerializableSingleton< RandomNumberGenerator >.
Definition at line 106 of file RandomNumberGenerator.hpp.
References mRandNum2, mSeed, mTimesCalled, and mUseLastNum.
Generate a random number from a normal distribution with given mean and standard deviation.
mean | the mean of the normal distribution from which the random number is drawn |
sd | the standard deviation of the normal distribution from which the random number is drawn |
Definition at line 90 of file RandomNumberGenerator.cpp.
References StandardNormalRandomDeviate().
Referenced by StochasticWntCellCycleModel::GenerateStochasticG2Duration(), StochasticOxygenBasedCellCycleModel::GenerateStochasticG2Duration(), and SimpleWntCellCycleModel::SetG1Duration().
Generate a random number modulo base (i.e. an integer within the range 0,..,base-1),
base | the order of the field of positive integers from which the random number is drawn |
Definition at line 78 of file RandomNumberGenerator.cpp.
References mTimesCalled.
Referenced by MultipleCaBasedCellPopulation< DIM >::AddCell(), Shuffle(), and PottsBasedCellPopulation< DIM >::UpdateCellLocations().
double RandomNumberGenerator::ranf | ( | ) |
Generate a uniform random number in (0,1).
Definition at line 84 of file RandomNumberGenerator.cpp.
References mTimesCalled.
Referenced by CryptSimulation2d::CalculateCellDivisionVector(), CryptSimulation1d::CalculateCellDivisionVector(), OffLatticeSimulation< ELEMENT_DIM, SPACE_DIM >::CalculateCellDivisionVector(), RandomCellKiller< DIM >::CheckAndLabelSingleCellForApoptosis(), CryptCellsGenerator< CELL_CYCLE_MODEL >::Generate(), CellsGenerator< CELL_CYCLE_MODEL, DIM >::GenerateBasicRandom(), HoneycombMeshGenerator::GetCircularMesh(), CryptStatistics::GetCryptSection(), CryptProjectionStatistics::GetCryptSection(), VertexMesh< ELEMENT_DIM, SPACE_DIM >::GetShortAxisOfElement(), CryptSimulationBoundaryCondition< DIM >::ImposeBoundaryCondition(), StochasticDurationGenerationBasedCellCycleModel::SetG1Duration(), StochasticDurationCellCycleModel::SetG1Duration(), StandardNormalRandomDeviate(), PottsBasedCellPopulation< DIM >::UpdateCellLocations(), MultipleCaBasedCellPopulation< DIM >::UpdateCellLocations(), SimpleOxygenBasedCellCycleModel::UpdateHypoxicDuration(), and MultipleCaBasedCellPopulation< DIM >::WriteVtkResultsToFile().
void RandomNumberGenerator::Reseed | ( | int | seed | ) |
Reseed the random number generator.
seed | the new seed |
Definition at line 95 of file RandomNumberGenerator.cpp.
References mSeed, and mTimesCalled.
Referenced by DistributedTetrahedralMesh< ELEMENT_DIM, SPACE_DIM >::ParMetisLibraryNodeAndElementPartitioning(), and AbstractCellBasedTestSuite::setUp().
void RandomNumberGenerator::save | ( | Archive & | archive, |
const unsigned int | version | ||
) | const [inline, private] |
Save the RandomNumberGenerator and its member variables.
archive | the archive |
version | the current version of this class |
Reimplemented from SerializableSingleton< RandomNumberGenerator >.
Definition at line 88 of file RandomNumberGenerator.hpp.
References mRandNum2, mSeed, mTimesCalled, and mUseLastNum.
void RandomNumberGenerator::Shuffle | ( | std::vector< boost::shared_ptr< T > > & | rValues | ) | [inline] |
Produce a permutation of the integers and non-empty std::vector, using the Knuth-algorithm (also called the Fisher-Yates algorithm), a linear time unbiased method. The values are shuffled in place.
rValues | the intial values and the output permutation of shuffled values. Must be non-empty |
Definition at line 180 of file RandomNumberGenerator.hpp.
References Instance(), and randMod().
Referenced by DistributedTetrahedralMesh< ELEMENT_DIM, SPACE_DIM >::ParMetisLibraryNodeAndElementPartitioning(), TetrahedralMesh< ELEMENT_DIM, SPACE_DIM >::PermuteNodes(), and PottsBasedCellPopulation< DIM >::UpdateCellLocations().
Produce a permutation of the integers 0,1,..,num-1, using the Knuth-algorithm (also called the Fisher-Yates algorithm), a linear time unbiased method. The shuffled values are returned in rValues, which doesn't need to be correctly-sized when passed in.
num | the number of integers to shuffle |
rValues | the output permutation of shuffled values (any initial values ignored) |
Definition at line 102 of file RandomNumberGenerator.cpp.
References Instance(), and randMod().
double RandomNumberGenerator::StandardNormalRandomDeviate | ( | ) |
Uses a ranf() call and an approximation to the inverse PDF of the normal distribution to generate an accurate estimate of a normally distributed random number. Adapted from the algorithm outlined at http://home.online.no/~pjacklam/notes/invnorm/#Pseudo_code_for_rational_approximation
This little method implements the Box-Mueller/Marsaglia polar method for getting normally distributed variables from uniform ones.
G.E.P. Box and Mervin E. Muller, A Note on the Generation of Random Normal Deviates, The Annals of Mathematical Statistics (1958), Vol. 29, No. 2 pp. 610–611
doi:10.1214/aoms/1177706645
as given on http://en.wikipedia.org/wiki/Marsaglia_polar_method on 29/11/10
Definition at line 120 of file RandomNumberGenerator.cpp.
References mRandNum2, mUseLastNum, mWorkingMem1, mWorkingMem2, mWorkingMemW, and ranf().
Referenced by DiffusionForce< DIM >::AddForceContribution(), and NormalRandomDeviate().
RandomNumberGenerator * RandomNumberGenerator::mpInstance = NULL [static, private] |
Pointer to the single instance.
Definition at line 60 of file RandomNumberGenerator.hpp.
Referenced by Destroy(), Instance(), and RandomNumberGenerator().
double RandomNumberGenerator::mRandNum2 [private] |
Stored normal random number (we generate two at once).
Definition at line 72 of file RandomNumberGenerator.hpp.
Referenced by load(), save(), and StandardNormalRandomDeviate().
int RandomNumberGenerator::mSeed [private] |
The random number generator seed.
Definition at line 54 of file RandomNumberGenerator.hpp.
Referenced by load(), RandomNumberGenerator(), Reseed(), and save().
long unsigned RandomNumberGenerator::mTimesCalled [private] |
bool RandomNumberGenerator::mUseLastNum [private] |
Whether to use the stored random number next.
Definition at line 75 of file RandomNumberGenerator.hpp.
Referenced by load(), save(), and StandardNormalRandomDeviate().
double RandomNumberGenerator::mWorkingMem1 [private] |
Working memory for the normal random number calculations.
Definition at line 63 of file RandomNumberGenerator.hpp.
Referenced by StandardNormalRandomDeviate().
double RandomNumberGenerator::mWorkingMem2 [private] |
Working memory for the normal random number calculations.
Definition at line 66 of file RandomNumberGenerator.hpp.
Referenced by StandardNormalRandomDeviate().
double RandomNumberGenerator::mWorkingMemW [private] |
Working memory for the normal random number calculations.
Definition at line 69 of file RandomNumberGenerator.hpp.
Referenced by StandardNormalRandomDeviate().