forked from jtlap/nt2
/
qmtc.hpp
112 lines (95 loc) · 4.48 KB
/
qmtc.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//==============================================================================
// Copyright 2003 - 2012 LASMEA UMR 6602 CNRS/Univ. Clermont II
// Copyright 2009 - 2012 LRI UMR 8623 CNRS/Univ Paris Sud XI
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//==============================================================================
#ifndef NT2_INTEGRATION_FUNCTIONS_QMTC_HPP_INCLUDED
#define NT2_INTEGRATION_FUNCTIONS_QMTC_HPP_INCLUDED
#include <nt2/integration/interfacen.hpp>
namespace nt2
{
namespace tag
{
struct qmtc_ : ext::unspecified_<qmtc_>
{
/// @brief Parent hierarchy
typedef ext::unspecified_<qmtc_> parent;
template<class... Args>
static BOOST_FORCEINLINE BOOST_AUTO_DECLTYPE dispatch(Args&&... args)
BOOST_AUTO_DECLTYPE_BODY( dispatching_qmtc_( ext::adl_helper(), static_cast<Args&&>(args)... ) )
};
}
namespace ext
{
template<class Site, class... Ts>
BOOST_FORCEINLINE generic_dispatcher<tag::qmtc_, Site> dispatching_qmtc_(adl_helper, boost::dispatch::meta::unknown_<Site>, boost::dispatch::meta::unknown_<Ts>...)
{
return generic_dispatcher<tag::qmtc_, Site>();
}
template<class... Args>
struct impl_qmtc_;
}
// specialization of abstol for qmtc method
template<class T, class V> struct integ_params<T, V, tag::qmtc_>
: integ_params<T, V, void>
{
typedef typename nt2::integ_params<T, V, void>::real_t real_t;
static bool enabled_singular_a() { return false; }
static bool enabled_singular_b() { return false; }
static bool enabled_abstol() { return false; }
static bool enabled_reltol() { return false; }
static bool enabled_maxintvcnt() { return false; }
static bool enabled_waypoints() { return false; }
static bool enabled_return_waypoints() { return false; }
static bool enabled_nbextrap() { return false; }
static bool enabled_maxstep() { return false; }
};
//============================================================================
/*! Apply qmtc algorithm to integrate a function over a real
hyper-rectangle using quasi-random numbers
\param f Function to optimize.
f must be a functor taking a matrix with n rows and any
number of columns able to return a row values: one by
data column.
\param ranges ranges of integration as a nx2xm expression.
Each line is an interval for a range of integration
and this for each page of ranges.
To be explicit a matrix as [0, 1; 1, 2] in matlab notation
will provide \f$\int_0^1 \int_1^2 f(x, y) dx dy\f$.
\param opt Options pack related to the tolerance handling
\return a tuple containing the result of the integration, the last
error value, the number of required function evaluation and a
boolean notifying success of the whole process.
Approximates the n superposed integrals of a scalar-valued from
\f$R^n\f$ to \f$R\f$ or \f$C\f$ in an hyper-rectangle with a simple Monte-Carlo
approach, but using quasi-random numbers.
@par Notes:
- f can have complex outputs but only real inputs.
- there is no way to ask for a given precision. The precision
depends of the number of evaluation points (default 10000) that can
be set with maxfunccnt_ option value. It can be said that if you multiply
limits::maxfunccnt_ by n, the error will be divided by sqrt(n).
- By default the returned error estimate is computed, but this is can be
expansive. If you do not care for an error estimate use the
option tolerance::compute_error_ = false
@see @funcref{mtc}, @funcref{quasi}
*/
//============================================================================
template<class F, class X, class Xpr> BOOST_FORCEINLINE
typename details::integration_n<F, X, tag::qmtc_>::result_type
qmtc(F f, X const& ranges, nt2::details::option_expr<Xpr> const& opt)
{
return details::integration_n<F, X, tag::qmtc_>::call(f, ranges, opt);
}
/// @overload
template<class F, class X> BOOST_FORCEINLINE
typename details::integration_n<F, X, tag::qmtc_>::result_type
qmtc(F f, X const& ranges)
{
return details::integration_n<F, X, tag::qmtc_>::call(f, ranges);
}
}
#endif