Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi! The safe constructors of several distributions accept an infinite parameter (a few accept NaN too), and the distribution they build then returns
NaN, is0everywhere, or never terminates. With this change they returnNothingorLeftfor those inputs.exponentialE (1/0)densityat1isNaNgammaDistrE (1/0) 1,studentTE (1/0),weibullDistrErr (1/0) 1densityat1isNaNnegativeBinomialE (1/0) 0.5probabilityat1isNaN, andcumulativenever terminatespoissonE (1/0)logProbabilityat1isNaNbetaDistrE (1/0) 1densityat0.5isNaN, andcumulativeat0.5never terminatesfDistributionRealE (1/0) 5cumulativenever terminatesnormalDistrE (1/0) 1densityat1is0.0, andmeanisInfinitycauchyDistributionE (1/0) 1,laplaceE (1/0) 1densityat1is0.0uniformDistrE (-1/0) 0cumulativeat0.5isNaNnormalDistrE (0/0) 1,weibullDistrErr (0/0) 1densityat1isNaNlognormalDistrErr 400 11. Infinite parameters
These constructors now check
x > 0 && x < 1/0for each parameter (x >= 0for the improper gamma and beta, and forpoissonE).An infinite location or scale gives a distribution with density
0everywhere, and so does an infinite scale in each of the normal, Cauchy and Laplace constructors. The location is now checked withabs m < 1/0and the scale withs < 1/0.uniformDistrE a breturnsNothingwhenabs a >= 1/0 || abs b >= 1/0, before it orders the two bounds.2. NaN parameters
NaN got through for a different reason. The normal, Cauchy and Laplace constructors only checked the scale and never looked at the location (Cauchy and Laplace accepted
(0/0) 1too). ForweibullDistrErr (0/0) 1, the guards werek <= 0andl <= 0, andNaN <= 0isFalse, so the NaN passes them (the same happens withweibullDistrErr 1 (0/0)). The guards are now in the positive form above, which a NaN fails.3. Lognormal with a large mean
The check was
and for
muabove about354.9(log m_huge / 2) that bound isNaN, so the comparison isFalsefor everysigmaand the check passes. It's nowwhich
NaNfails, together withabs mu < 1/0:lognormalDistrErr 354 1is accepted andlognormalDistrErr 355 1is rejected.lognormalDistrErr (1/0) 1was accepted for the same reason.The JSON string
{"mean":400,"stdDev":1}also decoded to a lognormal distribution, becauseFromJSON LognormalDistributionwas derived and never calledlognormalDistrErr. It's now an explicit instance that reads the same two fields,meanandstdDev, throughlognormalDistrErr.The
ReadandBinarydecoders of the lognormal distribution (read "lognormalDistr 400.0 1.0"returned a distribution, and so did decoding theBinaryencoding of(400, 1)), and those of the other changed distributions, go through the checked constructors, so they reject these values too, and so do the unsafe wrappers such asnormalDistr.4. Smaller changes
studentTE (1/0)is rejected now too, although the t distribution tends to the standard normal as the degrees of freedom grow: the module has no value for that limit, sincelogDensityUnscaledevaluateslogBetaandlog1pat infinity and givesNaN. The CauchyBinarydecoder now callsfailwhere it callederror, andfromSamplefor the exponential and Laplace distributions goes throughexponentialEandlaplaceE.Tests
Each wrong value above has a new test, which fails on master (with GHC 9.6.7) and passes with these commits. I ran
statistics-testson GHC 9.6.7, 9.12.4 and 9.14.1, and all 514 tests pass (the 451 already on master and the 63 new ones).The last commit adds an
## Unreleasedsection at the top ofchangelog.md, with one entry per fix.