@@ -49,31 +49,31 @@ quantile_bisect(d::ContinuousUnivariateDistribution, p::Real) =
49
49
# Distribution, with Application to the Inverse Gaussian Distribution
50
50
# http://www.statsci.org/smyth/pubs/qinvgaussPreprint.pdf
51
51
52
- function newton_impl (Δ, xs:: T = mode (d), tol :: Real = 1e-12 ) where {T}
52
+ function newton_impl (Δ, xs:: T = mode (d), xrtol :: Real = 1e-12 ) where {T}
53
53
x = xs - Δ (xs)
54
54
@assert typeof (x) === T
55
55
x0 = T (xs)
56
- while ! isapprox (x, x0, atol= 0 , rtol= tol )
56
+ while ! isapprox (x, x0, atol= 0 , rtol= xrtol )
57
57
x0 = x
58
58
x = x0 - Δ (x0)
59
59
end
60
60
return x
61
61
end
62
62
63
- function newton ((f,df), xs:: T = mode (d), tol :: Real = 1e-12 ) where {T}
63
+ function newton ((f,df), xs:: T = mode (d), xrtol :: Real = 1e-12 ) where {T}
64
64
Δ (x) = f (x)/ df (x)
65
- return newton_impl (Δ, xs, tol )
65
+ return newton_impl (Δ, xs, xrtol )
66
66
end
67
67
68
- function quantile_newton (d:: ContinuousUnivariateDistribution , p:: Real , xs:: Real = mode (d), tol :: Real = 1e-12 )
68
+ function quantile_newton (d:: ContinuousUnivariateDistribution , p:: Real , xs:: Real = mode (d), xrtol :: Real = 1e-12 )
69
69
f (x) = cdf (d, x) - p
70
70
df (x) = pdf (d, x)
71
71
# FIXME : can this be expressed via `promote_type()`? Test coverage missing.
72
72
Δ (x) = f (x)/ df (x)
73
73
x = xs - Δ (xs)
74
74
T = typeof (x)
75
75
if 0 < p < 1
76
- return newton ((f, df), T (xs), tol )
76
+ return newton ((f, df), T (xs), xrtol )
77
77
elseif p == 0
78
78
return T (minimum (d))
79
79
elseif p == 1
@@ -83,15 +83,15 @@ function quantile_newton(d::ContinuousUnivariateDistribution, p::Real, xs::Real=
83
83
end
84
84
end
85
85
86
- function cquantile_newton (d:: ContinuousUnivariateDistribution , p:: Real , xs:: Real = mode (d), tol :: Real = 1e-12 )
86
+ function cquantile_newton (d:: ContinuousUnivariateDistribution , p:: Real , xs:: Real = mode (d), xrtol :: Real = 1e-12 )
87
87
f (x) = p - ccdf (d, x)
88
88
df (x) = pdf (d, x)
89
89
# FIXME : can this be expressed via `promote_type()`? Test coverage missing.
90
90
Δ (x) = f (x)/ df (x)
91
91
x = xs - Δ (xs)
92
92
T = typeof (x)
93
93
if 0 < p < 1
94
- return newton ((f, df), T (xs), tol )
94
+ return newton ((f, df), T (xs), xrtol )
95
95
elseif p == 1
96
96
return T (minimum (d))
97
97
elseif p == 0
@@ -101,16 +101,16 @@ function cquantile_newton(d::ContinuousUnivariateDistribution, p::Real, xs::Real
101
101
end
102
102
end
103
103
104
- function invlogcdf_newton (d:: ContinuousUnivariateDistribution , lp:: Real , xs:: Real = mode (d), tol :: Real = 1e-12 )
104
+ function invlogcdf_newton (d:: ContinuousUnivariateDistribution , lp:: Real , xs:: Real = mode (d), xrtol :: Real = 1e-12 )
105
105
T = typeof (lp - logpdf (d,xs))
106
106
Δ_ver0 (x) = exp (lp - logpdf (d,x) + logexpm1 (max (logcdf (d,x)- lp,0 )))
107
107
Δ_ver1 (x) = - exp (lp - logpdf (d,x) + log1mexp (min (logcdf (d,x)- lp,0 )))
108
108
if - Inf < lp < 0
109
109
x0 = T (xs)
110
110
if lp < logcdf (d,x0)
111
- return newton_impl (Δ_ver0, T (xs), tol )
111
+ return newton_impl (Δ_ver0, T (xs), xrtol )
112
112
else
113
- return newton_impl (Δ_ver1, T (xs), tol )
113
+ return newton_impl (Δ_ver1, T (xs), xrtol )
114
114
end
115
115
return x
116
116
elseif lp == - Inf
@@ -122,16 +122,16 @@ function invlogcdf_newton(d::ContinuousUnivariateDistribution, lp::Real, xs::Rea
122
122
end
123
123
end
124
124
125
- function invlogccdf_newton (d:: ContinuousUnivariateDistribution , lp:: Real , xs:: Real = mode (d), tol :: Real = 1e-12 )
125
+ function invlogccdf_newton (d:: ContinuousUnivariateDistribution , lp:: Real , xs:: Real = mode (d), xrtol :: Real = 1e-12 )
126
126
T = typeof (lp - logpdf (d,xs))
127
127
Δ_ver0 (x) = - exp (lp - logpdf (d,x) + logexpm1 (max (logccdf (d,x)- lp,0 )))
128
128
Δ_ver1 (x) = exp (lp - logpdf (d,x) + log1mexp (min (logccdf (d,x)- lp,0 )))
129
129
if - Inf < lp < 0
130
130
x0 = T (xs)
131
131
if lp < logccdf (d,x0)
132
- return newton_impl (Δ_ver0, T (xs), tol )
132
+ return newton_impl (Δ_ver0, T (xs), xrtol )
133
133
else
134
- return newton_impl (Δ_ver1, T (xs), tol )
134
+ return newton_impl (Δ_ver1, T (xs), xrtol )
135
135
end
136
136
return x
137
137
elseif lp == - Inf
0 commit comments