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

Better handling of domain errors #71

Closed
albop opened this Issue Nov 13, 2016 · 4 comments

Comments

Projects
None yet
3 participants
@albop

albop commented Nov 13, 2016

Many of my optimization attempts failed with DomainError() exceptions when the optimizer tries any point where the function is not properly defined. Is there a way to avoid that with the existing algorithms ?

Otherwise, it would be nice if the backtracking algorithm didn't stop the first time it sees an invalid value.

Here is an example:

import Optim
using NLsolve

# w() has a zero around 0.16, is not defined for x<0.15
w(x) = (x-0.15).^0.2-0.4 

# optimizing starting from below the root works:
sol = nlsolve(not_in_place(w), [0.151], method=:newton)
sol.zero

# not from above  (raises DomainError())
sol = nlsolve(not_in_place(w), [0.4], method=:newton)

# backtracking doesn't avoid bad points (raises DomainError())
sol = nlsolve(not_in_place(w), [0.4], method=:newton, linesearch! = Optim.backtracking_linesearch!)
@sglyon

This comment has been minimized.

Show comment
Hide comment
@sglyon

sglyon Nov 28, 2016

Collaborator

This is an annoying issue that I've hit a few times myself.

Do you have any suggestions for how we can make sure the function is never evaluated out of the user-defined bounds?

Collaborator

sglyon commented Nov 28, 2016

This is an annoying issue that I've hit a few times myself.

Do you have any suggestions for how we can make sure the function is never evaluated out of the user-defined bounds?

@albop

This comment has been minimized.

Show comment
Hide comment
@albop

albop Nov 28, 2016

Maybe there could be a version of a linesearch procedure, which would surround function evaluation with try/catch statements. For instance a backtracking procedure could try to evaluate the function at 2^(-n) dx until it finds the values of n where the function evaluate without error and residuals are reduced.
If I understand correctly the plan is to use a separate linesearch package so I guess that could be done there, but I haven't looked at it yet.
Other option, would be to just wrap the function so that it returns some big value instead of an error. Not clear it would work well with optimization algorithms if they are sensitive to sign.

albop commented Nov 28, 2016

Maybe there could be a version of a linesearch procedure, which would surround function evaluation with try/catch statements. For instance a backtracking procedure could try to evaluate the function at 2^(-n) dx until it finds the values of n where the function evaluate without error and residuals are reduced.
If I understand correctly the plan is to use a separate linesearch package so I guess that could be done there, but I haven't looked at it yet.
Other option, would be to just wrap the function so that it returns some big value instead of an error. Not clear it would work well with optimization algorithms if they are sensitive to sign.

@albop

This comment has been minimized.

Show comment
Hide comment
@albop

albop Nov 28, 2016

Answering my own comment: the backtracking version does work if one wraps the function with try/catch statements and use the backtracking linesearch:

function wraped(x)
       try
           return w(x)
       catch
           return 100000
       end
 end
# does not work:
sol = nlsolve(not_in_place(wraped), [0.4], method=:newton)
# works:
sol = nlsolve(not_in_place(wraped), [0.4], method=:newton, linesearch! = Optim.backtracking_linesearch!)

albop commented Nov 28, 2016

Answering my own comment: the backtracking version does work if one wraps the function with try/catch statements and use the backtracking linesearch:

function wraped(x)
       try
           return w(x)
       catch
           return 100000
       end
 end
# does not work:
sol = nlsolve(not_in_place(wraped), [0.4], method=:newton)
# works:
sol = nlsolve(not_in_place(wraped), [0.4], method=:newton, linesearch! = Optim.backtracking_linesearch!)
@pkofod

This comment has been minimized.

Show comment
Hide comment
@pkofod

pkofod Jul 22, 2018

Contributor

This has been solved in LineSearches.jl

Contributor

pkofod commented Jul 22, 2018

This has been solved in LineSearches.jl

@pkofod pkofod closed this Jul 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment