27#ifndef G2O_GAUSSIAN_SAMPLER_
28#define G2O_GAUSSIAN_SAMPLER_
43 std::mt19937* generator = 0);
46template <
class SampleType,
class CovarianceType>
54 Eigen::LLT<CovarianceType> cholDecomp;
55 cholDecomp.compute(cov);
56 if (cholDecomp.info() == Eigen::NumericalIssue) {
57 assert(
false &&
"Cholesky decomposition on the covariance matrix failed");
65 for (
int i = 0; i < s.size(); i++) {
89 static double gaussRand(
double mean,
double sigma) {
92 double x = -1.0 + 2.0 * uniformRand(0.0, 1.0);
93 y = -1.0 + 2.0 * uniformRand(0.0, 1.0);
95 }
while (r2 > 1.0 || r2 == 0.0);
96 return mean + sigma * y * std::sqrt(-2.0 * log(r2) / r2);
104 ((double)std::rand() / (RAND_MAX + 1.0)) * (upperBndr - lowerBndr);
110 seedRand(
static_cast<unsigned int>(std::time(NULL)));
114 static void seedRand(
unsigned int seed) { std::srand(seed); }
std::unique_ptr< std::mt19937 > _generator
GaussianSampler(GaussianSampler const &)=delete
GaussianSampler & operator=(const GaussianSampler &)=delete
SampleType generateSample()
return a sample of the Gaussian distribution
void setDistribution(const CovarianceType &cov)
GaussianSampler(bool hasGenerator=true)
static void seedRand(unsigned int seed)
static double gaussRand(double mean, double sigma)
static double uniformRand(double lowerBndr, double upperBndr)
double sampleUniform(double min, double max, std::mt19937 *generator)
double sampleGaussian(std::mt19937 *generator)