|
| 1 | +""" |
| 2 | +```julia |
| 3 | +Itp(; k1::Real = 0.007, k2::Real = 1.5, n0::Int = 10) |
| 4 | +``` |
| 5 | +
|
| 6 | +ITP (Interpolate Truncate & Project) |
| 7 | +
|
| 8 | +Use the [ITP method](https://en.wikipedia.org/wiki/ITP_method) to find |
| 9 | +a root of a bracketed function, with a convergence rate between 1 and 1.62. |
| 10 | +
|
| 11 | +This method was introduced in the paper "An Enhancement of the Bisection Method |
| 12 | +Average Performance Preserving Minmax Optimality" |
| 13 | +(https://doi.org/10.1145/3423597) by I. F. D. Oliveira and R. H. C. Takahashi. |
| 14 | +
|
| 15 | +# Tuning Parameters |
| 16 | +
|
| 17 | +The following keyword parameters are accepted. |
| 18 | +
|
| 19 | +- `n₀::Int = 1`, the 'slack'. Must not be negative.\n |
| 20 | + When n₀ = 0 the worst-case is identical to that of bisection, |
| 21 | + but increacing n₀ provides greater oppotunity for superlinearity. |
| 22 | +- `κ₁::Float64 = 0.1`. Must not be negative.\n |
| 23 | + The recomended value is `0.2/(x₂ - x₁)`. |
| 24 | + Lower values produce tighter asymptotic behaviour, while higher values |
| 25 | + improve the steady-state behaviour when truncation is not helpful. |
| 26 | +- `κ₂::Real = 2`. Must lie in [1, 1+ϕ ≈ 2.62).\n |
| 27 | + Higher values allow for a greater convergence rate, |
| 28 | + but also make the method more succeptable to worst-case performance. |
| 29 | + In practice, κ=1,2 seems to work well due to the computational simplicity, |
| 30 | + as κ₂ is used as an exponent in the method. |
| 31 | +
|
| 32 | +### Worst Case Performance |
| 33 | +
|
| 34 | +n½ + `n₀` iterations, where n½ is the number of iterations using bisection |
| 35 | +(n½ = ⌈log2(Δx)/2`tol`⌉). |
| 36 | +
|
| 37 | +### Asymptotic Performance |
| 38 | +
|
| 39 | +If `f` is twice differentiable and the root is simple, |
| 40 | +then with `n₀` > 0 the convergence rate is √`κ₂`. |
| 41 | +""" |
| 42 | +struct Itp{T} <: AbstractBracketingAlgorithm |
| 43 | + k1::T |
| 44 | + k2::T |
| 45 | + n0::Int |
| 46 | + function Itp(; k1::Real = 0.007, k2::Real = 1.5, n0::Int = 10) |
| 47 | + if k1 < 0 |
| 48 | + error("Hyper-parameter κ₁ should not be negative") |
| 49 | + end |
| 50 | + if n0 < 0 |
| 51 | + error("Hyper-parameter n₀ should not be negative") |
| 52 | + end |
| 53 | + if k2 < 1 || k2 > (1.5 + sqrt(5) / 2) |
| 54 | + ArgumentError("Hyper-parameter κ₂ should be between 1 and 1 + ϕ where ϕ ≈ 1.618... is the golden ratio") |
| 55 | + end |
| 56 | + T = promote_type(eltype(k1), eltype(k2)) |
| 57 | + return new{T}(k1, k2, n0) |
| 58 | + end |
| 59 | +end |
| 60 | + |
| 61 | +function SciMLBase.solve(prob::IntervalNonlinearProblem, alg::Itp, |
| 62 | + args...; abstol = 1.0e-15, |
| 63 | + maxiters = 1000, kwargs...) |
| 64 | + f = Base.Fix2(prob.f, prob.p) |
| 65 | + left, right = prob.tspan # a and b |
| 66 | + fl, fr = f(left), f(right) |
| 67 | + ϵ = abstol |
| 68 | + if iszero(fl) |
| 69 | + return SciMLBase.build_solution(prob, alg, left, fl; |
| 70 | + retcode = ReturnCode.ExactSolutionLeft, left = left, |
| 71 | + right = right) |
| 72 | + elseif iszero(fr) |
| 73 | + return SciMLBase.build_solution(prob, alg, right, fr; |
| 74 | + retcode = ReturnCode.ExactSolutionRight, left = left, |
| 75 | + right = right) |
| 76 | + end |
| 77 | + #defining variables/cache |
| 78 | + k1 = alg.k1 |
| 79 | + k2 = alg.k2 |
| 80 | + n0 = alg.n0 |
| 81 | + n_h = ceil(log2((right - left) / (2 * ϵ))) |
| 82 | + mid = (left + right) / 2 |
| 83 | + x_f = (fr * left - fl * right) / (fr - fl) |
| 84 | + xt = left |
| 85 | + xp = left |
| 86 | + r = zero(left) #minmax radius |
| 87 | + δ = zero(left) # truncation error |
| 88 | + σ = 1.0 |
| 89 | + ϵ_s = ϵ * 2^(n_h + n0) |
| 90 | + i = 0 #iteration |
| 91 | + while i <= maxiters |
| 92 | + #mid = (left + right) / 2 |
| 93 | + r = ϵ_s - ((right - left) / 2) |
| 94 | + δ = k1 * ((right - left)^k2) |
| 95 | + |
| 96 | + ## Interpolation step ## |
| 97 | + x_f = (fr * left - fl * right) / (fr - fl) |
| 98 | + |
| 99 | + ## Truncation step ## |
| 100 | + σ = sign(mid - x_f) |
| 101 | + if δ <= abs(mid - x_f) |
| 102 | + xt = x_f + (σ * δ) |
| 103 | + else |
| 104 | + xt = mid |
| 105 | + end |
| 106 | + |
| 107 | + ## Projection step ## |
| 108 | + if abs(xt - mid) <= r |
| 109 | + xp = xt |
| 110 | + else |
| 111 | + xp = mid - (σ * r) |
| 112 | + end |
| 113 | + |
| 114 | + ## Update ## |
| 115 | + yp = f(xp) |
| 116 | + if yp > 0 |
| 117 | + right = xp |
| 118 | + fr = yp |
| 119 | + elseif yp < 0 |
| 120 | + left = xp |
| 121 | + fl = yp |
| 122 | + else |
| 123 | + left = xp |
| 124 | + right = xp |
| 125 | + end |
| 126 | + i += 1 |
| 127 | + mid = (left + right) / 2 |
| 128 | + ϵ_s /= 2 |
| 129 | + |
| 130 | + if (right - left < 2 * ϵ) |
| 131 | + return SciMLBase.build_solution(prob, alg, mid, f(mid); |
| 132 | + retcode = ReturnCode.Success, left = left, |
| 133 | + right = right) |
| 134 | + end |
| 135 | + end |
| 136 | + return SciMLBase.build_solution(prob, alg, left, fl; retcode = ReturnCode.MaxIters, |
| 137 | + left = left, right = right) |
| 138 | +end |
0 commit comments