npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
SmoothGOFTest1D.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_SMOOTHGOFTEST1D_HH_
2 #define NPSTAT_SMOOTHGOFTEST1D_HH_
3 
4 /*!
5 // \file SmoothGOFTest1D.hh
6 //
7 // \brief Smooth test for goodness-of-fit
8 //
9 // Author: I. Volobouev
10 //
11 // November 2020
12 */
13 
15 
16 namespace npstat {
17  // "Poly" template parameter is expected either to be
18  // ScalableClassicalOrthoPoly1D or to derive from (or
19  // to be) AbsClassicalOrthoPoly1D.
20  template<class Poly>
22  {
23  public:
24  typedef Poly poly_type;
25 
26  // The polynomials provided in the constructor must be
27  // orthonormal with the weight given by "distro.density(x)".
28  //
29  // The mask, if provided, should contain "maxdeg" elements.
30  // Put some number in the mask in order to discard the
31  // corresponding eigenvector and put 0 there to keep it.
32  // mask[0] specifies whether to use polynomial of degree 1, etc.
33  //
34  inline SmoothGOFTest1D(const AbsDistribution1D& distro,
35  const Poly& poly,
36  const unsigned maxdeg,
37  const unsigned char* mask=0,
38  const unsigned lenMask=0)
39  : AbsSmoothGOFTest1D(distro, maxdeg, mask, lenMask),
40  poly_(poly.clone()), aveBuf_(maxdeg+1U) {}
41 
42  inline SmoothGOFTest1D(const AbsDistribution1D& distro,
43  const Poly& poly,
44  const std::vector<int>& mask)
45  : AbsSmoothGOFTest1D(distro, mask),
46  poly_(poly.clone()), aveBuf_(mask.size()+1U) {}
47 
48  inline SmoothGOFTest1D(const SmoothGOFTest1D& r)
49  : AbsSmoothGOFTest1D(r),
50  poly_(r.poly_->clone()), aveBuf_(r.aveBuf_) {}
51 
52  inline SmoothGOFTest1D& operator=(const SmoothGOFTest1D& r)
53  {
54  if (&r != this)
55  {
56  AbsSmoothGOFTest1D::operator=(r);
57  aveBuf_ = r.aveBuf_;
58  delete poly_; poly_ = 0;
59  poly_ = r.poly_->clone();
60  }
61  return *this;
62  }
63 
64  inline virtual ~SmoothGOFTest1D() {delete poly_;}
65 
66  inline virtual std::string shortName() const
67  {return testNameWithMask("S");}
68 
69  virtual unsigned normalizedDeviations(
70  const double* data, unsigned long sz,
71  bool isDataSorted,
72  double* deviations, unsigned lenDeviations) const;
73 
74  virtual unsigned normalizedDeviations(
75  const float* data, unsigned long sz,
76  bool isDataSorted,
77  double* deviations, unsigned lenDeviations) const;
78 
79  private:
80  template<typename Numeric>
81  unsigned normalizedDeviationsHelper(
82  const Numeric* data, unsigned long lenData,
83  double* deviations) const;
84 
85  Poly* poly_;
86  mutable std::vector<double> aveBuf_;
87  };
88 }
89 
90 #include "npstat/stat/SmoothGOFTest1D.icc"
91 
92 #endif // NPSTAT_SMOOTHGOFTEST1D_HH_
Base class for smooth tests for goodness-of-fit.
Definition: AbsSmoothGOFTest1D.hh:20
Definition: SmoothGOFTest1D.hh:22
virtual unsigned normalizedDeviations(const double *data, unsigned long sz, bool isDataSorted, double *deviations, unsigned lenDeviations) const
Definition: AbsArrayProjector.hh:14
Definition: AbsDistribution1D.hh:31