-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Limit number of Newton iterations in beta_inc_inv #396
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -919,6 +919,9 @@ function beta_inc_inv(a::Real, b::Real, p::Real, q::Real) | |||||
end | ||||||
|
||||||
function _beta_inc_inv(a::Float64, b::Float64, p::Float64, q::Float64=1-p) | ||||||
|
||||||
maxiter = 30 | ||||||
|
||||||
#change tail if necessary | ||||||
if p > 0.5 | ||||||
y, x = _beta_inc_inv(b, a, q, p) | ||||||
|
@@ -968,8 +971,8 @@ function _beta_inc_inv(a::Float64, b::Float64, p::Float64, q::Float64=1-p) | |||||
sq = 1.0 | ||||||
prev = 1.0 | ||||||
|
||||||
if x < 0.0001 | ||||||
x = 0.0001 | ||||||
if x < 1e-200 | ||||||
x = 1e-200 | ||||||
end | ||||||
if x > .9999 | ||||||
x = .9999 | ||||||
|
@@ -1001,7 +1004,7 @@ function _beta_inc_inv(a::Float64, b::Float64, p::Float64, q::Float64=1-p) | |||||
acu = exp10(iex) | ||||||
|
||||||
#iterate | ||||||
while true | ||||||
for i in 1:maxiter | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe
Suggested change
since we don't use |
||||||
p_approx = beta_inc(a, b, x)[1] | ||||||
xin = x | ||||||
p_approx = (p_approx - p)*min( | ||||||
|
@@ -1026,7 +1029,7 @@ function _beta_inc_inv(a::Float64, b::Float64, p::Float64, q::Float64=1-p) | |||||
end | ||||||
|
||||||
#check if current estimate is acceptable | ||||||
|
||||||
prev, acu, p_approx, x, tx | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this was for debugging?
Suggested change
|
||||||
if prev <= acu || p_approx^2 <= acu | ||||||
x = tx | ||||||
return (x, 1.0 - x) | ||||||
|
@@ -1039,6 +1042,9 @@ function _beta_inc_inv(a::Float64, b::Float64, p::Float64, q::Float64=1-p) | |||||
x = tx | ||||||
p_approx_prev = p_approx | ||||||
end | ||||||
|
||||||
@debug "Newton iterations didn't converge in $maxiter iterations. The result might have reduced precision." | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably deserves a higher logging level?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I deliberately chose |
||||||
return (x, 1.0 - x) | ||||||
end | ||||||
|
||||||
function _beta_inc_inv(a::T, b::T, p::T) where {T<:Union{Float16, Float32}} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any specific reason for this choice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation-wise, it seems the section here could be simplified to