diff options
Diffstat (limited to 'src/stratified_sampling.hpp')
| -rw-r--r-- | src/stratified_sampling.hpp | 38 |
1 files changed, 14 insertions, 24 deletions
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 <vector> #include <algorithm> #include <iostream> -#include <gsl/gsl_rng.h> -#include "rtnorm.hpp" #include "var_alea.hpp" #include <gsl/gsl_cdf.h> #include "option.hpp" using namespace std; +vector<double> quantile_norm(int n, double sigma); -typedef var_alea<double> var_alea_real; -struct gaussian_truncated : public var_alea_real +struct gaussian_truncated : var_alea<double> { - 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<double, double> 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<std::vector<double> > { multi_gaussian_truncated(double a, double b, const std::vector<double> u) |
