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

options.errorTolerance doesn't recognize function minimum #41

Open
MontyThibault opened this issue Sep 4, 2021 · 2 comments
Open

options.errorTolerance doesn't recognize function minimum #41

MontyThibault opened this issue Sep 4, 2021 · 2 comments

Comments

@MontyThibault
Copy link

I ran into a problem and had to make a source modification for the convergence criteria. The currently-implemented convergence criterion operates in absolute terms of the squared residuals. Real data sets with noise may have a minimal curve with an arbitrarily-large error, and convergence in those cases will not be recognized.

https://github.com/mljs/levenberg-marquardt/blob/master/src/index.js#L106

I modified the convergence criteria to be the relative change based on the previous error, as described here: https://en.wikipedia.org/wiki/Non-linear_least_squares#Convergence_criteria.

...

error = errorCalculation(
      data,
      parameters,
      parameterizedFunction,
      weightSquare,
    );

converged = (previousError - error) / error <= errorTolerance;  // <<<

if (isNaN(error)) break;

...
@jobo322
Copy link
Member

jobo322 commented Sep 5, 2021

Hello @MontyThibault, Many thanks for it, I will check it soon.

@MontyThibault
Copy link
Author

If the curve can be fit exactly, I've gotten the inverse problem where convergence isn't recognized because the proportion of the change in error to the error itself has a lower bound. A combination of the relative and absolute approaches seems to work well in practice. Not an exact science in any case.

converged = (Math.abs(previousError - error) / error <= errorTolerance) || (error <= errorTolerance)

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

2 participants