SG++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sgpp::optimization::RandomNumberGenerator Class Reference

Singleton class for generating pseudo-random numbers (wrapper around std::mt19937 from <random>). More...

#include <RandomNumberGenerator.hpp>

Public Types

typedef std::mt19937::result_type SeedType
 type of the seed More...
 

Public Member Functions

double getGaussianRN (double mean=0.0, double stdDev=1.0)
 Generate a Gaussian pseudo-random number. More...
 
void getGaussianRV (base::DataVector &vector, double mean=0.0, double stdDev=1.0)
 Fills vector with Gaussian pseudo-random numbers. More...
 
SeedType getSeed () const
 
size_t getUniformIndexRN (size_t size)
 Generate a uniform pseudo-random array index. More...
 
double getUniformRN (double a=0.0, double b=1.0)
 Generate a uniform pseudo-random number. More...
 
void getUniformRV (base::DataVector &vector, double a=0.0, double b=1.0)
 Fills vector with uniform pseudo-random numbers. More...
 
void setSeed ()
 Reseeds with time-dependent seed. More...
 
void setSeed (SeedType seed)
 Reseeds. More...
 

Static Public Member Functions

static RandomNumberGeneratorgetInstance ()
 

Protected Attributes

std::mt19937 generator
 random number generator More...
 
SeedType seed
 seed More...
 

Detailed Description

Singleton class for generating pseudo-random numbers (wrapper around std::mt19937 from <random>).

Member Typedef Documentation

typedef std::mt19937::result_type sgpp::optimization::RandomNumberGenerator::SeedType

type of the seed

Member Function Documentation

double sgpp::optimization::RandomNumberGenerator::getGaussianRN ( double  mean = 0.0,
double  stdDev = 1.0 
)

Generate a Gaussian pseudo-random number.

Parameters
meanmean of the Gaussian distribution
stdDevstandard deviation of the Gaussian distribution
Returns
Gaussian pseudo-random number

References generator.

Referenced by sgpp::optimization::test_problems::UnconstrainedTestProblem::generateDisplacement(), sgpp::optimization::test_problems::ConstrainedTestProblem::generateDisplacement(), getGaussianRV(), and sgpp::optimization::optimizer::CMAES::optimize().

void sgpp::optimization::RandomNumberGenerator::getGaussianRV ( base::DataVector vector,
double  mean = 0.0,
double  stdDev = 1.0 
)

Fills vector with Gaussian pseudo-random numbers.

Parameters
[out]vectorvector to be filled, has to have desired size beforehand
meanmean of the Gaussian distribution
stdDevstandard deviation of the Gaussian distribution

References getGaussianRN(), and sgpp::base::DataVector::getSize().

RandomNumberGenerator::SeedType sgpp::optimization::RandomNumberGenerator::getSeed ( ) const
Returns
seed

References seed.

size_t sgpp::optimization::RandomNumberGenerator::getUniformIndexRN ( size_t  size)

Generate a uniform pseudo-random array index.

Parameters
sizesize of the array
Returns
discrete uniform pseudo-random number in \(\{0, \dotsc, \text{\texttt{size}} - 1\}\)

References generator.

Referenced by sgpp::optimization::optimizer::DifferentialEvolution::optimize().

double sgpp::optimization::RandomNumberGenerator::getUniformRN ( double  a = 0.0,
double  b = 1.0 
)

Generate a uniform pseudo-random number.

Parameters
alower bound
bupper bound
Returns
uniform pseudo-random number in \([a, b]\)

References generator.

Referenced by getUniformRV(), sgpp::optimization::optimizer::DifferentialEvolution::optimize(), and sgpp::optimization::optimizer::MultiStart::optimize().

void sgpp::optimization::RandomNumberGenerator::getUniformRV ( base::DataVector vector,
double  a = 0.0,
double  b = 1.0 
)

Fills vector with uniform pseudo-random numbers.

Parameters
[out]vectorvector to be filled, has to have desired size beforehand
alower bound
bupper bound

References sgpp::base::DataVector::getSize(), and getUniformRN().

void sgpp::optimization::RandomNumberGenerator::setSeed ( )

Reseeds with time-dependent seed.

void sgpp::optimization::RandomNumberGenerator::setSeed ( RandomNumberGenerator::SeedType  seed)

Reseeds.

Parameters
seedseed to be used

References generator, and seed.

Member Data Documentation

std::mt19937 sgpp::optimization::RandomNumberGenerator::generator
protected

random number generator

Referenced by getGaussianRN(), getUniformIndexRN(), getUniformRN(), and setSeed().

SeedType sgpp::optimization::RandomNumberGenerator::seed
protected

seed

Referenced by getSeed(), and setSeed().


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