48 MT19937_initializeGenerator(seed);
56 MT19937_initializeGenerator(
65 return m_normdistribution(m_MT19937);
73 const size_t dim,
const double std_scale,
const double diagonal_epsilon)
76 drawGaussian1DMatrix(
r, 0, std_scale);
79 for (
size_t i = 0; i < dim; i++)
80 cov(i, i) += diagonal_epsilon;
90 const std::vector<T>*
mean)
93 const size_t dim =
cov.getColCount();
103 out_result.resize(dim, 0);
110 cov.eigenVectors(Z, D);
113 D = D.array().sqrt().matrix();
116 for (
size_t i = 0; i < dim; i++)
118 T rnd = this->drawGaussian1D_normalized();
119 for (
size_t d = 0; d < dim; d++)
120 out_result[d] += (Z.get_unsafe(d, i) * rnd);
123 for (
size_t d = 0; d < dim; d++) out_result[d] += (*
mean)[d];
126 printf(
"\nEXCEPTION: Dumping variables for debugging:\n");
132 cov.eigenVectors(Z, D);
133 std::cout <<
"Original Z:" << Z <<
"Original D:" << D;
138 template void CRandomGenerator::drawGaussianMultivariate<double>(
140 const std::vector<double>*
mean);
141 template void CRandomGenerator::drawGaussianMultivariate<float>(
143 const std::vector<float>*
mean);
164 2.3283064370807973754314699618685e-10;
A namespace of pseudo-random numbers genrators of diferent distributions.
uint32_t drawUniform32bit()
Generate a uniformly distributed pseudo-random number using the MT19937 algorithm, in the whole range of 32-bit integers.
double RandomNormal(double mean, double std)
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
#define MRPT_END_WITH_CLEAN_UP(stuff)
mrpt::system::TTimeStamp getCurrentTime()
Returns the current (UTC) system time.
A thred-safe pseudo random number generator, based on an internal MT19937 randomness generator...
double drawGaussian1D(const double mean, const double std)
Generate a normally distributed pseudo-random number.
static CRandomGenerator randomGenerator
This base provides a set of functions for maths stuff.
uint64_t drawUniform64bit()
Returns a uniformly distributed pseudo-random number by joining two 32bit numbers from drawUniform32b...
mrpt::math::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*...
unsigned __int64 uint64_t
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLdouble GLdouble GLdouble r
void randomize()
Randomize the generators, based on current time.
void MT19937_initializeGenerator(const uint32_t &seed)
Eigen::Matrix< typename MATRIX::Scalar, MATRIX::ColsAtCompileTime, MATRIX::ColsAtCompileTime > cov(const MATRIX &v)
Computes the covariance matrix from a list of samples in an NxM matrix, where each row is a sample...
double RandomUni(const double min, const double max)
void drawGaussianMultivariate(std::vector< T > &out_result, const mrpt::math::CMatrixTemplateNumeric< T > &cov, const std::vector< T > *mean=nullptr)
Generate multidimensional random samples according to a given covariance matrix.
unsigned __int32 uint32_t
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.
double drawGaussian1D_normalized()
Generate a normalized (mean=0, std=1) normally distributed sample.
double normalizedGaussian()