9 #ifndef _MRPT_MONTE_CARLO_H_ 10 #define _MRPT_MONTE_CARLO_H_ 21 namespace mrpt {
namespace math {
37 template<
typename T,
typename NUM,
typename OTHER>
class CMonteCarlo {
42 Eigen::Matrix<NUM,Eigen::Dynamic,1>
data;
45 template<
typename VEC>
inline void setData(
const VEC &
v1) {
48 template<
typename VEC>
inline void getData(VEC &
v1)
const {
51 template<
typename VEC1,
typename VEC2>
inline void getDistribution(VEC1 &vx,VEC2 &vy,
const NUM
width=1.0)
const {
52 std::vector<double> vvx,vvy;
54 vx.assign(vvx.begin(),vvx.end());
55 vy.assign(vvy.begin(),vvy.end());
61 hist.getHistogram(vx,vy);
76 if (!
valueGenerator)
throw std::logic_error(
"Value generator function is not set.");
77 std::vector<T> baseData(N);
78 std::vector<NUM> errorData(N);
87 std::vector<OTHER> intermediate(N);
90 for (
size_t i=0;i<N;++i) errorData[i]=
errorFun2(baseData[i],intermediate[i]);
93 NUM
res=accumulate(errorData.begin(),errorData.end(),NUM(0))/errorData.size();
void setData(const VEC &v1)
This class provides an easy way of computing histograms for unidimensional real valued variables...
CStatisticalAnalyzer(const VEC &v1)
void getDistribution(VEC1 &vx, VEC2 &vy, const NUM width=1.0) const
NUM doExperiment(size_t N, double &time, bool showInWindow=false)
T(* valueGenerator)(mrpt::random::CRandomGenerator &)
EIGEN_STRONG_INLINE iterator begin()
A thred-safe pseudo random number generator, based on an internal MT19937 randomness generator...
void Tic()
Starts the stopwatch.
void add(const double x)
Add an element to the histogram.
void getData(VEC &v1) const
This class implements a high-performance stopwatch.
OTHER(* intermediateFun)(const T &)
NUM(* errorFun1)(const T &)
void getDistribution(std::vector< double > &vx, std::vector< double > &vy, const NUM width=1.0) const
mrpt::random::CRandomGenerator gen
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Eigen::Matrix< NUM, Eigen::Dynamic, 1 > data
double Tac()
Stops the stopwatch.
Montecarlo simulation for experiments in 1D.
GLuint GLenum GLenum transform
GLsizei GLsizei GLenum GLenum const GLvoid * data
static CHistogram createWithFixedWidth(double min, double max, double binWidth)
Constructor with a fixed bin width.
NUM(* errorFun2)(const T &, const OTHER &)