For rather exotic instances of a MixtureModel the quantile() method fails. The underlying reason is that the initial bisection interval (in quantile_bisect()) does not contain the solution. However, both ends of the interval are very close to the solution. The current implementation of quantile_bisect() checks for equality of the start and end of the interval. Changing this to approximately equal would fix this bug.
Example
using Distributions
d = MixtureModel([Normal(0, 1), Normal(eps(), 1)], [0.999, 0.001])
quantile(d, 0.001)
The problem
For rather exotic instances of a
MixtureModel
thequantile()
method fails. The underlying reason is that the initial bisection interval (inquantile_bisect()
) does not contain the solution. However, both ends of the interval are very close to the solution. The current implementation ofquantile_bisect()
checks for equality of the start and end of the interval. Changing this to approximately equal would fix this bug.Example
gives as output
I'm currently using
and Distributions v0.25.109.
The solution(?)
Changing line 8 of quantilealgs.jl https://github.com/JuliaStats/Distributions.jl/blob/b356da03a189d023cdb8467c61806a8a11dcb262/src/quantilealgs.jl#L8 to
if rx ≈ lx
seems to do the trick. I'm not sure whether this has bad side effects. However, after this change all tests in Distributions.jl still succeed.An appropriate new test case to catch this bug would be
I can submit this as a pull request if desired (would need to figure out how to do that).