Mantid
|
This implements the the Mersenne Twister 19937 pseudo-random number generator algorithm as a specialzation of the PseudoRandomNumberGenerator interface. More...
#include <MersenneTwister.h>
Public Member Functions | |
double | max () const override |
Return the maximum value of the range. More... | |
MersenneTwister () | |
Construct the generator using time stamp for the initial seed. More... | |
MersenneTwister (const double start, const double end) | |
Construct the generator with an initial range and default seed. More... | |
MersenneTwister (const MersenneTwister &)=delete | |
MersenneTwister (const size_t seedValue) | |
Construct the generator with an initial seed. More... | |
MersenneTwister (const size_t seedValue, const double start, const double end) | |
Construct the generator with an initial seed and range. More... | |
double | min () const override |
Return the minimum value of the range. More... | |
int | nextInt (int start, int end) override |
Return the next integer in the sequence within the given range. More... | |
double | nextValue () override |
Generate the next random number in the sequence within the given range default range. More... | |
double | nextValue (double start, double end) override |
Generate the next random number in the sequence within the given range. More... | |
MersenneTwister & | operator= (const MersenneTwister &)=delete |
void | restart () override |
Resets the generator. More... | |
void | restore () override |
Restores the generator to the last saved point, or the beginning if nothing has been saved. More... | |
void | save () override |
Saves the current state of the generator. More... | |
void | setRange (const double start, const double end) override |
Sets the range of the subsequent calls to next. More... | |
void | setSeed (const size_t seedValue) override |
Set the random number seed. More... | |
Public Member Functions inherited from Mantid::Kernel::PseudoRandomNumberGenerator | |
void | generateNextPoint () override |
Generates the next point. More... | |
virtual double | max () const =0 |
Return the maximum value of the range. More... | |
virtual double | min () const =0 |
Return the minimum value of the range. More... | |
virtual int | nextInt (int start, int end)=0 |
Return the next integer in the sequence. More... | |
virtual double | nextValue ()=0 |
Return the next double in the sequence. More... | |
virtual double | nextValue (double start, double end)=0 |
Return the next double in the sequence overriding the default range. More... | |
double | operator() () |
Return next random value. More... | |
PseudoRandomNumberGenerator & | operator= (const PseudoRandomNumberGenerator &)=delete |
Disable assignment operator. More... | |
PseudoRandomNumberGenerator () | |
Default constructor setting the dimension to 1. More... | |
PseudoRandomNumberGenerator (const PseudoRandomNumberGenerator &)=delete | |
Disable copy operator. More... | |
virtual void | setRange (const double start, const double end)=0 |
Sets the range of the subsequent calls to nextValue;. More... | |
virtual void | setSeed (const size_t seedValue)=0 |
Set the random number seed. More... | |
Public Member Functions inherited from Mantid::Kernel::NDRandomNumberGenerator | |
NDRandomNumberGenerator ()=delete | |
Disable default constructor. More... | |
NDRandomNumberGenerator (const NDRandomNumberGenerator &)=delete | |
Disable copy operator. More... | |
NDRandomNumberGenerator (const unsigned int ndims) | |
Constructor. More... | |
const std::vector< double > & | nextPoint () |
Generate the next set of values that form a point in ND space. More... | |
unsigned int | numberOfDimensions () const |
Returns the number of dimensions the point will be generated in, i.e. More... | |
NDRandomNumberGenerator & | operator= (const NDRandomNumberGenerator &)=delete |
Disable assignment operator. More... | |
virtual void | restart ()=0 |
Restarts the generator from the beginning of the sequence. More... | |
virtual void | restore ()=0 |
Restores the generator to the last saved point, or the beginning if nothing has been saved. More... | |
virtual void | save ()=0 |
Saves the current state of the generator. More... | |
virtual | ~NDRandomNumberGenerator ()=default |
Virtual destructor to ensure that all inheriting classes have one. More... | |
Private Attributes | |
double | m_end |
Maximum in range. More... | |
std::mt19937 | m_engine |
The engine. More... | |
std::unique_ptr< std::mt19937 > | m_savedEngine |
A generator that will take the value when save is requested. More... | |
std::mt19937::result_type | m_seed |
The current seed. More... | |
double | m_start |
Minimum in range. More... | |
std::uniform_real_distribution< double > | uniformRealDistribution |
Uniform Real distribution. More... | |
Additional Inherited Members | |
Public Types inherited from Mantid::Kernel::PseudoRandomNumberGenerator | |
using | result_type = double |
Result (output) value type. More... | |
Protected Member Functions inherited from Mantid::Kernel::NDRandomNumberGenerator | |
void | cacheGeneratedValue (const size_t index, const double value) |
Cache a value for a given dimension index, i.e. 0->ND-1. More... | |
void | cacheNextPoint (const std::vector< double > &nextPoint) |
Cache the while point in one go. More... | |
virtual void | generateNextPoint ()=0 |
Generate the next point. Override this in you concrete implementation. More... | |
std::vector< double > & | getNextPointCache () |
Some generators need direct access to the cache. More... | |
This implements the the Mersenne Twister 19937 pseudo-random number generator algorithm as a specialzation of the PseudoRandomNumberGenerator interface.
Definition at line 24 of file MersenneTwister.h.
Mantid::Kernel::MersenneTwister::MersenneTwister | ( | ) |
Construct the generator using time stamp for the initial seed.
Construct the generator time stamp for the initial seed.
The range is set to [0.0, 1.0]
Definition at line 32 of file MersenneTwister.cpp.
Mantid::Kernel::MersenneTwister::MersenneTwister | ( | const double | start, |
const double | end | ||
) |
Construct the generator with an initial range and default seed.
Constructor taking a range.
start | :: The minimum value a generated number should take |
end | :: The maximum value a generated number should take |
Definition at line 39 of file MersenneTwister.cpp.
|
explicit |
Construct the generator with an initial seed.
Constructor taking a seed value.
It can be reseeded using setSeed.
Sets the range to [0.0,1.0]
seedValue | :: The initial seed |
Definition at line 26 of file MersenneTwister.cpp.
Mantid::Kernel::MersenneTwister::MersenneTwister | ( | const size_t | seedValue, |
const double | start, | ||
const double | end | ||
) |
Construct the generator with an initial seed and range.
Constructor taking a seed value and a range.
seedValue | :: The initial seed |
start | :: The minimum value a generated number should take |
end | :: The maximum value a generated number should take |
Definition at line 48 of file MersenneTwister.cpp.
References setSeed().
|
delete |
|
inlineoverridevirtual |
Return the maximum value of the range.
Implements Mantid::Kernel::PseudoRandomNumberGenerator.
Definition at line 63 of file MersenneTwister.h.
|
inlineoverridevirtual |
Return the minimum value of the range.
Implements Mantid::Kernel::PseudoRandomNumberGenerator.
Definition at line 61 of file MersenneTwister.h.
|
overridevirtual |
Return the next integer in the sequence within the given range.
Returns the next integer in the pseudo-random sequence generated by the Mersenne Twister 19937 algorithm.
start | Start of the requested range |
end | End of the requested range |
Implements Mantid::Kernel::PseudoRandomNumberGenerator.
Definition at line 81 of file MersenneTwister.cpp.
References m_engine.
|
inlineoverridevirtual |
Generate the next random number in the sequence within the given range default range.
Implements Mantid::Kernel::PseudoRandomNumberGenerator.
Definition at line 46 of file MersenneTwister.h.
Referenced by WorkspaceCreationHelper::addNoise(), WorkspaceCreationHelper::create1DWorkspaceRand(), WorkspaceCreationHelper::createRandomEventWorkspace(), and Mantid::Kernel::Matrix< T >::setRandom().
|
inlineoverridevirtual |
Generate the next random number in the sequence within the given range.
Implements Mantid::Kernel::PseudoRandomNumberGenerator.
Definition at line 48 of file MersenneTwister.h.
|
delete |
|
overridevirtual |
Resets the generator.
Resets the generator using the value given at the last call to setSeed.
Implements Mantid::Kernel::NDRandomNumberGenerator.
Definition at line 88 of file MersenneTwister.cpp.
References m_seed, and setSeed().
Referenced by restore().
|
overridevirtual |
Restores the generator to the last saved point, or the beginning if nothing has been saved.
Implements Mantid::Kernel::NDRandomNumberGenerator.
Definition at line 95 of file MersenneTwister.cpp.
References m_engine, m_savedEngine, and restart().
|
overridevirtual |
Saves the current state of the generator.
Implements Mantid::Kernel::NDRandomNumberGenerator.
Definition at line 91 of file MersenneTwister.cpp.
References m_engine, and m_savedEngine.
|
overridevirtual |
Sets the range of the subsequent calls to next.
Sets the range of the subsequent calls to nextValue()
start | :: The lowest value a call to nextValue() will produce |
end | :: The largest value a call to nextValue() will produce |
Implements Mantid::Kernel::PseudoRandomNumberGenerator.
Definition at line 68 of file MersenneTwister.cpp.
References m_end, m_start, and uniformRealDistribution.
|
overridevirtual |
Set the random number seed.
(Re-)seed the generator.
This resets the current saved state
seedValue | :: A seed for the generator |
Implements Mantid::Kernel::PseudoRandomNumberGenerator.
Definition at line 57 of file MersenneTwister.cpp.
References m_engine, m_savedEngine, and m_seed.
Referenced by MersenneTwister(), and restart().
|
private |
|
private |
|
private |
A generator that will take the value when save is requested.
Pointer so that it is only instantiated when required
Definition at line 78 of file MersenneTwister.h.
|
private |
The current seed.
Definition at line 75 of file MersenneTwister.h.
|
private |
|
private |
Uniform Real distribution.
Definition at line 69 of file MersenneTwister.h.
Referenced by setRange().