Index: trunk/npstat/stat/make_UnbinnedGOFTest1D.cc =================================================================== --- trunk/npstat/stat/make_UnbinnedGOFTest1D.cc (revision 880) +++ trunk/npstat/stat/make_UnbinnedGOFTest1D.cc (revision 881) @@ -1,136 +1,135 @@ #include #include #include "npstat/nm/ClassicalOrthoPolys1D.hh" #include "npstat/nm/ScalableClassicalOrthoPoly1D.hh" #include "npstat/stat/Distributions1D.hh" #include "npstat/stat/DensityOrthoPoly1D.hh" #include "npstat/stat/UnbinnedGOFTest1DFactory.hh" #include "npstat/stat/SmoothGOFTest1D.hh" #include "npstat/stat/SmoothCDGOFTest1D.hh" #include "npstat/stat/SineGOFTest1D.hh" #include "npstat/stat/make_UnbinnedGOFTest1D.hh" template static void printMapKeys(const Map& m, std::ostream& os) { unsigned cnt = 0; const typename Map::const_iterator end = m.end(); for (typename Map::const_iterator it = m.begin(); it != end; ++it, ++cnt) { if (cnt) os << ", "; os << '"' << it->first << '"'; } } namespace npstat { CPP11_auto_ptr make_UnbinnedGOFTest1D( const std::string& classname, const AbsDistribution1D& nullD, const unsigned maxDegree, const std::vector& degreeMask) { const unsigned dMaskSz = degreeMask.size(); if (classname == "SmoothGOFTest1D") { const Gauss1D* g_d = dynamic_cast(&nullD); if (g_d) { HermiteProbOrthoPoly1D gaussPoly; ScalableClassicalOrthoPoly1D scaledPoly(gaussPoly, g_d->location(), g_d->scale()); return CPP11_auto_ptr( new SmoothGOFTest1D( nullD, scaledPoly, maxDegree, dMaskSz ? °reeMask[0] : (unsigned char*)0, dMaskSz)); } const Beta1D* beta_d = dynamic_cast(&nullD); if (beta_d) { JacobiOrthoPoly1D jac(beta_d->beta()-1, beta_d->alpha()-1); const double s = beta_d->scale()/2.0; ScalableClassicalOrthoPoly1D scaledPoly(jac, beta_d->location() + s, s); return CPP11_auto_ptr( new SmoothGOFTest1D( nullD, scaledPoly, maxDegree, dMaskSz ? °reeMask[0] : (unsigned char*)0, dMaskSz)); } const SymmetricBeta1D* sb_d = dynamic_cast(&nullD); if (sb_d) { const double p = sb_d->power(); JacobiOrthoPoly1D jac(p, p); ScalableClassicalOrthoPoly1D scaledPoly(jac, sb_d->location(), sb_d->scale()); return CPP11_auto_ptr( new SmoothGOFTest1D( nullD, scaledPoly, maxDegree, dMaskSz ? °reeMask[0] : (unsigned char*)0, dMaskSz)); } const Uniform1D* u_d = dynamic_cast(&nullD); if (u_d) { ShiftedLegendreOrthoPoly1D shL; ScalableClassicalOrthoPoly1D scaledPoly(shL, u_d->location(), u_d->scale()); return CPP11_auto_ptr( new SmoothGOFTest1D( nullD, scaledPoly, maxDegree, dMaskSz ? °reeMask[0] : (unsigned char*)0, dMaskSz)); } const double unbounded = 1.0e10; if (nullD.quantile(0.0) < -unbounded || nullD.quantile(1.0) > unbounded) { throw std::invalid_argument("In npstat::make_UnbinnedGOFTest1D: " "the SmoothGOFTest1D GoF test is not implemented " "for densities with unbounded support"); return CPP11_auto_ptr(); } // A somewhat arbitrary choice const unsigned nIntegPoints = 2*maxDegree + 1 + 1024; DensityOrthoPoly1D poly(nullD, maxDegree, nIntegPoints); return CPP11_auto_ptr( new SmoothGOFTest1D( nullD, poly, maxDegree, dMaskSz ? °reeMask[0] : (unsigned char*)0, dMaskSz)); } else if (classname == "SineGOFTest1D") { return CPP11_auto_ptr( new SineGOFTest1D(nullD, maxDegree, dMaskSz ? °reeMask[0] : (unsigned char*)0, dMaskSz)); } else if (classname == "SmoothCDGOFTest1D") { return CPP11_auto_ptr( new SmoothCDGOFTest1D(nullD, maxDegree, dMaskSz ? °reeMask[0] : (unsigned char*)0, dMaskSz)); } else { DefaultUnbinnedGOFTest1DFactory defaultFactory; if (defaultFactory.contains(classname)) return CPP11_auto_ptr( defaultFactory[classname]->create(nullD)); else { std::ostringstream os; os << "In npstat::make_UnbinnedGOFTest1D: " << "invalid 1-d GoF test class name \"" << classname << "\". Valid 1-d GoF test class names are: "; printMapKeys(defaultFactory, os); os << ", \"SmoothGOFTest1D\"" << ", \"SmoothCDGOFTest1D\"" - << ", \"CosineGOFTest1D\"" << ", and \"SineGOFTest1D\"."; throw std::invalid_argument(os.str()); return CPP11_auto_ptr(); } } } }