npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
OrthoPolyGOFTest1D.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_ORTHOPOLYGOFTEST1D_HH_
2 #define NPSTAT_ORTHOPOLYGOFTEST1D_HH_
3 
4 /*!
5 // \file OrthoPolyGOFTest1D.hh
6 //
7 // \brief Orthogonal polynomial goodness-of-fit test
8 //
9 // Author: I. Volobouev
10 //
11 // November 2020
12 */
13 
14 #include <memory>
15 
16 #include "npstat/nm/Matrix.hh"
19 
21 
22 namespace npstat {
24  {
25  public:
26  typedef std::pair<double,UUPair> EigenInfo;
27 
28  // The mask, if provided, should contain 2*maxdeg elements.
29  // Put some number in the mask in order to discard the
30  // corresponding eigenvector and put 0 there to keep it.
31  template <class Quadrature>
33  const Quadrature& q,
34  const AbsClassicalOrthoPoly1D& poly,
35  unsigned maxdeg,
36  const unsigned char* mask=0, unsigned lenMask=0);
37 
38  inline virtual ~OrthoPolyGOFTest1D() {}
39 
40  virtual std::string shortName() const;
41 
42  inline unsigned maxDegree() const {return maxdeg_;}
43  inline unsigned numDeviations() const {return nUnmasked_;}
44  inline bool isEigenvectorUsed(const unsigned i) const
45  {return i >= 2U*maxdeg_ ? false : !mask_[i];}
46 
47  /**
48  // Get the uncertainty (i.e., the square root of the covariance
49  // matrix eigenvalue) associated with a particular eigenvector.
50  // This function ignores the mask. The return value is 0 if the
51  // eigenvector number is out of range.
52  */
53  double eigenUncertainty(unsigned i) const;
54 
55  /**
56  // Get the covariance matrix eigenvector with the given number. If
57  // the vector number is out of range, an exception will be thrown.
58  // Interpretation of these eigenvectors is for experts only. Make
59  // sure that you know what you are doing.
60  */
61  std::vector<double> covmatEigenvector(unsigned i) const;
62 
63  /**
64  // Collect the information about the given eigenvector.
65  // The first element in the "EigenInfo" pair is the
66  // eigenvector value and the second element is the
67  // pair of polynomials corresponding to that value.
68  // Components are included in the result only if the
69  // magnitude of the eigenvector value is above the threshold.
70  */
71  std::vector<EigenInfo> eigenComponents(
72  unsigned i, double threshold) const;
73 
74  /**
75  // Get the value of the test statistic with all unmasked
76  // terms weighted equally
77  */
78  inline virtual double testStatistic(
79  const double* data, const unsigned long sz, bool) const
80  {return testStat(data, sz);}
81 
82  inline virtual double testStatistic(
83  const float* data, const unsigned long sz, bool) const
84  {return testStat(data, sz);}
85 
86  inline virtual bool hasAnalyticPValue() const {return true;}
87 
88  virtual double analyticPValue(double stat, unsigned long sz) const;
89 
90  virtual double inverseExceedance(double pvalue, unsigned long sz,
91  double smin, double smax) const;
92 
93  /**
94  // Get individual normalized deviations from which
95  // the test statistic is constructed. Only unmasked
96  // deviations are returned. The return value of this
97  // function is the number of such deviations.
98  */
99  template<typename Numeric>
101  const Numeric* data, unsigned long lenData,
102  double* deviations, unsigned lenDeviations) const;
103 
104  private:
105  template <class Quadrature>
106  void calculateNormalizingMatrix(const Quadrature& q,
107  Matrix<lapack_double>* m) const;
108  template<typename Numeric>
109  double testStat(const Numeric* data, unsigned long lenData) const;
110 
111  std::shared_ptr<const AbsClassicalOrthoPoly1D> poly_;
112  Matrix<lapack_double> invsqr_;
113  std::vector<double> buf_;
114  std::vector<double> statBuf_;
115  std::vector<double> sqrBuf_;
116  std::vector<unsigned char> mask_;
117  unsigned maxdeg_;
118  unsigned nUnmasked_;
119  };
120 }
121 
122 #include "npstat/stat/OrthoPolyGOFTest1D.icc"
123 
124 #endif // NPSTAT_ORTHOPOLYGOFTEST1D_HH_
Base class for classical continuous orthonormal polynomials.
Interface definition for goodness-of-fit tests for 1-d distributions.
Template matrix class.
Definition: AbsClassicalOrthoPoly1D.hh:32
Definition: AbsUnbinnedGOFTest1D.hh:24
Definition: OrthoPolyGOFTest1D.hh:24
std::vector< EigenInfo > eigenComponents(unsigned i, double threshold) const
double eigenUncertainty(unsigned i) const
std::vector< double > covmatEigenvector(unsigned i) const
virtual double inverseExceedance(double pvalue, unsigned long sz, double smin, double smax) const
unsigned normalizedDeviations(const Numeric *data, unsigned long lenData, double *deviations, unsigned lenDeviations) const
virtual double testStatistic(const double *data, const unsigned long sz, bool) const
Definition: OrthoPolyGOFTest1D.hh:78
Utility for enumerating pairs on diagonals of symmetric matrices.
Definition: AbsArrayProjector.hh:14
Definition: AbsDistribution1D.hh:31