npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
ClassicalOrthoPoly1DFromWeight.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_CLASSICALORTHOPOLY1DFROMWEIGHT_HH_
2 #define NPSTAT_CLASSICALORTHOPOLY1DFROMWEIGHT_HH_
3 
4 /*!
5 // \file ClassicalOrthoPoly1DFromWeight.hh
6 //
7 // \brief Orthogonal polynomials on an interval with an arbitrary
8 // user-provided weight function
9 //
10 // Author: I. Volobouev
11 //
12 // November 2020
13 */
14 
15 #include <vector>
16 
18 #include "npstat/nm/Recurrence.hh"
20 
21 namespace npstat {
22  template <class Functor1D>
24  {
25  public:
26  /**
27  // "nIntegPoints" parameter is the number of integration points
28  // for the Fejer or rectangular rule quadrature. Note that Fejer
29  // quadrature with n points can integrate exactly polynomials of
30  // degree n-1 and that this quadrature will be used for calculating
31  // various inner products in which the density is used as the weight.
32  // Therefore, "nIntegPoints" should be at least 2*maxDegree + 1 + C,
33  // where "C" is the polynomial degree that can be used to approximate
34  // the density reasonably well.
35  //
36  // Rectangular rule quadrature can be used for densities whose
37  // multiple derivatives become very close to 0 near the support
38  // boundaries. In particular, rectangular quadrature is expected
39  // to be useful for KDE densities estimated with symmetric beta
40  // kernels without boundary correction and with support on
41  // an appropriately extended interval.
42  */
44  const Functor1D& fcn,
45  const unsigned maxDegree, const unsigned nIntegPoints,
46  const long double i_xmin, const long double i_xmax,
47  const OrthoPolyMethod m = OPOLY_STIELTJES,
48  const bool useFejerQuadrature = true)
49  : fcn_(fcn), xmin_(i_xmin), xmax_(i_xmax), maxdeg_(maxDegree)
50  {
51  initialize(nIntegPoints, m, useFejerQuadrature);
52  }
53 
54  inline virtual ~ClassicalOrthoPoly1DFromWeight() {}
55 
56  inline virtual ClassicalOrthoPoly1DFromWeight* clone() const
57  {return new ClassicalOrthoPoly1DFromWeight(*this);}
58 
59  inline virtual long double weight(const long double x) const
60  {return fcn_(x)/wsum_;}
61  inline virtual double xmin() const {return xmin_;}
62  inline virtual double xmax() const {return xmax_;}
63  inline virtual unsigned maxDegree() const {return maxdeg_;}
64 
65  inline virtual std::pair<long double,long double>
66  monicRecurrenceCoeffs(const unsigned deg) const
67  {
68  const Private::Recurrence& r = rCoeffs_.at(deg);
69  return std::pair<long double,long double>(r.alpha, r.beta);
70  }
71 
72  inline virtual std::pair<long double,long double>
73  recurrenceCoeffs(const unsigned deg) const
74  {
75  const Private::Recurrence& r = rCoeffs_.at(deg);
76  return std::pair<long double,long double>(r.alpha, r.sqrbeta);
77  }
78 
79  private:
80  void initialize(unsigned nIntegPoints, OrthoPolyMethod m,
81  bool useFejerQuadrature);
82 
83  template<class Quad1D>
84  void calcCoeffs(const Quad1D& quad, OrthoPolyMethod m);
85 
86  Functor1D fcn_;
87  std::vector<Private::Recurrence> rCoeffs_;
88  long double wsum_;
89  long double xmin_;
90  long double xmax_;
91  unsigned maxdeg_;
92 
93 #ifdef SWIG
94  public:
96  const Functor1D& fcn,
97  const unsigned maxDegree, const unsigned nIntegPoints,
98  const double i_xmin, const double i_xmax,
99  const OrthoPolyMethod m = OPOLY_STIELTJES,
100  const bool useFejerQuadrature = true)
101  : fcn_(fcn), xmin_(i_xmin), xmax_(i_xmax), maxdeg_(maxDegree)
102  {
103  initialize(nIntegPoints, m, useFejerQuadrature);
104  }
105 #endif
106  };
107 }
108 
109 #include "npstat/nm/ClassicalOrthoPoly1DFromWeight.icc"
110 
111 #endif // NPSTAT_CLASSICALORTHOPOLY1DFROMWEIGHT_HH_
Base class for classical continuous orthonormal polynomials.
Enumeration of methods used to create orthogonal polynomials with discrete weights.
Definition: AbsClassicalOrthoPoly1D.hh:32
Definition: ClassicalOrthoPoly1DFromWeight.hh:24
ClassicalOrthoPoly1DFromWeight(const Functor1D &fcn, const unsigned maxDegree, const unsigned nIntegPoints, const long double i_xmin, const long double i_xmax, const OrthoPolyMethod m=OPOLY_STIELTJES, const bool useFejerQuadrature=true)
Definition: ClassicalOrthoPoly1DFromWeight.hh:43
virtual ClassicalOrthoPoly1DFromWeight * clone() const
Definition: ClassicalOrthoPoly1DFromWeight.hh:56
virtual double xmin() const
Definition: ClassicalOrthoPoly1DFromWeight.hh:61
virtual unsigned maxDegree() const
Definition: ClassicalOrthoPoly1DFromWeight.hh:63
virtual long double weight(const long double x) const
Definition: ClassicalOrthoPoly1DFromWeight.hh:59
Definition: AbsArrayProjector.hh:14
OrthoPolyMethod
Definition: OrthoPolyMethod.hh:20
Definition: Recurrence.hh:22