Skip to content
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

Default ITP parameters update #155

Merged
merged 5 commits into from
Aug 10, 2024
Merged

Default ITP parameters update #155

merged 5 commits into from
Aug 10, 2024

Conversation

DaniGlez
Copy link
Contributor

@DaniGlez DaniGlez commented Aug 9, 2024

Address #108 and update default ITP parameters to the ones in the paper.

Additional context

Additionally, the coefficient κ₁ has been replaced in the ITP struct by a scale-invariant version that is dimensionally coherent. In the original ITP paper, they fix κ₁ so that the first scaled step is 20% of the interval, but for their test functions in the (-1,1) interval. This produces an algorithm that is not scale-invariant: just resizing the span (while appropriately "stretching" the corresponding function) can improve or degrade performance: see Fig. 1, which evaluates it on the test functions from the ITP paper:

current

With the proposed changes in this PR (using a value that is equivalent to the "20% of the span" rule of thumb), this pattern disappears:

pr

Code:

using SimpleNonlinearSolve, SpecialFunctions

normpdf(z::Number) = exp(-abs2(z)/2) * (1 / sqrt(2π))
ϕ(x) = normpdf(x)
Φ(x) = erfc(x / sqrt(2))/2

function count_evals(f, r)
    function g(x, p)
        p[1] += 1
        f(x / r)
    end
    p = [0]
    prob = IntervalNonlinearProblem{false}(g, (-r, r), p)
    sol = solve(prob, ITP(); abstol = 1e-9 * r)
    p[1]
end

# Well-behaved functions from ITP paper
f_wb = (
    x -> x * exp(x) - 1, 
    x -> tan(x - 0.1), 
    x -> sin(x) + 0.5,
    x -> 4x^5 + x^2 + 1, 
    x -> x + x^10 - 1, 
    x -> π^x - exp(1),
    x -> log(abs(x - 10 / 9)), 
    x -> 1 / 3 + sign(x) * abs(x)^(1 / 3) + x^3,
    x -> 10^(-3) + sum(sin(0.5π * i^3 * x)/*i^3) for i  1:10),
    x -> (x + 2/3)/(x + 101/100), 
    x -> Φ(x-1) - (2)/4, 
    x -> ϕ(x-1) - (2)/4
)

# Ill-behaved functions from ITP paper (selection)
f_ib = (
    x -> (1e6x - 1)^3,
    x -> exp(x)*(1e6x - 1)^3,
    x -> (x - 1/3)^2 * atan(x - 1/3),
    x -> sign(3x+1)*(1 - sqrt(1 - (3x + 1)^2 / 9^2)),
    x -> ifelse(x > (1 - 1e6)/1e6, (1 + 1e6)/1e6, 0.0) - 1, # notation ?
    x -> ifelse(x == 1/21, 0.0, 1/(21x - 1)),
    x -> (0.5x)^2 + ceil(0.5x) - 0.5,
    x -> ceil(10x - 1) + 0.5,
    x -> x + sin(1e6x)/10 + 1e-3,
    # x -> ifelse(x > -1, 1 + sin(), 0.0)    
)

f_all = (f_wb..., f_ib...)
scales_list = [1e-12, 1e-9, 1e-6, 1e-3, 1.0, 1e3, 1e6, 1e9, 1e12]
l = [[count_evals(f, s) for s  scales_list]  for f  f_all]

begin
    using Plots
    p = Plots.plot(scales_list, l, xaxis=:log, title="PR", 
    xlabel="Scale factor", ylabel="Function evaluations", legend=false)
end

Checklist

  • Appropriate tests were added (does not apply)
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

@DaniGlez
Copy link
Contributor Author

DaniGlez commented Aug 9, 2024

As an additional boon, this PR now makes ITP work with fancy numbers e.g. Unitful. This example does not work now but it works with this PR:

using Unitful
m = u"m"
kg = u"kg"
f_m(x, p) = 4kg*m^-5*x^5 + 1.0kg/m^2 * x^2 + 1kg

prob = IntervalNonlinearProblem{false}(f_m, (-1.0m, 1.0m), ())
sol = solve(prob, ITP(); abstol = 1e-9m)

@ChrisRackauckas ChrisRackauckas merged commit bdfe12f into SciML:main Aug 10, 2024
15 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants