Main MRPT website > C++ reference
MRPT logo

mrpt::random::CRandomGenerator Class Reference

A thred-safe pseudo random number generator, based on an internal MT19937 randomness generator. More...

#include <mrpt/random/RandomGenerators.h>

Collaboration diagram for mrpt::random::CRandomGenerator:
Collaboration graph
[legend]

List of all members.

Classes

struct  TMT19937_data
 Data used internally by the MT19937 PRNG algorithm. More...

Public Member Functions

Initialization



 CRandomGenerator ()
 Default constructor: initialize random seed based on current time.
 CRandomGenerator (const uint32_t seed)
 Constructor for providing a custom random seed to initialize the PRNG.
void randomize (const uint32_t seed)
 Initialize the PRNG from the given random seed.
void randomize ()
 Randomize the generators, based on current time.
Uniform pdf



uint32_t drawUniform32bit ()
 Generate a uniformly distributed pseudo-random number using the MT19937 algorithm, in the whole range of 32-bit integers.
double drawUniform (const double Min, const double Max)
 Generate a uniformly distributed pseudo-random number using the MT19937 algorithm, scaled to the selected range.
template<class MAT >
void drawUniformMatrix (MAT &matrix, const double unif_min=0, const double unif_max=1)
 Fills the given matrix with independent, uniformly distributed samples.
template<class T >
void drawUniformVector (std::vector< T > &v, const double unif_min=0, const double unif_max=1)
 Fills the given vector with independent, uniformly distributed samples.
Normal/Gaussian pdf



double drawGaussian1D_normalized (double *likelihood=NULL)
 Generate a normalized (mean=0, std=1) normally distributed sample.
double drawGaussian1D (const double mean, const double std)
 Generate a normally distributed pseudo-random number.
template<class MAT >
void drawGaussian1DMatrix (MAT &matrix, const double mean=0, const double std=1)
 Fills the given matrix with independent, 1D-normally distributed samples.
template<class T >
void drawGaussian1DVector (std::vector< T > &v, const double mean=0, const double std=1)
 Fills the given vector with independent, 1D-normally distributed samples.
template<typename T >
void drawGaussianMultivariate (std::vector< T > &out_result, const CMatrixTemplateNumeric< T > &cov, const std::vector< T > *mean=NULL)
 Generate multidimensional random samples according to a given covariance matrix.
template<typename VECTORLIKE , typename MATRIXLIKE >
void drawGaussianMultivariateMany (std::vector< VECTORLIKE > &ret, size_t desiredSamples, const MATRIXLIKE &cov, const VECTORLIKE *mean=NULL, VECTORLIKE *samplesLikelihoods=NULL)
 Generate a given number of multidimensional random samples according to a given covariance matrix.
template<class VECTORLIKE , typename T , size_t N>
void drawGaussianMultivariate (VECTORLIKE &out_result, const CMatrixFixedNumeric< T, N, N > &cov, const VECTORLIKE *mean=NULL)
 Generate multidimensional random samples according to a given covariance matrix.
template<typename T , size_t N>
void drawGaussianMultivariateMany (std::vector< std::vector< T > > &ret, size_t desiredSamples, const CMatrixFixedNumeric< T, N, N > &cov, const std::vector< T > *mean=NULL)
 Generate a given number of multidimensional random samples according to a given covariance matrix.
Miscellaneous



template<class T >
void permuteVector (const std::vector< T > &in_vector, std::vector< T > &out_result)
 Returns a random permutation of a vector: all the elements of the input vector are in the output but at random positions.

Protected Member Functions

void MT19937_generateNumbers ()
void MT19937_initializeGenerator (const uint32_t &seed)

Protected Attributes

struct
mrpt::random::CRandomGenerator::TMT19937_data 
m_MT19937_data
 Data used internally by the MT19937 PRNG algorithm.

Detailed Description

A thred-safe pseudo random number generator, based on an internal MT19937 randomness generator.

The base algorithm for randomness is platform-independent. See http://en.wikipedia.org/wiki/Mersenne_twister

For real thread-safety, each thread must create and use its own instance of this class.

