From cee0800329a0be3b27ae3907498ddf0883393382 Mon Sep 17 00:00:00 2001 From: Bertrand Date: Mon, 15 Feb 2016 19:16:29 +0000 Subject: création de nouvelles classes, composition de monte_carlo... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rqmc.hpp | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 rqmc.hpp (limited to 'rqmc.hpp') diff --git a/rqmc.hpp b/rqmc.hpp new file mode 100644 index 0000000..62efbaa --- /dev/null +++ b/rqmc.hpp @@ -0,0 +1,96 @@ +#include "low_discrepancy.hpp" +#include +#include +#include "var_alea.hpp" + + +double frac_part(double x); + +//fonctions de compositions de monte_carlo.hpp + +template +struct generator +{ + typedef _Result result_type; +}; + +template +struct compose_t : public generator< typename Fct::result_type > +{ + compose_t(Fct f, VA X) : f(f), X(X) {}; + typename Fct::result_type operator()() { + return f(X()); + }; + private: + Fct f; VA X; +}; + +template +inline compose_t +compose(Fct f, VA X) { + return compose_t(f, X); +}; + +// + +template +std::vector monte_carlo(int n, L X) +{ + std::vector result(3,0); + double x; + for (int j = 0; j < n; j++) { + x = X(); + result[0] += x; + result[1] += x*x; + } + result[0] /= (double) n; + result[1] = (result[1] - n*result[0]*result[0])/(double)(n-1); + result[2] = 1.96*sqrt(result[1]/(double) n); + return result; +}; + +template +std::vector monte_carlo(int n, Fct f, L X) +{ + return monte_carlo(n, compose(f, X)); +}; + +struct quasi_gaussian : public var_alea > +{ + quasi_gaussian (int d, double mean = 0, double std =1) + : d(d), mean(mean), std(std), sob(d) {}; + std::vector operator ()(){ + std::vector result = sob(); + for(int i=0;i > +{ + gaussian_d(int d, double mean = 0, double std =1) + : d(d), mean(mean), std(std), G(mean, std) {}; + std::vector operator ()(){ + std::vector result(d); + for(int i=0;i