test_new_distributions.py 874 B

1234567891011121314151617
  1. # file for distribution-specific tests with new infrastructure (UnivariateDistribution)
  2. import numpy as np
  3. from numpy.testing import assert_allclose
  4. from scipy import stats
  5. class TestBinomial:
  6. def test_gh23708_binomial_logcdf_method_complement(self):
  7. # gh-23708 found that `logcdf` method='complement' was inaccurate in the tails
  8. x = np.asarray([0., 18.])
  9. X = stats.Binomial(n=np.asarray([18.]), p=np.asarray(0.71022842))
  10. assert_allclose(X.logcdf(x, method='complement'), X.logcdf(x), rtol=1e-15)
  11. assert_allclose(X.logccdf(x, method='complement'), X.logccdf(x), rtol=1e-15)
  12. # going even deeper into the tails
  13. X = stats.Binomial(n=100, p=0.5)
  14. assert_allclose(X.logcdf(0, method='complement'), X.logpmf(0), rtol=1e-15)
  15. assert_allclose(X.logccdf(99, method='complement'), X.logpmf(100), rtol=1e-15)