Quantcast

Handling non-convergence in roots.jl

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Handling non-convergence in roots.jl

Joaquim Masset Lacombe Dias Garcia
I am running a sequence of root finding functions in a loop.
For my problem the basic fzero always work.

However, using Newtons method is very useful because it is very fast when it converges.
The problem is that when it does not converge it throws an error instead of a non-convergence flag.

That way I cant use the fzero when newton fails (actually try/catch works but its very slow).

Any suggestions?


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Handling non-convergence in roots.jl

Mauro
On Thu, 2016-11-10 at 18:54, Joaquim Masset Lacombe Dias Garcia <[hidden email]> wrote:

> I am running a sequence of root finding functions in a loop.
> For my problem the basic fzero always work.
>
> However, using Newtons method is very useful because it is very fast when
> it converges.
> The problem is that when it does not converge it throws an error instead of
> a non-convergence flag.
>
> That way I cant use the fzero when newton fails (actually try/catch works
> but its very slow).
>
> Any suggestions?

Just modify the Roots.jl package.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Handling non-convergence in roots.jl

Mauro

On Thu, 2016-11-10 at 20:07, Mauro <[hidden email]> wrote:

> On Thu, 2016-11-10 at 18:54, Joaquim Masset Lacombe Dias Garcia <[hidden email]> wrote:
>> I am running a sequence of root finding functions in a loop.
>> For my problem the basic fzero always work.
>>
>> However, using Newtons method is very useful because it is very fast when
>> it converges.
>> The problem is that when it does not converge it throws an error instead of
>> a non-convergence flag.
>>
>> That way I cant use the fzero when newton fails (actually try/catch works
>> but its very slow).
>>
>> Any suggestions?
>
> Just modify the Roots.jl package.

To be a bit more informative:  The error gets thrown here:
https://github.com/JuliaMath/Roots.jl/blob/943cf897e9ea6b31ab3ec70238ac4931065d365a/src/derivative_free.jl#L45

In that function, modify all occurrences of
  throw(ConvergenceFailed("some message"))
with
  ( warn("some message"); return true)

Restart the REPL

Then it should not throw but warn and return the best value it found.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Handling non-convergence in roots.jl

Joaquim Masset Lacombe Dias Garcia
Thanks!

On Thu, Nov 10, 2016 at 6:03 PM, Mauro <[hidden email]> wrote:

On Thu, 2016-11-10 at 20:07, Mauro <[hidden email]> wrote:
> On Thu, 2016-11-10 at 18:54, Joaquim Masset Lacombe Dias Garcia <[hidden email]> wrote:
>> I am running a sequence of root finding functions in a loop.
>> For my problem the basic fzero always work.
>>
>> However, using Newtons method is very useful because it is very fast when
>> it converges.
>> The problem is that when it does not converge it throws an error instead of
>> a non-convergence flag.
>>
>> That way I cant use the fzero when newton fails (actually try/catch works
>> but its very slow).
>>
>> Any suggestions?
>
> Just modify the Roots.jl package.

To be a bit more informative:  The error gets thrown here:
https://github.com/JuliaMath/Roots.jl/blob/943cf897e9ea6b31ab3ec70238ac4931065d365a/src/derivative_free.jl#L45

In that function, modify all occurrences of
  throw(ConvergenceFailed("some message"))
with
  ( warn("some message"); return true)

Restart the REPL

Then it should not throw but warn and return the best value it found.

Loading...