#include <mrpt/random/RandomGenerators.h>
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 T > | |
void | drawGaussianMultivariateMany (std::vector< std::vector< T > > &ret, size_t desiredSamples, const CMatrixTemplateNumeric< T > &cov, const std::vector< T > *mean=NULL, std::vector< T > *samplesLikelihoods=NULL) |
Generate a given number of multidimensional random samples according to a given covariance matrix. | |
template<typename T , size_t N> | |
void | drawGaussianMultivariate (std::vector< T > &out_result, const CMatrixFixedNumeric< T, N, N > &cov, const std::vector< T > *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. |
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 50 of file RandomGenerators.h.
mrpt::random::CRandomGenerator::CRandomGenerator | ( | ) | [inline] |
Default constructor: initialize random seed based on current time.
Definition at line 72 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 75 of file RandomGenerators.h.
double mrpt::random::CRandomGenerator::drawGaussian1D | ( | const double | mean, | |
const double | std | |||
) | [inline] |
Generate a normally distributed pseudo-random number.
mean | The mean value of desired normal distribution | |
std | The standard deviation value of desired normal distribution |
Definition at line 137 of file RandomGenerators.h.
double mrpt::random::CRandomGenerator::drawGaussian1D_normalized | ( | double * | likelihood = NULL |
) |
Generate a normalized (mean=0, std=1) normally distributed sample.
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().
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
Definition at line 146 of file RandomGenerators.h.
References mrpt::math::mean().
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.
Definition at line 160 of file RandomGenerators.h.
References mrpt::math::mean().
void mrpt::random::CRandomGenerator::drawGaussianMultivariate | ( | std::vector< T > & | out_result, | |
const CMatrixFixedNumeric< T, N, N > & | 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.
std::exception | On invalid covariance matrix |
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 208 of file RandomGenerators.h.
References ASSERT_, mrpt::math::CMatrixFixedNumeric< T, NROWS, NCOLS >::eigenVectors(), mrpt::math::CMatrixFixedNumeric< T, NROWS, NCOLS >::get_unsafe(), and mrpt::math::mean().
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.
std::exception | On invalid covariance matrix |
Referenced by mrpt::random::randomNormalMultiDimensional().
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.
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 257 of file RandomGenerators.h.
References ASSERT_, mrpt::math::CMatrixFixedNumeric< T, NROWS, NCOLS >::eigenVectors(), mrpt::math::CMatrixFixedNumeric< T, NROWS, NCOLS >::get_unsafe(), and mrpt::math::mean().
void mrpt::random::CRandomGenerator::drawGaussianMultivariateMany | ( | std::vector< std::vector< T > > & | ret, | |
size_t | desiredSamples, | |||
const CMatrixTemplateNumeric< T > & | cov, | |||
const std::vector< T > * | mean = NULL , |
|||
std::vector< T > * | samplesLikelihoods = NULL | |||
) | [inline] |
Generate a given number of multidimensional random samples according to a given covariance matrix.
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. |
std::exception | On invalid covariance matrix |
Referenced by mrpt::random::randomNormalMultiDimensionalMany().
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 90 of file RandomGenerators.h.
Referenced by mrpt::random::matrixRandomUni(), and mrpt::random::vectorRandomUni().
uint32_t mrpt::random::CRandomGenerator::drawUniform32bit | ( | ) |
Generate a uniformly distributed pseudo-random number using the MT19937 algorithm, in the whole range of 32-bit integers.
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
Definition at line 99 of file RandomGenerators.h.
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.
Definition at line 113 of file RandomGenerators.h.
void mrpt::random::CRandomGenerator::MT19937_generateNumbers | ( | ) | [protected] |
void mrpt::random::CRandomGenerator::MT19937_initializeGenerator | ( | const uint32_t & | seed | ) | [protected] |
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 311 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 | ) |
struct mrpt::random::CRandomGenerator::TMT19937_data mrpt::random::CRandomGenerator::m_MT19937_data [protected] |
Data used internally by the MT19937 PRNG algorithm.
Page generated by Doxygen 1.5.9 for MRPT 0.7.1 SVN: at Mon Aug 17 22:21:34 EDT 2009 |