diff options
| author | Guillaume Horel <guillaume.horel@serenitascapital.com> | 2016-02-18 18:13:02 -0500 |
|---|---|---|
| committer | Bertrand <bertrand.horel@gmail.com> | 2016-04-15 14:35:07 +0200 |
| commit | b23e6679cfce2f3d4266cb318c3b4afec6073449 (patch) | |
| tree | 424fd2038318905c207b4b5f0fba9a1978931e21 /src/low_discrepancy.hpp | |
| parent | 745160f29da6ec55fa48863768bcc1305edd9314 (diff) | |
| download | projet_C++-b23e6679cfce2f3d4266cb318c3b4afec6073449.tar.gz | |
add Nlopt version of sobol which allows higher dimensions
Diffstat (limited to 'src/low_discrepancy.hpp')
| -rw-r--r-- | src/low_discrepancy.hpp | 73 |
1 files changed, 48 insertions, 25 deletions
diff --git a/src/low_discrepancy.hpp b/src/low_discrepancy.hpp index 6b3c1bd..bc8e820 100644 --- a/src/low_discrepancy.hpp +++ b/src/low_discrepancy.hpp @@ -8,6 +8,9 @@ #include <algorithm> #include <numeric> #include <gsl/gsl_qrng.h> +#ifdef NLOPT +#include "nlopt-util.h" +#endif class p_adic { public: @@ -159,27 +162,32 @@ struct faure { struct sobol { - typedef std::vector<double> result_type; - sobol(int dimension) : dimension(dimension), result(dimension) { - q = gsl_qrng_alloc(gsl_qrng_sobol, dimension); - } - sobol(sobol const & o) : dimension(o.dimension) { - q = gsl_qrng_clone(o.q); - result = o.result; - } + typedef std::vector<double> result_type; + sobol(int dimension) : dimension(dimension), result(dimension) { +#ifdef NLOPT + s = nlopt_sobol_create(dimension); +#else + q = gsl_qrng_alloc(gsl_qrng_sobol, dimension); +#endif + } +#ifndef NLOPT + sobol(sobol const & o) : dimension(o.dimension) { + q = gsl_qrng_clone(o.q); + result = o.result; + } // constructeur move uniquement en C++11 sobol(sobol && o) : dimension(o.dimension), q(o.q), result(std::move(o.result)) { o.dimension = 0; o.q = nullptr; } - sobol & operator=(sobol const & o) { - if (this != &o) { - dimension = o.dimension; - gsl_qrng_memcpy(q, o.q); - result = o.result; - } - return *this; - } + sobol & operator=(sobol const & o) { + if (this != &o) { + dimension = o.dimension; + gsl_qrng_memcpy(q, o.q); + result = o.result; + } + return *this; + } // operateur move uniquement en C++11 sobol & operator=(sobol && o) { if (this != &o) { @@ -191,15 +199,30 @@ struct sobol { } return *this; } - ~sobol() { gsl_qrng_free(q); } - result_type operator()() { - gsl_qrng_get(q, &(*result.begin())); - return result; - } - protected: - int dimension; - gsl_qrng * q; - result_type result; +#endif + ~sobol() { +#ifdef NLOPT + nlopt_sobol_destroy(s); +#else + gsl_qrng_free(q); +#endif + } + result_type operator()() { +#ifdef NLOPT + nlopt_sobol_next01(s, result.data()); +#else + gsl_qrng_get(q, result.data()); +#endif + return result; + } +protected: + int dimension; +#ifdef NLOPT + nlopt_sobol s; +#else + gsl_qrng * q; +#endif + result_type result; }; #endif |
