9 #ifndef _MRPT_MONTE_CARLO_H_ 10 #define _MRPT_MONTE_CARLO_H_ 44 template <
typename T,
typename NUM,
typename OTHER>
52 Eigen::Matrix<NUM, Eigen::Dynamic, 1>
data;
55 template <
typename VEC>
59 template <
typename VEC>
64 template <
typename VEC>
69 template <
typename VEC1,
typename VEC2>
71 VEC1& vx, VEC2& vy,
const NUM
width = 1.0)
const 73 std::vector<double> vvx, vvy;
75 vx.assign(vvx.begin(), vvx.end());
76 vy.assign(vvy.begin(), vvy.end());
80 std::vector<double>& vx, std::vector<double>& vy,
81 const NUM
width = 1.0)
const 87 hist.getHistogram(vx, vy);
111 throw std::logic_error(
"Value generator function is not set.");
112 std::vector<T> baseData(N);
113 std::vector<NUM> errorData(N);
120 baseData.begin(), baseData.end(), errorData.begin(),
errorFun1);
126 throw std::logic_error(
127 "Experiment-related functions are not set.");
128 std::vector<OTHER> intermediate(N);
130 baseData.begin(), baseData.end(), intermediate.begin(),
133 for (
size_t i = 0; i < N; ++i)
134 errorData[i] =
errorFun2(baseData[i], intermediate[i]);
137 NUM
res = accumulate(errorData.begin(), errorData.end(), NUM(0)) /
144 std::vector<NUM> errorX,errorY;
146 wnd.
plot(errorX,errorY,
"b-",
"Plot1");
147 NUM maxVal=*std::max_element(errorY.begin(),errorY.end());
148 const std::vector<NUM> dx{
res,
res}, dy{.0, maxVal};
149 wnd.
plot(dx,dy,
"r-",
"Plot2");
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
Create a GUI window and display plots with MATLAB-like interfaces and commands.
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
Eigen::Matrix< NUM, Eigen::Dynamic, 1 > data
This class implements a high-performance stopwatch.
bool isOpen()
Returns false if the user has already closed the window.
OTHER(* intermediateFun)(const T &)
void plot(const std::vector< T1 > &x, const std::vector< T2 > &y, const std::string &lineFormat=std::string("b-"), const std::string &plotName=std::string("plotXY"))
Adds a new layer with a 2D plot based on two vectors of X and Y points, using a MATLAB-like syntax...
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.
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 &)