25#include <ql/math/integrals/gaussianquadratures.hpp>
26#include <ql/methods/montecarlo/lsmbasissystem.hpp>
36 typedef std::vector<ext::function<
Real(
Real)> > VF_R;
37 typedef std::vector<ext::function<
Real(Array)> > VF_A;
38 typedef std::vector<std::vector<Size> > VV;
43 explicit MonomialFct(
Size order): order_(order) {}
44 inline Real operator()(
const Real x)
const {
46 for(
Size i=0; i<order_; ++i)
58 explicit MultiDimFct(VF_R b) : b_(
std::move(b)) {
59 QL_REQUIRE(!b_.empty(),
"zero size basis");
61 inline Real operator()(
const Array& a)
const {
62 #if defined(QL_EXTRA_SAFETY_CHECKS)
63 QL_REQUIRE(b_.size()==a.size(),
"wrong argument size");
65 Real ret = b_[0](a[0]);
66 for(
Size i=1; i<b_.size(); ++i)
75 void check_tuples(
const VV& v,
Size dim,
Size order) {
76 for (
const auto& i : v) {
77 QL_REQUIRE(dim == i.size(),
"wrong tuple size");
78 QL_REQUIRE(order == std::accumulate(i.begin(), i.end(), 0UL),
"wrong tuple order");
83 VV next_order_tuples(
const VV& v) {
84 const Size order = std::accumulate(v[0].begin(), v[0].end(), 0UL);
85 const Size dim = v[0].size();
87 check_tuples(v, dim, order);
90 std::set<std::vector<Size> > tuples;
92 for(
Size i=0; i<dim; ++i) {
94 for (
const auto& j : v) {
101 VV ret(tuples.begin(), tuples.end());
111 for (
Size i=0; i<=order; ++i) {
114 ret[i] = MonomialFct(i);
153 QL_FAIL(
"unknown regression type");
161 QL_REQUIRE(dim>0,
"zero dimension");
166 VF_R term(dim, pathBasis[0]);
167 ret.emplace_back(MultiDimFct(term));
169 VV tuples(1, std::vector<Size>(dim));
171 for(
Size i=1; i<=order; ++i) {
172 tuples = next_order_tuples(tuples);
175 for (
auto& tuple : tuples) {
176 for(
Size k=0; k<dim; ++k)
177 term[k] = pathBasis[tuple[k]];
178 ret.emplace_back(MultiDimFct(term));
Gauss-Chebyshev polynomial (second kind)
Gauss-Chebyshev polynomial.
Gauss-Hermite polynomial.
Gauss hyperbolic polynomial.
Gauss-Laguerre polynomial.
Gauss-Legendre polynomial.
Real weightedValue(Size i, Real x) const
static std::vector< ext::function< Real(Real)> > pathBasisSystem(Size order, PolynomialType type)
static std::vector< ext::function< Real(Array)> > multiPathBasisSystem(Size dim, Size order, PolynomialType type)
std::size_t Size
size of a container