Strange behaviour of find_zero() from Roots.jl

Hi everyone,

I recently updated the version of Roots.jl I use in my package. I have some simple code that looks like this

    f    = β -> begin
                    diff = mb(β, β, par, bpar = ConstructBPar(β, par)) - infocostdiff(β,par)
                    @show diff
                    @show β
                    return diff
                end
        find_zero(f, (0.00000001, 2), Bisection())
    end

This is what the last iterations look like

diff = -1.6653345369377348e-16
β = 0.06802616450595264
diff = 3.3306690738754696e-16
β = 0.06802616450595263
diff = 3.3306690738754696e-16
β = 0.06802616450595263
diff = -2.220446049250313e-16
β = 0.06802616450595265
diff = -5.0e-8
β = 1.0e-8
diff = -10.0
β = 2.0

and I get the following error

ArgumentError: The interval [a,b] is not a bracketing interval.
You need f(a) and f(b) to have different signs (f(a) * f(b) < 0).
Consider a different bracket or try fzero(f, c) with an initial guess c.


init_state(::Bisection, ::Roots.DerivativeFree{getfield(AlbagliInfo, Symbol("##238#239")){Pars}}, ::Tuple{Float64,Float64}) at bracketing.jl:81
#find_zero#8(::Roots.NullTracks, ::Bool, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(find_zero), ::Function, ::Tuple{Float64,Int64}, ::Bisection) at bracketing.jl:310
find_zero at bracketing.jl:307 [inlined]
FindFixedPoint at Functions.jl:636 [inlined]
ChooseBeta at GrowthFuncs.jl:236 [inlined]
#Sim#186(::Array{Float64,2}, ::Type, ::Int64, ::Type{Sim}, ::Pars, ::Int64, ::Symbol) at GrowthFuncs.jl:159
Sim(::Pars, ::Int64, ::Symbol) at GrowthFuncs.jl:137
top-level scope at Growth.jl:65

It seems to me that it found a zero, but then decided that it actually didn’t and that an error would a better outcome.

What can I do? When I run status inside my package, this happens, but I don’t understand why

(MyPackage) pkg> status
Project MyPackage v0.1.0
    Status `C:\Path\MyPackage\Project.toml`
  [1375f997] + CompEcon v0.4.0
  [a93c6f00] ↑ DataFrames v0.17.1 ⇒ v0.19.4
  [31c24e10] ↑ Distributions v0.16.4 ⇒ v0.21.8
  [2fe49d83] ↑ Expectations v1.0.2 ⇒ v1.1.1
  [442a2c76] ↑ FastGaussQuadrature v0.3.2 ⇒ v0.4.0
  [a98d9a8b] ↑ Interpolations v0.11.2 ⇒ v0.12.5
  [429524aa] ↑ Optim v0.17.2 ⇒ v0.19.4
  [d96e819e] ↑ Parameters v0.10.3 ⇒ v0.12.0
  [fcd29c91] ↑ QuantEcon v0.15.0 ⇒ v0.16.2
  [f2b01f46] ↑ Roots v0.7.4 ⇒ v0.8.3
  [37e2e46d]   LinearAlgebra
  [9a3f8284]   Random
  [10745b16]   Statistics
    Status `C:\Path\MyPackage\Project.toml`
  [1375f997] + CompEcon v0.4.0
  [a93c6f00] ↑ DataFrames v0.17.1 ⇒ v0.19.4
  [31c24e10] ↑ Distributions v0.16.4 ⇒ v0.21.8
  [2fe49d83] ↑ Expectations v1.0.2 ⇒ v1.1.1
  [442a2c76] ↑ FastGaussQuadrature v0.3.2 ⇒ v0.4.0
  [a98d9a8b] ↑ Interpolations v0.11.2 ⇒ v0.12.5
  [429524aa] ↑ Optim v0.17.2 ⇒ v0.19.4
  [d96e819e] ↑ Parameters v0.10.3 ⇒ v0.12.0
  [fcd29c91] ↑ QuantEcon v0.15.0 ⇒ v0.16.2
  [f2b01f46] ↑ Roots v0.7.4 ⇒ v0.8.3

You could make an MWE and open an issue for Roots.jl.

I am not sure what the problem is with the pkg> status output.

I am just confused by all the updating statements, I thought it should just give you a list of installed packages, as it just in the general environment.

Sure, I’ll open an issue with a MWE this week.

Is there another package you can recommend in the meantime that has a similar functionality (rootfinding)? I kind of need this to work now :sweat_smile:

1 Like

Bisection is really simple to implement. Eg

1 Like

And of course the problem was not at all with Roots.jl, but somewhere else in my code >.<

Sorry for the inconvenience and your help nonetheless Tamas_Papp! You have helped already a few times and you are in general very helpful in this forum! :smile:

Is it possible to delete this topic?

1 Like

Haahah, don’t delete it, i had this same problem, now i make sure that my intervals are of opposite signs before passing those to find_zero