From 69ef15f06495b92bd619963eb543cb098bab479c Mon Sep 17 00:00:00 2001 From: Bertrand Date: Tue, 1 Mar 2016 14:32:31 +0000 Subject: on n'utilise plus rtnorm --- src/stratified_sampling.hpp | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) (limited to 'src/stratified_sampling.hpp') diff --git a/src/stratified_sampling.hpp b/src/stratified_sampling.hpp index c04369e..9099e38 100644 --- a/src/stratified_sampling.hpp +++ b/src/stratified_sampling.hpp @@ -1,42 +1,32 @@ #include #include #include -#include -#include "rtnorm.hpp" #include "var_alea.hpp" #include #include "option.hpp" using namespace std; +vector quantile_norm(int n, double sigma); -typedef var_alea var_alea_real; -struct gaussian_truncated : public var_alea_real +struct gaussian_truncated : var_alea { - gaussian_truncated(double a, double b, double mean=0, double sigma2=1, int seed=0) - :a(a), b(b), mean(mean), sigma2(sigma2), seed(seed) { - const gsl_rng_type* type = gsl_rng_default; - gen = gsl_rng_alloc(type); - gsl_rng_set(gen, seed); - }; - gaussian_truncated(gaussian_truncated const &other) - :a(other.a),b(other.b), mean(other.mean),sigma2(other.sigma2){ - gen = gsl_rng_clone(other.gen); - }; - + gaussian_truncated(double a, double b, double mu = 0, double sigma = 1) + :a(a), b(b), V(gsl_cdf_ugaussian_P(a), gsl_cdf_ugaussian_P(b)), mu(mu), sigma(sigma) {}; + double operator()() { - pair p = rtnorm(gen, a, b, mean, sigma2); - return value = p.first; + double v = V(); + return mu + gsl_cdf_gaussian_Pinv(v,sigma); + } + + private: + double a, b; + uniform V; + double mu; + double sigma; }; - ~gaussian_truncated() { gsl_rng_free(gen); } -private: - double a, b, mean, sigma2; - int seed; - gsl_rng *gen; -}; - struct multi_gaussian_truncated : public var_alea > { multi_gaussian_truncated(double a, double b, const std::vector u) -- cgit v1.2.3-70-g09d2