npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
ContOrthoPoly1DQ.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_CONTORTHOPOLY1DQ_HH_
2 #define NPSTAT_CONTORTHOPOLY1DQ_HH_
3 
4 /*!
5 // \file ContOrthoPoly1DQ.hh
6 //
7 // \brief Continuous orthogonal polynomial series in one dimension
8 // generated for a discrete measure, using quadruple precision
9 //
10 // Author: I. Volobouev
11 //
12 // July 2023
13 */
14 
15 #include <vector>
16 #include <utility>
17 
19 #include "npstat/nm/RecurrenceQ.hh"
20 #include "npstat/nm/Matrix.hh"
21 
22 namespace npstat {
24  {
25  public:
26  typedef std::pair<quad_float,quad_float> MeasurePoint;
27 
28  /**
29  // Main constructor, with obvious arguments. The first element
30  // of the measure pair is the coordinate and the second element
31  // is the weight (all weights must be non-negative). Internally,
32  // the measure will be sorted in the order of increasing weight
33  // and the measure coordinates will normally be shifted so that
34  // their weighted mean is at 0.
35  */
36  template<typename Numeric1, typename Numeric2>
38  const std::vector<std::pair<Numeric1,Numeric2> >& measure,
39  OrthoPolyMethod m = OPOLY_STIELTJES,
40  bool shiftMeasureCoords = true);
41 
42  /** Constructor which assumes that all weights are 1.0 */
43  template<typename Numeric>
45  const std::vector<Numeric>& coords,
46  OrthoPolyMethod m = OPOLY_STIELTJES,
47  bool shiftMeasureCoords = true);
48 
49  /** Constructor that uses the modified Chebyshev algorithm */
50  template<typename Numeric1, typename Numeric2, class OrthoPoly>
52  const std::vector<std::pair<Numeric1,Numeric2> >& measure,
53  const OrthoPoly& ops, bool shiftMeasureCoords = false);
54 
55  /**
56  // Constructor that uses the modified Chebyshev algorithm
57  // and assumes that all weights are 1.0
58  */
59  template<typename Numeric, class OrthoPoly>
61  const std::vector<Numeric>& coords,
62  const OrthoPoly& ops, bool shiftMeasureCoords = false);
63 
64  /**
65  // Function added for interface compatibility with
66  // AbsClassicalOrthoPoly1D
67  */
68  inline ContOrthoPoly1DQ* clone() const {return new ContOrthoPoly1DQ(*this);}
69 
70  //@{
71  /** A simple inspector of object properties */
72  inline unsigned maxDegree() const {return maxdeg_;}
73  inline bool areAllWeightsEqual() const {return allWeightsEqual_;}
74  inline quad_float measureShift() const {return shiftX_;}
75  inline quad_float meanCoordinate() const {return meanX_;}
76  inline quad_float location() const {return meanX_;}
77  inline quad_float scale() const {return 1.0;}
78  //@}
79 
80  /** Kish's effective sample size for the measure */
81  quad_float effectiveSampleSize() const;
82 
83  /** Return the value of one of the normalized polynomials */
84  quad_float poly(unsigned deg, quad_float x) const;
85 
86  /** Return the values of two of the normalized polynomials */
87  std::pair<quad_float,quad_float> polyPair(
88  unsigned deg1, unsigned deg2, quad_float x) const;
89 
90  /**
91  // Return the values of all orthonormal polynomials up to some
92  // maximum degree. Size of the "polyValues" array should be
93  // at least maxdeg + 1.
94  */
95  template <typename Numeric>
96  inline void allPolys(const quad_float x, const unsigned maxdeg,
97  Numeric* polyValues) const
98  {getAllPolys(x - shiftX_, maxdeg, polyValues);}
99 
100  /**
101  // Function added for interface compatibility with
102  // AbsClassicalOrthoPoly1D
103  */
104  inline void allpoly(const long double x, long double* values,
105  const unsigned maxdeg) const
106  {getAllPolys(x - shiftX_, maxdeg, values);}
107 
108  /**
109  // This method is useful for testing the numerical precision
110  // of the orthonormalization procedure. It returns the scalar
111  // products between various polynomials.
112  */
113  quad_float empiricalKroneckerDelta(unsigned deg1, unsigned deg2) const;
114 
115  /**
116  // A faster way to generate Kronecker deltas if the whole matrix
117  // of them is needed. The argument must not exceed the return
118  // value of the "maxDegree" function. The resulting matrix will
119  // be dimensioned (maxdeg + 1) x (maxdeg + 1).
120  */
122 
123  private:
124  template<typename Numeric1, typename Numeric2>
125  void copyMeasure(const std::vector<std::pair<Numeric1,Numeric2> >& inMeasure);
126 
127  template<typename Numeric>
128  void copyInputCoords(const std::vector<Numeric>& inCoords);
129 
130  void calcMeanXandWeightSums(bool shiftTheMeasure);
131 
132  template<class OrthoPoly>
133  quad_float sigma(const OrthoPoly& ops, int k, int l,
134  Matrix<quad_float>& sigMatrix,
135  Matrix<int>& flagMatrix) const;
136 
137  template<class OrthoPoly>
138  void calculateMonicAverages(const OrthoPoly& ops, quad_float* averages,
139  unsigned maxdeg);
140 
141  template<class OrthoPoly>
142  void calcRecurrenceModifiedChebyshev(const OrthoPoly& ops);
143 
144  quad_float normpoly(unsigned degree, quad_float x) const;
145 
146  std::pair<quad_float,quad_float> twonormpoly(
147  unsigned deg1, unsigned deg2, quad_float x) const;
148 
149  template <typename Numeric>
150  void getAllPolys(quad_float x, unsigned maxdeg, Numeric *polyValues) const;
151 
152  std::vector<MeasurePoint> measure_;
153  std::vector<Private::RecurrenceQ> rCoeffs_;
154  quad_float wsum_;
155  quad_float wsumsq_;
156  quad_float meanX_;
157  quad_float shiftX_;
158  quad_float minX_;
159  quad_float maxX_;
160  unsigned maxdeg_;
161  bool allWeightsEqual_;
162  };
163 }
164 
165 #include "npstat/nm/ContOrthoPoly1DQ.icc"
166 
167 #endif // NPSTAT_CONTORTHOPOLY1DQ_HH_
Template matrix class.
Enumeration of methods used to create orthogonal polynomials with discrete weights.
Definition: ContOrthoPoly1DQ.hh:24
void allPolys(const quad_float x, const unsigned maxdeg, Numeric *polyValues) const
Definition: ContOrthoPoly1DQ.hh:96
quad_float empiricalKroneckerDelta(unsigned deg1, unsigned deg2) const
void allpoly(const long double x, long double *values, const unsigned maxdeg) const
Definition: ContOrthoPoly1DQ.hh:104
quad_float effectiveSampleSize() const
ContOrthoPoly1DQ * clone() const
Definition: ContOrthoPoly1DQ.hh:68
std::pair< quad_float, quad_float > polyPair(unsigned deg1, unsigned deg2, quad_float x) const
ContOrthoPoly1DQ(unsigned maxDegree, const std::vector< Numeric > &coords, const OrthoPoly &ops, bool shiftMeasureCoords=false)
ContOrthoPoly1DQ(unsigned maxDegree, const std::vector< Numeric > &coords, OrthoPolyMethod m=OPOLY_STIELTJES, bool shiftMeasureCoords=true)
Matrix< quad_float > empiricalKroneckerMatrix(unsigned maxdeg) const
unsigned maxDegree() const
Definition: ContOrthoPoly1DQ.hh:72
ContOrthoPoly1DQ(unsigned maxDegree, const std::vector< std::pair< Numeric1, Numeric2 > > &measure, const OrthoPoly &ops, bool shiftMeasureCoords=false)
ContOrthoPoly1DQ(unsigned maxDegree, const std::vector< std::pair< Numeric1, Numeric2 > > &measure, OrthoPolyMethod m=OPOLY_STIELTJES, bool shiftMeasureCoords=true)
quad_float poly(unsigned deg, quad_float x) const
Definition: Matrix.hh:49
Definition: AbsArrayProjector.hh:14
OrthoPolyMethod
Definition: OrthoPolyMethod.hh:20