Main MRPT website > C++ reference
MRPT logo
Classes | Protected Member Functions | Protected Attributes

mrpt::random::CRandomGenerator Class Reference


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.

#include <mrpt/random/RandomGenerators.h>

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 VEC >
void drawUniformVector (VEC &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.
CMatrixDouble drawDefinitePositiveMatrix (const size_t dim, const double std_scale=1.0, const double diagonal_epsilon=1e-8)
 Generates a random definite-positive matrix of the given size, using the formula C = v*v^t + epsilon*I, with "v" being a vector of gaussian random samples.
template<class VEC >
void drawGaussian1DVector (VEC &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<class VECTORLIKE , class COVMATRIX >
void drawGaussianMultivariate (VECTORLIKE &out_result, const COVMATRIX &cov, const VECTORLIKE *mean=NULL)
 Generate multidimensional random samples according to a given covariance matrix.
template<typename VECTOR_OF_VECTORS , typename COVMATRIX >
void drawGaussianMultivariateMany (VECTOR_OF_VECTORS &ret, size_t desiredSamples, const COVMATRIX &cov, const typename VECTOR_OF_VECTORS::value_type *mean=NULL)
 Generate a given number of multidimensional random samples according to a given covariance matrix.
Miscellaneous

template<class VEC >
void permuteVector (const VEC &in_vector, VEC &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.

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

CMatrixDouble mrpt::random::CRandomGenerator::drawDefinitePositiveMatrix ( const size_t  dim,
const double  std_scale = 1.0,
const double  diagonal_epsilon = 1e-8 
)

Generates a random definite-positive matrix of the given size, using the formula C = v*v^t + epsilon*I, with "v" being a vector of gaussian random samples.

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 mean().

template<class VEC >
void mrpt::random::CRandomGenerator::drawGaussian1DVector ( VEC &  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 165 of file RandomGenerators.h.

References mean().

template<class VECTORLIKE , class COVMATRIX >
void mrpt::random::CRandomGenerator::drawGaussianMultivariate ( VECTORLIKE &  out_result,
const COVMATRIX &  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

Definition at line 194 of file RandomGenerators.h.

References ASSERT_, ASSERT_EQUAL_, Eigen::SelfAdjointEigenSolver< _MatrixType >::eigenvalues(), Eigen::SelfAdjointEigenSolver< _MatrixType >::eigenvectors(), and mean().

template<typename T >
void mrpt::random::CRandomGenerator::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.

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 VECTOR_OF_VECTORS , typename COVMATRIX >
void mrpt::random::CRandomGenerator::drawGaussianMultivariateMany ( VECTOR_OF_VECTORS &  ret,
size_t  desiredSamples,
const COVMATRIX &  cov,
const typename VECTOR_OF_VECTORS::value_type 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.

Definition at line 237 of file RandomGenerators.h.

References ASSERT_EQUAL_, CwiseUnaryOp< UnaryOp, XprType >::cols(), Eigen::SelfAdjointEigenSolver< _MatrixType >::eigenvalues(), Eigen::SelfAdjointEigenSolver< _MatrixType >::eigenvectors(), and mean().

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, MYSELF >::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 VEC >
void mrpt::random::CRandomGenerator::drawUniformVector ( VEC &  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 VEC >
void mrpt::random::CRandomGenerator::permuteVector ( const VEC &  in_vector,
VEC &  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 286 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.




Page generated by Doxygen 1.7.1 for MRPT 0.9.4 SVN: at Mon Jan 10 23:33:19 UTC 2011