/* ----------------------------------------------------------------------- *//** * * @file kolmogorov.hpp * *//* ----------------------------------------------------------------------- */ /** * @brief Kolmogorov cumulative distribution function */ DECLARE_UDF(prob, kolmogorov_cdf) #ifndef MADLIB_MODULES_PROB_KOLMOGOROV_HPP #define MADLIB_MODULES_PROB_KOLMOGOROV_HPP #include #include #include namespace madlib { namespace modules { namespace prob { double KolmogorovProb(double); template < class RealType = double, class Policy = boost::math::policies::policy<> > class kolmogorov_distribution { public: typedef RealType value_type; typedef Policy policy_type; kolmogorov_distribution() { } }; typedef kolmogorov_distribution kolmogorov; /** * @brief Range of permissible values for random variable x. */ template inline const std::pair range(const kolmogorov_distribution& /*dist*/) { return std::pair( static_cast(0), static_cast(1)); } /** * @brief Range of supported values for random variable x. * * This is range where cdf rises from 0 to 1, and outside it, the pdf is zero. */ template inline const std::pair support(const kolmogorov_distribution& /*dist*/) { return std::pair( static_cast(0), static_cast(1)); } template inline RealType cdf(const kolmogorov_distribution&, const RealType& x) { static const char* function = "madlib::modules::prob::cdf(" "const kolmogorov_distribution<%1%>&, %1%)"; RealType result; if ((boost::math::isinf)(x)) { if(x < 0) return 0; // -infinity else return 1; // + infinity } if (boost::math::detail::check_x(function, x, &result, Policy()) == false) return result; // FIXME: Numerically questionable if t is close to 1. return 1. - KolmogorovProb(x); } template inline RealType cdf( const boost::math::complemented2_type< kolmogorov_distribution, RealType >& c ) { static const char* function = "madlib::modules::prob::cdf(" "const complement(kolmogorov_distribution<%1%>&), %1%)"; RealType result; const RealType& x = c.param; if ((boost::math::isinf)(x)) { if(x < 0) return 1; // cdf complement -infinity is unity. return 0; // cdf complement +infinity is zero } if (boost::math::detail::check_x(function, x, &result, Policy()) == false) return result; return KolmogorovProb(x); } } // namespace prob } // namespace modules } // namespace madlib #endif // defined(MADLIB_MODULES_PROB_KOLMOGOROV_HPP)