9 #ifndef _MRPT_MONTE_CARLO_H_ 10 #define _MRPT_MONTE_CARLO_H_ 42 template <
typename T,
typename NUM,
typename OTHER>
50 Eigen::Matrix<NUM, Eigen::Dynamic, 1>
data;
53 template <
typename VEC>
57 template <
typename VEC>
62 template <
typename VEC>
67 template <
typename VEC1,
typename VEC2>
69 VEC1& vx, VEC2& vy,
const NUM
width = 1.0)
const 71 std::vector<double> vvx, vvy;
73 vx.assign(vvx.begin(), vvx.end());
74 vy.assign(vvy.begin(), vvy.end());
78 std::vector<double>& vx, std::vector<double>& vy,
79 const NUM
width = 1.0)
const 85 hist.getHistogram(vx, vy);
109 throw std::logic_error(
"Value generator function is not set.");
110 std::vector<T> baseData(N);
111 std::vector<NUM> errorData(N);
118 baseData.begin(), baseData.end(), errorData.begin(),
errorFun1);
124 throw std::logic_error(
125 "Experiment-related functions are not set.");
126 std::vector<OTHER> intermediate(N);
128 baseData.begin(), baseData.end(), intermediate.begin(),
131 for (
size_t i = 0; i < N; ++i)
132 errorData[i] =
errorFun2(baseData[i], intermediate[i]);
135 NUM
res = accumulate(errorData.begin(), errorData.end(), NUM(0)) /
142 std::vector<NUM> errorX,errorY;
144 wnd.
plot(errorX,errorY,
"b-",
"Plot1");
145 NUM maxVal=*std::max_element(errorY.begin(),errorY.end());
146 const std::vector<NUM> dx{
res,
res}, dy{.0, maxVal};
147 wnd.
plot(dx,dy,
"r-",
"Plot2");
double Tac() noexcept
Stops the stopwatch.
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 &)
A high-performance stopwatch, with typical resolution of nanoseconds.
EIGEN_STRONG_INLINE iterator begin()
A thred-safe pseudo random number generator, based on an internal MT19937 randomness generator...
This base provides a set of functions for maths stuff.
void add(const double x)
Add an element to the histogram.
void getData(VEC &v1) const
Eigen::Matrix< NUM, Eigen::Dynamic, 1 > data
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
Montecarlo simulation for experiments in 1D.
void Tic() noexcept
Starts the stopwatch.
GLuint GLenum GLenum transform
GLsizei GLsizei GLenum GLenum const GLvoid * data
CHistogram createWithFixedWidth(double min, double max, double binWidth)
Constructor with a fixed bin width.
NUM(* errorFun2)(const T &, const OTHER &)