Skip to content

Commit 96786f0

Browse files
committed
Be more specific that tol is really a xrtol
1 parent cf55a37 commit 96786f0

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/quantilealgs.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,31 @@ quantile_bisect(d::ContinuousUnivariateDistribution, p::Real) =
4747
# Distribution, with Application to the Inverse Gaussian Distribution
4848
# http://www.statsci.org/smyth/pubs/qinvgaussPreprint.pdf
4949

50-
function newton_impl(Δ, xs::T=mode(d), tol::Real=1e-12) where {T}
50+
function newton_impl(Δ, xs::T=mode(d), xrtol::Real=1e-12) where {T}
5151
x = xs - Δ(xs)
5252
@assert typeof(x) === T
5353
x0 = T(xs)
54-
while !isapprox(x, x0, atol=0, rtol=tol)
54+
while !isapprox(x, x0, atol=0, rtol=xrtol)
5555
x0 = x
5656
x = x0 - Δ(x0)
5757
end
5858
return x
5959
end
6060

61-
function newton((f,df), xs::T=mode(d), tol::Real=1e-12) where {T}
61+
function newton((f,df), xs::T=mode(d), xrtol::Real=1e-12) where {T}
6262
Δ(x) = f(x)/df(x)
63-
return newton_impl(Δ, xs, tol)
63+
return newton_impl(Δ, xs, xrtol)
6464
end
6565

66-
function quantile_newton(d::ContinuousUnivariateDistribution, p::Real, xs::Real=mode(d), tol::Real=1e-12)
66+
function quantile_newton(d::ContinuousUnivariateDistribution, p::Real, xs::Real=mode(d), xrtol::Real=1e-12)
6767
f(x) = cdf(d, x) - p
6868
df(x) = pdf(d, x)
6969
# FIXME: can this be expressed via `promote_type()`? Test coverage missing.
7070
Δ(x) = f(x)/df(x)
7171
x = xs - Δ(xs)
7272
T = typeof(x)
7373
if 0 < p < 1
74-
return newton((f, df), T(xs), tol)
74+
return newton((f, df), T(xs), xrtol)
7575
elseif p == 0
7676
return T(minimum(d))
7777
elseif p == 1
@@ -81,15 +81,15 @@ function quantile_newton(d::ContinuousUnivariateDistribution, p::Real, xs::Real=
8181
end
8282
end
8383

84-
function cquantile_newton(d::ContinuousUnivariateDistribution, p::Real, xs::Real=mode(d), tol::Real=1e-12)
84+
function cquantile_newton(d::ContinuousUnivariateDistribution, p::Real, xs::Real=mode(d), xrtol::Real=1e-12)
8585
f(x) = p - ccdf(d, x)
8686
df(x) = pdf(d, x)
8787
# FIXME: can this be expressed via `promote_type()`? Test coverage missing.
8888
Δ(x) = f(x)/df(x)
8989
x = xs - Δ(xs)
9090
T = typeof(x)
9191
if 0 < p < 1
92-
return newton((f, df), T(xs), tol)
92+
return newton((f, df), T(xs), xrtol)
9393
elseif p == 1
9494
return T(minimum(d))
9595
elseif p == 0
@@ -99,17 +99,17 @@ function cquantile_newton(d::ContinuousUnivariateDistribution, p::Real, xs::Real
9999
end
100100
end
101101

102-
function invlogcdf_newton(d::ContinuousUnivariateDistribution, lp::Real, xs::Real=mode(d), tol::Real=1e-12)
102+
function invlogcdf_newton(d::ContinuousUnivariateDistribution, lp::Real, xs::Real=mode(d), xrtol::Real=1e-12)
103103
T = typeof(lp - logpdf(d,xs))
104104
f_ver0(x) = exp(lp - logpdf(d,x) + logexpm1(max(logcdf(d,x)-lp,0)))
105105
f_ver1(x) = -exp(lp - logpdf(d,x) + log1mexp(min(logcdf(d,x)-lp,0)))
106106
df(x::T) where {T} = T(1)
107107
if -Inf < lp < 0
108108
x0 = T(xs)
109109
if lp < logcdf(d,x0)
110-
return newton((f_ver0,df), T(xs), tol)
110+
return newton((f_ver0,df), T(xs), xrtol)
111111
else
112-
return newton((f_ver1,df), T(xs), tol)
112+
return newton((f_ver1,df), T(xs), xrtol)
113113
end
114114
return x
115115
elseif lp == -Inf
@@ -121,17 +121,17 @@ function invlogcdf_newton(d::ContinuousUnivariateDistribution, lp::Real, xs::Rea
121121
end
122122
end
123123

124-
function invlogccdf_newton(d::ContinuousUnivariateDistribution, lp::Real, xs::Real=mode(d), tol::Real=1e-12)
124+
function invlogccdf_newton(d::ContinuousUnivariateDistribution, lp::Real, xs::Real=mode(d), xrtol::Real=1e-12)
125125
T = typeof(lp - logpdf(d,xs))
126126
f_ver0(x) = -exp(lp - logpdf(d,x) + logexpm1(max(logccdf(d,x)-lp,0)))
127127
f_ver1(x) = exp(lp - logpdf(d,x) + log1mexp(min(logccdf(d,x)-lp,0)))
128128
df(x::T) where {T} = T(1)
129129
if -Inf < lp < 0
130130
x0 = T(xs)
131131
if lp < logccdf(d,x0)
132-
return newton((f_ver0,df), T(xs), tol)
132+
return newton((f_ver0,df), T(xs), xrtol)
133133
else
134-
return newton((f_ver1,df), T(xs), tol)
134+
return newton((f_ver1,df), T(xs), xrtol)
135135
end
136136
return x
137137
elseif lp == -Inf

0 commit comments

Comments
 (0)