Index: trunk/npstat/stat/AbsUnbinnedGOFTest1D.hh =================================================================== --- trunk/npstat/stat/AbsUnbinnedGOFTest1D.hh (revision 736) +++ trunk/npstat/stat/AbsUnbinnedGOFTest1D.hh (revision 737) @@ -1,54 +1,69 @@ #ifndef NPSTAT_ABSUNBINNEDGOFTEST1D_HH_ #define NPSTAT_ABSUNBINNEDGOFTEST1D_HH_ +/*! +// \file AbsUnbinnedGOFTest1D.hh +// +// \brief Interface definition for goodness-of-fit tests for 1-d distributions +// +// Author: I. Volobouev +// +// November 2020 +*/ + #include #include #include "npstat/rng/AbsRandomGenerator.hh" #include "npstat/stat/AbsDistribution1D.hh" namespace npstat { class AbsUnbinnedGOFTest1D { public: inline explicit AbsUnbinnedGOFTest1D(const AbsDistribution1D& d) : distro_(d.clone()) {} inline AbsUnbinnedGOFTest1D(const AbsUnbinnedGOFTest1D& r) : distro_(r.distro_->clone()) {} inline AbsUnbinnedGOFTest1D& operator=(const AbsUnbinnedGOFTest1D& r) { if (this != &r) { delete distro_; distro_ = 0; distro_ = r.distro_->clone(); } return *this; } inline virtual ~AbsUnbinnedGOFTest1D() {delete distro_;} - virtual double testStatistic(const double* data, unsigned long sz) const=0; - virtual double testStatistic(const float* data, unsigned long sz) const=0; + virtual double testStatistic( + const double* data, unsigned long sz, bool isDataSorted) const=0; + + virtual double testStatistic( + const float* data, unsigned long sz, bool isDataSorted) const=0; inline virtual double analyticPValue( double /* stat */, unsigned long /* sz */) const { throw std::runtime_error( "In npstat::AbsUnbinnedGOFTest1D::analyticPValue: " "this function is not implemented by the derived class"); } inline virtual bool hasAnalyticPValue() const {return false;} + // The following method should sort the statistics values + // in the increasing order virtual void simulateStatistic( AbsRandomGenerator& g, unsigned long sz, unsigned nPseudo, std::vector* stats) const; protected: AbsDistribution1D* distro_; }; } #endif // NPSTAT_ABSUNBINNEDGOFTEST1D_HH_ Index: trunk/npstat/stat/OrthoPolyGOFTest1D.hh =================================================================== --- trunk/npstat/stat/OrthoPolyGOFTest1D.hh (revision 736) +++ trunk/npstat/stat/OrthoPolyGOFTest1D.hh (revision 737) @@ -1,78 +1,78 @@ #ifndef NPSTAT_ORTHOPOLYGOFTEST1D_HH_ #define NPSTAT_ORTHOPOLYGOFTEST1D_HH_ /*! // \file OrthoPolyGOFTest1D.hh // // \brief Orthogonal polynomial goodness-of-fit test // // Author: I. Volobouev // // November 2020 */ #include #include "npstat/nm/Matrix.hh" #include "npstat/nm/AbsClassicalOrthoPoly1D.hh" #include "npstat/stat/AbsUnbinnedGOFTest1D.hh" namespace npstat { class OrthoPolyGOFTest1D : public AbsUnbinnedGOFTest1D { public: template OrthoPolyGOFTest1D(const AbsDistribution1D& distro, const Quadrature& q, const AbsClassicalOrthoPoly1D& poly, unsigned maxdeg); inline virtual ~OrthoPolyGOFTest1D() {} inline unsigned maxDegree() const {return maxdeg_;} inline unsigned numDeviations() const {return 2U*maxdeg_;} /** // Get the value of the test statistic with all // terms weighted equally */ inline virtual double testStatistic( - const double* data, const unsigned long sz) const + const double* data, const unsigned long sz, bool) const {return testStat(data, sz);} inline virtual double testStatistic( - const float* data, const unsigned long sz) const + const float* data, const unsigned long sz, bool) const {return testStat(data, sz);} - + inline virtual bool hasAnalyticPValue() const {return true;} virtual double analyticPValue(double stat, unsigned long sz) const; /** // Get individual normalized deviations from which // the test statistic is constructed */ template void normalizedDeviations( const Numeric* data, unsigned long lenData, double* deviations, unsigned lenDeviations) const; private: template void calculateNormalizingMatrix(const Quadrature& q, Matrix* m) const; template double testStat(const Numeric* data, unsigned long lenData) const; std::shared_ptr poly_; Matrix invsqr_; std::vector buf_; std::vector statBuf_; unsigned maxdeg_; }; } #include "npstat/stat/OrthoPolyGOFTest1D.icc" #endif // NPSTAT_ORTHOPOLYGOFTEST1D_HH_ Index: trunk/npstat/stat/AbsUnbinnedGOFTest1D.cc =================================================================== --- trunk/npstat/stat/AbsUnbinnedGOFTest1D.cc (revision 736) +++ trunk/npstat/stat/AbsUnbinnedGOFTest1D.cc (revision 737) @@ -1,30 +1,30 @@ #include #include "npstat/stat/AbsUnbinnedGOFTest1D.hh" namespace npstat { void AbsUnbinnedGOFTest1D::simulateStatistic( AbsRandomGenerator& g, const unsigned long sz, const unsigned nPseudo, std::vector* stats) const { if (!sz) throw std::invalid_argument( "In npstat::AbsUnbinnedGOFTest1D::simulateStatistic: " "sample size must be positive"); if (nPseudo < 2U) std::invalid_argument( "In npstat::AbsUnbinnedGOFTest1D::simulateStatistic: " "insufficient number od pseudo experiments"); assert(stats); stats->clear(); stats->reserve(nPseudo); std::vector sampleVec(sz); double* sample = &sampleVec[0]; for (unsigned ips=0; ipsrandom(g, sample+i); - stats->push_back(this->testStatistic(sample, sz)); + stats->push_back(this->testStatistic(sample, sz, false)); } std::sort(stats->begin(), stats->end()); } }