Single-thread programs can use the static object mrpt::random::randomGenerator

Definition at line 51 of file RandomGenerators.h.


Constructor & Destructor Documentation

mrpt::random::CRandomGenerator::CRandomGenerator (  )  [inline]

Default constructor: initialize random seed based on current time.

Definition at line 73 of file RandomGenerators.h.

mrpt::random::CRandomGenerator::CRandomGenerator ( const uint32_t  seed  )  [inline]

Constructor for providing a custom random seed to initialize the PRNG.

Definition at line 76 of file RandomGenerators.h.


Member Function Documentation

double mrpt::random::CRandomGenerator::drawGaussian1D ( const double  mean,
const double  std 
) [inline]

Generate a normally distributed pseudo-random number.

Parameters:
mean The mean value of desired normal distribution
std The standard deviation value of desired normal distribution

Definition at line 138 of file RandomGenerators.h.

double mrpt::random::CRandomGenerator::drawGaussian1D_normalized ( double *  likelihood = NULL  ) 

Generate a normalized (mean=0, std=1) normally distributed sample.

Parameters:
likelihood If desired, pass a pointer to a double which will receive the likelihood of the given sample to have been obtained, that is, the value of the normal pdf at the sample value.

Referenced by mrpt::random::matrixRandomNormal(), and mrpt::random::vectorRandomNormal().

template<class MAT >
void mrpt::random::CRandomGenerator::drawGaussian1DMatrix ( MAT &  matrix,
const double  mean = 0,
const double  std = 1 
) [inline]

Fills the given matrix with independent, 1D-normally distributed samples.

Matrix classes can be CMatrixTemplateNumeric or CMatrixFixedNumeric

See also:
drawGaussian1D

Definition at line 147 of file RandomGenerators.h.

References mrpt::math::mean().

template<class T >
void mrpt::random::CRandomGenerator::drawGaussian1DVector ( std::vector< T > &  v,
const double  mean = 0,
const double  std = 1 
) [inline]

Fills the given vector with independent, 1D-normally distributed samples.

See also:
drawGaussian1D

Definition at line 161 of file RandomGenerators.h.

References mrpt::math::mean().

template<class VECTORLIKE , typename T , size_t N>
void mrpt::random::CRandomGenerator::drawGaussianMultivariate ( VECTORLIKE &  out_result,
const CMatrixFixedNumeric< T, N, N > &  cov,
const VECTORLIKE *  mean = NULL 
) [inline]

Generate multidimensional random samples according to a given covariance matrix.

Mean is assumed to be zero if mean==NULL.

Exceptions:
std::exception On invalid covariance matrix
See also:
drawGaussianMultivariateMany

Computes the eigenvalues/eigenvector decomposition of this matrix, so that: M = Z · D · ZT, where columns in Z are the eigenvectors and the diagonal matrix D contains the eigenvalues as diagonal elements, sorted in ascending order.

Definition at line 296 of file RandomGenerators.h.

References ASSERT_, and mrpt::math::mean().

template<typename T >
void mrpt::random::CRandomGenerator::drawGaussianMultivariate ( std::vector< T > &  out_result,
const CMatrixTemplateNumeric< T > &  cov,
const std::vector< T > *  mean = NULL 
) [inline]

Generate multidimensional random samples according to a given covariance matrix.

Mean is assumed to be zero if mean==NULL.

Exceptions:
std::exception On invalid covariance matrix
See also:
drawGaussianMultivariateMany

Referenced by mrpt::random::randomNormalMultiDimensional().

template<typename T , size_t N>
void mrpt::random::CRandomGenerator::drawGaussianMultivariateMany ( std::vector< std::vector< T > > &  ret,
size_t  desiredSamples,
const CMatrixFixedNumeric< T, N, N > &  cov,
const std::vector< T > *  mean = NULL 
) [inline]

Generate a given number of multidimensional random samples according to a given covariance matrix.

Parameters:
cov The covariance matrix where to draw the samples from.
desiredSamples The number of samples to generate.
ret The output list of samples
mean The mean, or zeros if mean==NULL.

