OpenANN  1.1.0
An open source library for artificial neural networks.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
List of all members | Public Member Functions
OpenANN::RandomNumberGenerator Class Reference

A utility class that simplifies the generation of random numbers. More...

#include <Random.h>

Public Member Functions

 RandomNumberGenerator ()
 Initialize the seed. More...
 
void seed (unsigned int seed)
 Set the seed to ensure repeatability. More...
 
int generateInt (int min, int range) const
 Draw an integer from a uniform distribution. More...
 
size_t generateIndex (size_t size) const
 Draw an index from a uniform distribution. More...
 
template<class T >
generate (T min, T range) const
 Draw a number from a uniform distribution. More...
 
template<class T >
sampleNormalDistribution () const
 Draw a sample from a normal distribution with zero mean and variance 1. More...
 
template<class C >
void generateIndices (int n, C &result, bool initialized=false)
 Generate a random sequence of indices. More...
 
template<class M >
void fillNormalDistribution (M &matrix, double stdDev=1.0)
 

Detailed Description

A utility class that simplifies the generation of random numbers.

Constructor & Destructor Documentation

OpenANN::RandomNumberGenerator::RandomNumberGenerator ( )

Initialize the seed.

Member Function Documentation

template<class M >
void OpenANN::RandomNumberGenerator::fillNormalDistribution ( M &  matrix,
double  stdDev = 1.0 
)
inline
template<class T >
T OpenANN::RandomNumberGenerator::generate ( min,
range 
) const
inline

Draw a number from a uniform distribution.

Template Parameters
Tnumber type
Parameters
minminimal value
rangerange of the interval, must be greater than 0
Returns
random number from the interval [min, range)
size_t OpenANN::RandomNumberGenerator::generateIndex ( size_t  size) const

Draw an index from a uniform distribution.

Parameters
sizerange of the index, must be greater than 0
Returns
random number from the interval [0, size)
template<class C >
void OpenANN::RandomNumberGenerator::generateIndices ( int  n,
C &  result,
bool  initialized = false 
)
inline

Generate a random sequence of indices.

Template Parameters
containertype of result (must support push_back())
Parameters
nnumber of indices
resultresult container, must be empty if initialized = false
initializeddoes the container already contain indices?
int OpenANN::RandomNumberGenerator::generateInt ( int  min,
int  range 
) const

Draw an integer from a uniform distribution.

Parameters
minminimal value
rangerange of the interval, must be greater than 0
Returns
random number from the interval [min, range)
template<class T >
T OpenANN::RandomNumberGenerator::sampleNormalDistribution ( ) const
inline

Draw a sample from a normal distribution with zero mean and variance 1.

We use the Box–Muller transform. In order to draw a random number from the distribution $ \mathcal{N}(\mu, \sigma) $, you have to shift and scale the output of this function:

double mu = ...
double sigma = ...
double rn = mu + sigma*rng.sampleNormalDistribution<double>();
Template Parameters
Tnumber type
Returns
standard normal distributed random number
void OpenANN::RandomNumberGenerator::seed ( unsigned int  seed)

Set the seed to ensure repeatability.

Note that the seed is set globally, i.e. it might also be overwritten by another part of you program.

Parameters
seedinitial parameter for random number generator

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