-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathRandomNumbers.cpp
More file actions
53 lines (35 loc) · 1.5 KB
/
RandomNumbers.cpp
File metadata and controls
53 lines (35 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "RandomNumbers.h"
#include <iostream>
RandomNumbers::RandomNumbers() :
m_numericTools(0)
{
m_numericTools = new NumericTools();
}
RandomNumbers::~RandomNumbers()
{
if ( m_numericTools ) delete m_numericTools;
}
double RandomNumbers::univariateGaussian(double mu, double sigma)
{
return m_numericTools->generateStandardDistributionRand(mu, sigma);
}
Eigen::Vector3f RandomNumbers::multivariateGaussian(Eigen::Vector3f &mu, Eigen::Matrix3f &covariance)
{
// to generate multivariate gaussian random numbers given mean and covariance
// 1. decompose the covariance with cholesky LU: cov = U'U (size n x n)
// 2. generate n normally distributed random numbers in a vector RND (size n x 1)
// 3. generate the multivariate random number: mvrnd = mu + U' * RND
Eigen::FullPivHouseholderQR<Eigen::Matrix3f> _qr(covariance);
Eigen::LLT<Eigen::Matrix3f> _test;
_test.compute(covariance);
Eigen::Matrix3f _Uprime = Eigen::Matrix3f::Zero();
_Uprime.block<3,3>(0,0).part<Eigen::Lower>() = _test.matrixL();
//std::cout <<"L" << std::endl << _Uprime << std::endl;
// random vector
Eigen::Vector3f _randomVec = Eigen::Vector3f::Zero(3);
double _stdVal1 = 0.0;
double _stdVal2 = 1.0;
_randomVec << m_numericTools->generateStandardDistributionRand(_stdVal1, _stdVal2), m_numericTools->generateStandardDistributionRand(_stdVal1, _stdVal2), m_numericTools->generateStandardDistributionRand(_stdVal1, _stdVal2);;
return _Uprime*_randomVec+mu;
//Eigen::LU
}