From 4e5104a0186bd705b5ed1f57f73375ace60587f6 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Tue, 12 Apr 2016 12:23:13 -0400 Subject: Rename f_mu as exponential_tilt and template it instead of having it depend on asian_option --- src/stratified_sampling.hpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'src/stratified_sampling.hpp') diff --git a/src/stratified_sampling.hpp b/src/stratified_sampling.hpp index 9099e38..9175f75 100644 --- a/src/stratified_sampling.hpp +++ b/src/stratified_sampling.hpp @@ -3,7 +3,6 @@ #include #include "var_alea.hpp" #include -#include "option.hpp" using namespace std; @@ -14,14 +13,14 @@ struct gaussian_truncated : var_alea { 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()() { double v = V(); return mu + gsl_cdf_gaussian_Pinv(v,sigma); } - + private: - double a, b; + double a, b; uniform V; double mu; double sigma; @@ -31,7 +30,7 @@ struct multi_gaussian_truncated : public var_alea > { multi_gaussian_truncated(double a, double b, const std::vector 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 operator()() { double v = V(); double Z = gsl_cdf_gaussian_Pinv(v,1); @@ -49,9 +48,9 @@ struct multi_gaussian_truncated : public var_alea > } return X; } - + private: - double a, b; + double a, b; uniform V; gaussian G; std::vector u; @@ -180,15 +179,16 @@ pair stratified_sampling::estimator() const { return {est_mean, est_std}; } -struct f_mu : public std::unary_function, double> +template +struct exponential_tilt : public std::unary_function, double> { - f_mu(std::vector mu, asian_option A) : mu(mu), A(A){ + exponential_tilt(std::vector mu, Fct f) : mu(mu), f(f){ norm_mu = 0; for(unsigned int i=0; i X) { std::vector Y(X.size()); double scal = 0; @@ -196,12 +196,11 @@ struct f_mu : public std::unary_function, double> Y[i] = X[i] + mu[i]; scal+=X[i]*mu[i]; } - return A(Y)*exp(-scal-0.5*norm_mu); + return f(Y) * exp(-scal-0.5*norm_mu); }; - - private : + + private: std::vector mu; - asian_option A; + Fct f; double norm_mu; }; - -- cgit v1.2.3-70-g09d2