Index: trunk/npstat/stat/AbsUnbinnedGOFTest1D.cc =================================================================== --- trunk/npstat/stat/AbsUnbinnedGOFTest1D.cc (revision 763) +++ trunk/npstat/stat/AbsUnbinnedGOFTest1D.cc (revision 764) @@ -1,57 +1,58 @@ #include #include "npstat/nm/findRootUsingBisections.hh" #include "npstat/stat/AbsUnbinnedGOFTest1D.hh" namespace npstat { - void AbsUnbinnedGOFTest1D::simulateStatistic( + void AbsUnbinnedGOFTest1D::simulateAltStatistic( + const AbsDistribution1D& alternative, AbsRandomGenerator& g, const unsigned long sz, const unsigned nPseudo, std::vector* stats) const { if (!sz) throw std::invalid_argument( - "In npstat::AbsUnbinnedGOFTest1D::simulateStatistic: " + "In npstat::AbsUnbinnedGOFTest1D::simulateAltStatistic: " "sample size must be positive"); if (nPseudo < 2U) std::invalid_argument( - "In npstat::AbsUnbinnedGOFTest1D::simulateStatistic: " - "insufficient number od pseudo experiments"); + "In npstat::AbsUnbinnedGOFTest1D::simulateAltStatistic: " + "insufficient number of 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); + alternative.random(g, sample+i); std::sort(sampleVec.begin(), sampleVec.end()); stats->push_back(this->testStatistic(sample, sz, true)); } std::sort(stats->begin(), stats->end()); } double AbsUnbinnedGOFTest1D::inverseExceedance( const double pvalue, const unsigned long sz, const double smin, const double smax) const { static const double tol = 1.0e-14; if (!hasAnalyticPValue()) throw std::runtime_error( "In npstat::AbsUnbinnedGOFTest1D::inverseExceedance: " "analytic p-value calculation is not implemented by " "the derived class"); if (pvalue <= 0.0 || pvalue >= 1.0) throw std::invalid_argument( "In npstat::AbsUnbinnedGOFTest1D::inverseExceedance: " "p-value argument must be inside (0, 1) interval"); double q = 0.0; if (!findRootUsingBisections( GOFTest1DPVFunctor(*this, sz), pvalue, smin, smax, tol, &q)) throw std::invalid_argument( "In npstat::AbsUnbinnedGOFTest1D::inverseExceedance: " "the initial interval does not bracket the root"); return q; } } Index: trunk/npstat/stat/AbsUnbinnedGOFTest1D.hh =================================================================== --- trunk/npstat/stat/AbsUnbinnedGOFTest1D.hh (revision 763) +++ trunk/npstat/stat/AbsUnbinnedGOFTest1D.hh (revision 764) @@ -1,105 +1,105 @@ #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 #include "npstat/nm/SimpleFunctors.hh" #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_;} inline const AbsDistribution1D& getNull() const {return *distro_;} virtual std::string shortName() 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;} /** This is the inverse function to "analyticPValue" */ virtual double inverseExceedance(double pvalue, unsigned long sz, double smin, double smax) const; // The following method should sort the statistic values // in the increasing order - virtual void simulateStatistic( + inline virtual void simulateStatistic( + AbsRandomGenerator& g, unsigned long sz, + unsigned nPseudo, std::vector* stats) const + { + simulateAltStatistic(*distro_, g, sz, nPseudo, stats); + } + + virtual void simulateAltStatistic( + const AbsDistribution1D& alternative, AbsRandomGenerator& g, unsigned long sz, unsigned nPseudo, std::vector* stats) const; protected: AbsDistribution1D* distro_; - - private: - inline void copyNull(const AbsDistribution1D& newNull) - { - delete distro_; - distro_ = 0; - distro_ = newNull.clone(); - } }; class GOFTest1DPVFunctor : public Functor1 { public: inline GOFTest1DPVFunctor(const AbsUnbinnedGOFTest1D& goftest, const unsigned long sz) : goftest_(goftest), sz_(sz) {} inline virtual ~GOFTest1DPVFunctor() {} inline virtual double operator()(const double& a) const {return goftest_.analyticPValue(a, sz_);} private: const AbsUnbinnedGOFTest1D& goftest_; unsigned long sz_; }; } #endif // NPSTAT_ABSUNBINNEDGOFTEST1D_HH_