Computes the eigenvalues/eigenvector decomposition of this matrix, so that: M = Z · D · ZT, where columns in Z are the eigenvectors and the diagonal matrix D contains the eigenvalues as diagonal elements, sorted in ascending order.

Definition at line 344 of file RandomGenerators.h.

References ASSERT_, and mrpt::math::mean().

template<typename VECTORLIKE , typename MATRIXLIKE >
void mrpt::random::CRandomGenerator::drawGaussianMultivariateMany ( std::vector< VECTORLIKE > &  ret,
size_t  desiredSamples,
const MATRIXLIKE &  cov,
const VECTORLIKE *  mean = NULL,
VECTORLIKE *  samplesLikelihoods = NULL 
) [inline]

Generate a given number of multidimensional random samples according to a given covariance matrix.

Parameters:
cov The covariance matrix where to draw the samples from.
desiredSamples The number of samples to generate.
samplesLikelihoods If desired, set to a valid pointer to a vector, where it will be stored the likelihoods of having obtained each sample: the product of the gaussian-pdf for each independent variable.
ret The output list of samples
mean The mean, or zeros if mean==NULL.
Exceptions:
std::exception On invalid covariance matrix
See also:
drawGaussianMultivariate

Computes the eigenvalues/eigenvector decomposition of this matrix, so that: M = Z · D · ZT, where columns in Z are the eigenvectors and the diagonal matrix D contains the eigenvalues as diagonal elements, sorted in ascending order.

Definition at line 195 of file RandomGenerators.h.

References ASSERT_, mrpt::math::mean(), MRPT_END_WITH_CLEAN_UP, and MRPT_START.

Referenced by mrpt::random::randomNormalMultiDimensionalMany(), and mrpt::math::transform_gaussian_montecarlo().

double mrpt::random::CRandomGenerator::drawUniform ( const double  Min,
const double  Max 
) [inline]

Generate a uniformly distributed pseudo-random number using the MT19937 algorithm, scaled to the selected range.

Definition at line 91 of file RandomGenerators.h.

Referenced by mrpt::random::matrixRandomUni(), mrpt::slam::PF_implementation< PARTICLE_TYPE >::PF_SLAM_aux_perform_one_rejection_sampling_step(), and mrpt::random::vectorRandomUni().

uint32_t mrpt::random::CRandomGenerator::drawUniform32bit (  ) 
template<class MAT >
void mrpt::random::CRandomGenerator::drawUniformMatrix ( MAT &  matrix,
const double  unif_min = 0,
const double  unif_max = 1 
) [inline]

Fills the given matrix with independent, uniformly distributed samples.

Matrix classes can be CMatrixTemplateNumeric or CMatrixFixedNumeric

See also:
drawUniform

Definition at line 100 of file RandomGenerators.h.

template<class T >
void mrpt::random::CRandomGenerator::drawUniformVector ( std::vector< T > &  v,
const double  unif_min = 0,
const double  unif_max = 1 
) [inline]

Fills the given vector with independent, uniformly distributed samples.

See also:
drawUniform

Definition at line 114 of file RandomGenerators.h.

void mrpt::random::CRandomGenerator::MT19937_generateNumbers (  )  [protected]
void mrpt::random::CRandomGenerator::MT19937_initializeGenerator ( const uint32_t &  seed  )  [protected]
template<class T >
void mrpt::random::CRandomGenerator::permuteVector ( const std::vector< T > &  in_vector,
std::vector< T > &  out_result 
) [inline]

Returns a random permutation of a vector: all the elements of the input vector are in the output but at random positions.

Definition at line 398 of file RandomGenerators.h.

Referenced by mrpt::random::randomPermutation().

void mrpt::random::CRandomGenerator::randomize (  ) 

Randomize the generators, based on current time.

void mrpt::random::CRandomGenerator::randomize ( const uint32_t  seed  ) 

Initialize the PRNG from the given random seed.

Referenced by mrpt::random::Randomize().


Member Data Documentation

Data used internally by the MT19937 PRNG algorithm.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines



Page generated by Doxygen 1.6.1 for MRPT 0.9.0 SVN: at Mon Jun 7 06:47:58 UTC 2010