boostorg/math

CDF and PMF of binomial function not same with extreme values

Closed this issue · 4 comments

This may not be us:

#include <boost/math/distributions.hpp>
#include <vector>
#include <iostream>

int main() 
{
   double n = 25.0e21;
   double p = 1.0e-21;
   double r = 0;

   boost::math::binomial_distribution<double> d(n, p);

   std::cout << pdf(d, r) << std::endl;
   std::cout << cdf(d, r) << std::endl;

   return 0;
}

Outputs:

1.38879e-11
1.38879e-11

Or have I misread the OP?

I don't think this is us now that you confirmed. I got the same results with the following.

#include <boost/math/distributions/binomial.hpp>
#include "math_unit_test.hpp"

// See: https://github.com/scipy/scipy/issues/17809

int main()
{
    constexpr double n {25.0e21};
    constexpr double p {1.0e-21};
    constexpr double r {0};

    // In R the PDF and CDF are both 1.388794386496407e-11
    // In boost 1.81 CDF was 1.388794386496407e-11 but PDF was 1.0

    const auto binom_dist = boost::math::binomial_distribution<double>(n, p);

    CHECK_ULP_CLOSE(1.388794386496407e-11, boost::math::cdf(binom_dist, r), 1);
    CHECK_ULP_CLOSE(1.388794386496407e-11, boost::math::pdf(binom_dist, r), 1);

    return boost::math::test::report_errors();
}

I ran this against master too, and we still get the correct results.

Confirmed this fails using 1.80 but was fixed in 1.81. Scipy will update their packaged version of Boost.Math for next release.