aboutsummaryrefslogtreecommitdiffstats
path: root/stratified_sampling.hpp
diff options
context:
space:
mode:
authorBertrand <bertrand.horel@gmail.com>2016-02-06 19:32:06 +0000
committerBertrand <bertrand.horel@gmail.com>2016-02-06 19:32:06 +0000
commit22358d075a89d44dbe8ef901a0a42d2c3f8e285a (patch)
tree9b22d4b0f4bb7131ed37ddd9973a23845a9109ef /stratified_sampling.hpp
parent65a9710eb66dbc00d4c4962467b753f62e7fcffe (diff)
downloadprojet_C++-22358d075a89d44dbe8ef901a0a42d2c3f8e285a.tar.gz
encapsulage du stratified sampling
Diffstat (limited to 'stratified_sampling.hpp')
-rw-r--r--stratified_sampling.hpp51
1 files changed, 51 insertions, 0 deletions
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 <vector>
+#include <gsl/gsl_rng.h>
+#include "rtnorm.hpp"
+
+using namespace std;
+
+template <typename T>
+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<double> 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<double, double> 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 <typename Gen>
+struct stratified_sampling {
+ stratified_sampling(vector<double> p, vector<Gen> gen)
+ :p(p), gen(gen) {};
+ void update(int N);
+ //vector<double> get_mean();
+ //double estimator();
+private:
+ vector<double> p;
+ vector<int> M;
+ vector<double> sigma;
+ vector<Gen> gen;
+
+};