9#ifndef _MRPT_MONTE_CARLO_H_
10#define _MRPT_MONTE_CARLO_H_
21namespace 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) {
46 data.assign(v1.begin(),v1.end());
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());
58 inline void getDistribution(std::vector<double> &vx,std::vector<double> &vy,
const NUM width=1.0)
const {
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);
83 std::transform(baseData.begin(),baseData.end(),errorData.begin(),
errorFun1);
87 std::vector<OTHER> intermediate(N);
88 transform(baseData.begin(),baseData.end(),intermediate.begin(),
intermediateFun);
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();
This class provides an easy way of computing histograms for unidimensional real valued variables.
static CHistogram createWithFixedWidth(double min, double max, double binWidth)
Constructor with a fixed bin width.
void getHistogram(std::vector< double > &x, std::vector< double > &hits) const
Returns the list of bin centers & hit counts.
void add(const double x)
Add an element to the histogram.
void setData(const VEC &v1)
CStatisticalAnalyzer(const VEC &v1)
Eigen::Matrix< NUM, Eigen::Dynamic, 1 > data
void getDistribution(VEC1 &vx, VEC2 &vy, const NUM width=1.0) const
void getData(VEC &v1) const
void getDistribution(std::vector< double > &vx, std::vector< double > &vy, const NUM width=1.0) const
Montecarlo simulation for experiments in 1D.
T(* valueGenerator)(mrpt::random::CRandomGenerator &)
OTHER(* intermediateFun)(const T &)
NUM doExperiment(size_t N, double &time, bool showInWindow=false)
mrpt::random::CRandomGenerator gen
NUM(* errorFun1)(const T &)
NUM(* errorFun2)(const T &, const OTHER &)
A thred-safe pseudo random number generator, based on an internal MT19937 randomness generator.
This class implements a high-performance stopwatch.
double Tac()
Stops the stopwatch.
void Tic()
Starts the stopwatch.
EIGEN_STRONG_INLINE iterator begin()
EIGEN_STRONG_INLINE iterator end()
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.