aboutsummaryrefslogtreecommitdiffstats
path: root/src/stratified_sampling.hpp
diff options
context:
space:
mode:
authorBertrand <bertrand.horel@gmail.com>2016-02-21 14:26:26 +0000
committerBertrand <bertrand.horel@gmail.com>2016-02-21 14:26:26 +0000
commit045fc28b3432e07f3d9702150a56f21e7650f12a (patch)
tree6465e412bdb9ac2c45eaa4434a9897925e620622 /src/stratified_sampling.hpp
parentbb210dbdc524ad51927a9932638078ddb1383bb6 (diff)
downloadprojet_C++-045fc28b3432e07f3d9702150a56f21e7650f12a.tar.gz
modif du Makefile et de var_alea et autres
Diffstat (limited to 'src/stratified_sampling.hpp')
-rw-r--r--src/stratified_sampling.hpp44
1 files changed, 33 insertions, 11 deletions
diff --git a/src/stratified_sampling.hpp b/src/stratified_sampling.hpp
index 81080fc..cebee8d 100644
--- a/src/stratified_sampling.hpp
+++ b/src/stratified_sampling.hpp
@@ -3,20 +3,11 @@
#include <iostream>
#include <gsl/gsl_rng.h>
#include "rtnorm.hpp"
+#include "var_alea.hpp"
+#include <gsl/gsl_cdf.h>
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;
@@ -45,6 +36,37 @@ private:
gsl_rng *gen;
};
+struct multi_gaussian_truncated : public var_alea<std::vector<double> >
+{
+ multi_gaussian_truncated(double a, double b, const std::vector<double> u)
+ :a(a), b(b), V(gsl_cdf_ugaussian_P(a), gsl_cdf_ugaussian_P(b)), G(0,1), u(u), d(u.size()) {};
+
+ std::vector<double> operator()() {
+ double v = V();
+ double Z = gsl_cdf_gaussian_Pinv(v,1);
+ std::vector<double> Y(d);
+ double scal = 0;
+ for(int i=0; i<d; i++){
+ Y[i] = G();
+ }
+ std::vector<double> X(d);
+ for(int j=0; j<d; j++){
+ scal += Y[j]*u[j];
+ }
+ for(int i=0; i<d; i++){
+ X[i] = u[i]*Z + Y[i] - u[i]*scal;
+ }
+ return X;
+ }
+
+ private:
+ double a, b;
+ uniform V;
+ gaussian G;
+ std::vector<double> u;
+ int d;
+ };
+
template <typename L>
struct stratified_sampling {
stratified_sampling(vector<double> p, vector<L> X)