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

Why return the *function* value when maxIter fails to converge to tolerance? #2

Closed
fasiha opened this issue Sep 17, 2018 · 3 comments
Closed

Comments

@fasiha
Copy link

fasiha commented Sep 17, 2018

I was minimizing a function of Dates using this fine library, with just lowerBound and upperBound and without specifying tolerance/maxIter, and was surprised to see function values instead of argument values as output, till I read in the docs that,

If tolerance is not met, returns best answer.

(This is what triggered my #1… 😅)

This is such a surprising behavior for when the tolerance is not met, I almost think that it'd be better to throw an error in this situation rather than return the function's value?

Just a suggestion. Now I've made my tolerance 1e3 (since my function operates on milliseconds since Unix epoch) and am getting perfect results, hooray!

@jaspervdg
Copy link
Member

jaspervdg commented Sep 18, 2018 via email

@rreusser
Copy link
Member

rreusser commented Sep 18, 2018

You're right! That makes precisely no sense at all. Gosh, it's painful to read old code.

What do you think about an optional status argument, e.g. minimize(f, options, status). After completion, it'll have, maybe:

status = {value: minimizedValue, iterations: ##, converged: true|false}`

That way you can get lazy and just use it inline (argmin = minimize(f)), and if you want to be careful about convergence, there's no overloading of outputs or try/catch (is try/catch still the optimization killer it's traditionally been?). I suppose it'd either return either the best guess or NaN (probably NaN?) if it fails to converge.

Edit: Ah, and if you return NaN, then you can still return the best guess via the status, just in case that's useful information…

@fasiha
Copy link
Author

fasiha commented Sep 19, 2018

Fixed by #4!

@fasiha fasiha closed this as completed Sep 19, 2018
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

No branches or pull requests

3 participants