Skip to content

Commit 1f9b7a3

Browse files
committed
invlogcdf_newton()/invlogccdf_newton(): use strict inequality
This is what the `quantile_newton()`/`cquantile_newton()` does, because otherwise they were able to end up in an endless loops, when the initial point and the mode are the same, see #666. I'm not sure this is needed here, but the next change is going to refactor them to use general `newton()`, which would make this change anyway, so unless we need the current behaviour, let's do this change explicitly.
1 parent 330f8fa commit 1f9b7a3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/quantilealgs.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ function invlogcdf_newton(d::ContinuousUnivariateDistribution, lp::Real, xs::Rea
9696
x0 = T(xs)
9797
if lp < logcdf(d,x0)
9898
x = x0 - exp(lp - logpdf(d,x0) + logexpm1(max(logcdf(d,x0)-lp,0)))
99-
while abs(x-x0) >= max(abs(x),abs(x0)) * tol
99+
while abs(x-x0) > max(abs(x),abs(x0)) * tol
100100
x0 = x
101101
x = x0 - exp(lp - logpdf(d,x0) + logexpm1(max(logcdf(d,x0)-lp,0)))
102102
end
103103
else
104104
x = x0 + exp(lp - logpdf(d,x0) + log1mexp(min(logcdf(d,x0)-lp,0)))
105-
while abs(x-x0) >= max(abs(x),abs(x0))*tol
105+
while abs(x-x0) > max(abs(x),abs(x0))*tol
106106
x0 = x
107107
x = x0 + exp(lp - logpdf(d,x0) + log1mexp(min(logcdf(d,x0)-lp,0)))
108108
end
@@ -123,13 +123,13 @@ function invlogccdf_newton(d::ContinuousUnivariateDistribution, lp::Real, xs::Re
123123
x0 = T(xs)
124124
if lp < logccdf(d,x0)
125125
x = x0 + exp(lp - logpdf(d,x0) + logexpm1(max(logccdf(d,x0)-lp,0)))
126-
while abs(x-x0) >= max(abs(x),abs(x0)) * tol
126+
while abs(x-x0) > max(abs(x),abs(x0)) * tol
127127
x0 = x
128128
x = x0 + exp(lp - logpdf(d,x0) + logexpm1(max(logccdf(d,x0)-lp,0)))
129129
end
130130
else
131131
x = x0 - exp(lp - logpdf(d,x0) + log1mexp(min(logccdf(d,x0)-lp,0)))
132-
while abs(x-x0) >= max(abs(x),abs(x0)) * tol
132+
while abs(x-x0) > max(abs(x),abs(x0)) * tol
133133
x0 = x
134134
x = x0 - exp(lp - logpdf(d,x0) + log1mexp(min(logccdf(d,x0)-lp,0)))
135135
end

0 commit comments

Comments
 (0)