namespace mrpt::random
Overview
A namespace of pseudo-random numbers generators of different distributions.
The central class in this namespace is mrpt::random::CRandomGenerator
namespace random { // classes class CRandomGenerator; class Generator_MT19937; // global functions template <class URBG> uint64_t portable_uniform_distribution(URBG&& g, uint64_t min, uint64_t max); template <class RandomIt, class URBG> void shuffle( RandomIt first, RandomIt last, URBG&& g ); template <class RandomIt> void shuffle(RandomIt first, RandomIt last); template <class RandomIt, class URBG> void partial_shuffle( RandomIt first, RandomIt last, URBG&& g, size_t N ); CRandomGenerator& getRandomGenerator(); ptrdiff_t random_generator_for_STL(ptrdiff_t i); template <class MAT> void matrixRandomUni( MAT& matrix, const double unif_min = 0, const double unif_max = 1 ); template <class T> void vectorRandomUni( std::vector<T>& v_out, const T& unif_min = 0, const T& unif_max = 1 ); template <class MAT> void matrixRandomNormal( MAT& matrix, const double mean = 0, const double std = 1 ); template <class T> void vectorRandomNormal( std::vector<T>& v_out, const T& mean = 0, const T& std = 1 ); void Randomize(const uint32_t seed); void Randomize(); template <class T> void randomPermutation( const std::vector<T>& in_vector, std::vector<T>& out_result ); template <typename T, typename MATRIX> void randomNormalMultiDimensionalMany( const MATRIX& cov, size_t desiredSamples, std::vector<std::vector<T>>& ret, std::vector<T>* samplesLikelihoods = nullptr ); template <typename T, typename MATRIXLIKE> void randomNormalMultiDimensionalMany( const MATRIXLIKE& cov, size_t desiredSamples, std::vector<std::vector<T>>& ret ); template <typename T, typename MATRIX> void randomNormalMultiDimensional( const MATRIX& cov, std::vector<T>& out_result ); } // namespace random
Global Functions
CRandomGenerator& getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
ptrdiff_t random_generator_for_STL(ptrdiff_t i)
A random number generator for usage in STL algorithms expecting a function like this (eg, random_shuffle):
template <class MAT> void matrixRandomUni( MAT& matrix, const double unif_min = 0, const double unif_max = 1 )
Fills the given matrix with independent, uniformly distributed samples.
Matrix classes can be mrpt::math::CMatrixDynamic or mrpt::math::CMatrixFixed
See also:
template <class T> void vectorRandomUni( std::vector<T>& v_out, const T& unif_min = 0, const T& unif_max = 1 )
Fills the given matrix with independent, uniformly distributed samples.
See also:
template <class MAT> void matrixRandomNormal( MAT& matrix, const double mean = 0, const double std = 1 )
Fills the given matrix with independent, normally distributed samples.
Matrix classes can be mrpt::math::CMatrixDynamic or mrpt::math::CMatrixFixed
See also:
template <class T> void vectorRandomNormal( std::vector<T>& v_out, const T& mean = 0, const T& std = 1 )
Generates a random vector with independent, normally distributed samples.
See also:
void Randomize(const uint32_t seed)
Randomize the generators.
A seed can be providen, or a current-time based seed can be used (default)
template <class T> void randomPermutation( 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.
template <typename T, typename MATRIX> void randomNormalMultiDimensionalMany( const MATRIX& cov, size_t desiredSamples, std::vector<std::vector<T>>& ret, std::vector<T>* samplesLikelihoods = nullptr )
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 |
std::exception |
On invalid covariance matrix |
See also:
template <typename T, typename MATRIXLIKE> void randomNormalMultiDimensionalMany( const MATRIXLIKE& cov, size_t desiredSamples, std::vector<std::vector<T>>& ret )
Generate multidimensional random samples according to a given covariance matrix.
Parameters:
std::exception |
On invalid covariance matrix |
See also:
template <typename T, typename MATRIX> void randomNormalMultiDimensional( const MATRIX& cov, std::vector<T>& out_result )
Generate multidimensional random samples according to a given covariance matrix.
Parameters:
std::exception |
On invalid covariance matrix |
See also: