Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Attributes | Friends | List of all members
Menge::Math::NormalFloatGenerator Class Reference

A FloatGenerator which returns a normally distributed value. More...

#include <RandGenerator.h>

Inheritance diagram for Menge::Math::NormalFloatGenerator:
Menge::Math::FloatGenerator

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 FloatGeneratorcopy () 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

Loggeroperator<< (Logger &out, const NormalFloatGenerator &gen)
 Friend function for writing string representation to an output stream. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

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].

Parameters
meanThe mean value of the distribution.
stddevThe standard deviation of the value
minValThe 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.
maxValThe 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.
seedIf the seed is zero, the global seed will be used otherwise the particular seed will be used.

Member Function Documentation

FloatGenerator * Menge::Math::NormalFloatGenerator::copy ( ) const
virtual

Create a copy of itself.

Returns
A pointer to a new generator which is a copy of this one. The caller of this function is responsible for freeing up the memory for the copy.

Implements Menge::Math::FloatGenerator.

float Menge::Math::NormalFloatGenerator::getValue ( ) const
virtual

Return a value based on the float generation rules.

Returns
A clamped, normally-distributed float value.

Implements Menge::Math::FloatGenerator.

float Menge::Math::NormalFloatGenerator::getValueConcurrent ( ) const
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.

Returns
A float value.

Implements Menge::Math::FloatGenerator.

void Menge::Math::NormalFloatGenerator::print ( Logger out) const
virtual

Function for converting the generator to a string on a output stream.

Parameters
outThe 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.

Parameters
meanThe mean value of the distribution.
stddevThe standard deviation of the value
minValThe 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.
maxValThe 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.

Friends And Related Function Documentation

Logger& operator<< ( Logger out,
const NormalFloatGenerator gen 
)
friend

Friend function for writing string representation to an output stream.

Parameters
outThe output stream.
genAn instance of the generator to represent as a string.
Returns
Reference to the input output stream.

The documentation for this class was generated from the following files: