Menge
Modular Pedestrian Simulation Framework for Research and Development
|
A FloatGenerator which returns a normally distributed value. More...
#include <RandGenerator.h>
Public Member Functions | |
NormalFloatGenerator (float mean, float stddev, float minVal, float maxVal, int seed=0) | |
Constructor. More... | |
void | set (float mean, float stddev, float minVal, float maxVal) |
Sets the distribution parameters. More... | |
virtual float | getValue () const |
Return a value based on the float generation rules. More... | |
virtual float | getValueConcurrent () const |
Return a value based on the float generation rules - performed in a thread-safe manner. More... | |
virtual void | print (Logger &out) const |
Function for converting the generator to a string on a output stream. More... | |
virtual FloatGenerator * | copy () const |
Create a copy of itself. More... | |
Public Member Functions inherited from Menge::Math::FloatGenerator | |
FloatGenerator () | |
Constructor. | |
virtual | ~FloatGenerator () |
Virtual destructor. | |
Protected Attributes | |
float | _mean |
The mean value of the distribution. | |
float | _std |
The standard deviation of the value. | |
float | _min |
The lower clamped value, such that all values returned will be greater than or equal to minVal. For largely "pure" normal distribution, minVal <= mean - 3 * stddev. | |
float | _max |
The upper clamped value, such that all values returned will be less than or equal to maxVal. For largely "pure" normal distribution, maxVal >= mean + 3 * stddev. | |
float | _second |
The second random number generated (see Math::r4_normalR). | |
unsigned int | _calls |
The number of calls to the generator. Every second call requires a new call to the random number generator. | |
int | _seed |
A seed for the random number generator. | |
SimpleLock | _lock |
The lock for guaranteeing threadsafe random number generation. | |
Friends | |
Logger & | operator<< (Logger &out, const NormalFloatGenerator &gen) |
Friend function for writing string representation to an output stream. More... | |
A FloatGenerator which returns a normally distributed value.
Furthermore, the normally distributed value is clamped to a range [min, max] that prevents the otherwise theoretically possible (though highly improbable) values that can lie outside of practical ranges.
The min and max values should span a range which includes the interval: [ mean - 3 * std. dev., mean + 3 * std. dev.] Clamping the range smaller will lead to abnormal accretions of samples at the clamping boundaries. By having the range span at least six standard deviations, centered at the mean, most of the normal distribution will be unaffected by clamping.
Menge::Math::NormalFloatGenerator::NormalFloatGenerator | ( | float | mean, |
float | stddev, | ||
float | minVal, | ||
float | maxVal, | ||
int | seed = 0 |
||
) |
Constructor.
The value is normally distributed around mean, with a standard deviation of stddev but clamped to lie within the range [minVal, maxVal].
mean | The mean value of the distribution. |
stddev | The standard deviation of the value |
minVal | The lower clamped value, such that all values returned will be greater than or equal to minVal. For largely "pure" normal distribution, minVal <= mean - 3 * stddev. |
maxVal | The upper clamped value, such that all values returned will be less than or equal to maxVal. For largely "pure" normal distribution, maxVal >= mean + 3 * stddev. |
seed | If the seed is zero, the global seed will be used otherwise the particular seed will be used. |
|
virtual |
Create a copy of itself.
Implements Menge::Math::FloatGenerator.
|
virtual |
Return a value based on the float generation rules.
Implements Menge::Math::FloatGenerator.
|
virtual |
Return a value based on the float generation rules - performed in a thread-safe manner.
This is the basic functionality that must be overwridden by derived classes.
Implements Menge::Math::FloatGenerator.
|
virtual |
Function for converting the generator to a string on a output stream.
out | The output stream to write the string representation to. |
Implements Menge::Math::FloatGenerator.
void Menge::Math::NormalFloatGenerator::set | ( | float | mean, |
float | stddev, | ||
float | minVal, | ||
float | maxVal | ||
) |
Sets the distribution parameters.
mean | The mean value of the distribution. |
stddev | The standard deviation of the value |
minVal | The lower clamped value, such that all values returned will be greater than or equal to minVal. For largely "pure" normal distribution, minVal <= mean - 3 * stddev. |
maxVal | The upper clamped value, such that all values returned will be less than or equal to maxVal. For largely "pure" normal distribution, maxVal >= mean + 3 * stddev. |
|
friend |
Friend function for writing string representation to an output stream.
out | The output stream. |
gen | An instance of the generator to represent as a string. |