From 22358d075a89d44dbe8ef901a0a42d2c3f8e285a Mon Sep 17 00:00:00 2001 From: Bertrand Date: Sat, 6 Feb 2016 19:32:06 +0000 Subject: encapsulage du stratified sampling --- stratified_sampling.hpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 stratified_sampling.hpp (limited to 'stratified_sampling.hpp') diff --git a/stratified_sampling.hpp b/stratified_sampling.hpp new file mode 100644 index 0000000..b63cd52 --- /dev/null +++ b/stratified_sampling.hpp @@ -0,0 +1,51 @@ +#include +#include +#include "rtnorm.hpp" + +using namespace std; + +template +struct var_alea { + typedef T result_type; + var_alea() : value(0) {}; + var_alea(T value) : value(value) {}; + virtual ~var_alea() {}; + virtual T operator()() = 0; + T current() const { return value; }; + protected: + T value; +}; + +typedef var_alea var_alea_real; + +struct gaussian_truncated : public var_alea_real +{ + gaussian_truncated(double a, double b, double mean=0, double sigma=1) + :a(a), b(b), mean(mean), sigma(sigma) { + const gsl_rng_type* type = gsl_rng_default; + gen = gsl_rng_alloc(type); + }; + double operator()() { + pair p = rtnorm(gen, a, b, mean, sigma); + return value = p.first; + }; + ~gaussian_truncated() { gsl_rng_free(gen); } +private: + double mean, sigma, a, b; + gsl_rng *gen; +}; + +template +struct stratified_sampling { + stratified_sampling(vector p, vector gen) + :p(p), gen(gen) {}; + void update(int N); + //vector get_mean(); + //double estimator(); +private: + vector p; + vector M; + vector sigma; + vector gen; + +}; -- cgit v1.2.3-70-g09d2