JuliaNLSolvers / NLsolve.jl

Julia solvers for systems of nonlinear equations and mixed complementarity problems

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hard fail after too many iterations

djsegal opened this issue · comments

If iterations = 40, how do you make the solver return NaN after 40 iterations are up?

I don't think this should be a built in behavior.

I would suggest that you check the iterations field on the result and see if it is the same as the number of iterations you asked it to do. Doing this in conjunction with checking x_converged and f_converged is probably a good idea. If you really want the result to be nan you can do the checks and then fill!(result.zero, NaN)

That being said, I'm open to being convinced otherwise if people can provide a compelling argument.

could there be a built-in function that wraps checking:

  • iterations
  • x_converged
  • f_converged

?

There is the converged function, but it doesn't handle checking iterations because we don't store the max number of iterations allowed by the user.

I would not be opposed to storing max_iterations as another field on SolverResults, which would make your suggestion possible.

In Optim we simply store a bool that states if the max was reached or not. I think it's about time that we discuss if NLsolve and Optim should maybe move a little bit closer in terms of syntax (etc) and how. See also the discussion here JuliaNLSolvers/Optim.jl#263 where we discuss if results should not be available if you didn't get converged(res)==true, and at the same time allow for something like unsafe_minimizer(res) that would give you the last result even if you didn't converge.

NaN isn't defined for every number type, so that would shoehorn NLsolve into specific number types unnecessarily.

Just have a field for a retcode symbol, and have one for each of the possible things that can happen. NLopt does this and it's really nice to work with so I stole the idea for DiffEq. Anyone can check for success via sol.retcode == :Success, but if it's not a success they have more information about what actually happened.

Retcode is kind of esoteric though.

I agree it should be in the package. I just think more simple functions should exist that use retcode under the hood

NaN isn't defined for every number type, so that would shoehorn NLsolve into specific number types unnecessarily.

Just curious, what number types are they?

The one that I always have to work around for is integers and rationals. Depends on what you're looking to support though.

Integers seems a bit unusual. Rationals could perhaps be accommodated

I won't do this. People should verify convergence before using the values imo.