mljs / levenberg-marquardt

Curve fitting method in JavaScript
MIT License
70 stars 15 forks source link

Constraint parameter values (feature request) #15

Closed jacobq closed 5 years ago

jacobq commented 6 years ago

Is it possible to constraint the parameters? For example, I have some that cannot be less than 1. These could either be used as limits to "clamp" the values or they could be used as a termination condition similar to maxIterations.

If this isn't currently possible, would you accept a PR to add support for this? e.g. extend options to include a validators parameter equal to an array of functions that return true if the provided argument is a valid value for the corresponding parameter, otherwise returns false.

maasencioh commented 6 years ago

Hello @jacobq, first, all the PR are always welcomed, so go for it, and second, wouldn't be easier to use a Simplex if you know about the restrictions?

jacobq commented 6 years ago

I'm not familiar with what you're referring to. Is it the "simplex algorithm" in linear programming, the "downhill simplex method", or something else?

I wonder if I could achieve something similiar to constraints by modifying my target function to generate grossly large values when invalid (out of range) parameters are provided.

m93a commented 6 years ago

It seems that there already are options for that… 🤔 You can use options.maxValue = [100, 50, -3, …] to restrict the upper bound and options.minValue to restrict the lower bound similarly. It is however missing in the README, so we should close this after we add the documentation.

jobo322 commented 6 years ago

hello there, you are just right, this option was implemented early, I am not sure if the name of those options isok

m93a commented 6 years ago

Maybe we should rename them to maxValues and minValues (with the s in the end) so that it's in accordance with initialValues.

jacobq commented 5 years ago

I came back to this today... @maasencioh I can't use the Simplex Algorithm because my function is non-linear. @m93a, Regarding existing options they are not present in the latest release -- only since https://github.com/mljs/levenberg-marquardt/commit/ad8e7507163e6978920c006418a65c8b6a48efa7 @jobo322 Thanks for adding support for min/max values. I agree that minValues and maxValues would be preferable (plural form).

Would someone be willing to publish a (beta?) version to NPM so that I can try it out? Update: Nevermind, I published @jacobq/ml-levenberg-marquardt, my own fork

m93a commented 5 years ago

I'm planing on finishing the PR later this month, then it can be published to NPM as a stable version, before that you'll have to use a fork.

PS: Did you know you can install a package directly from GitHub? That way you don't need to publish the fork to NPM, and still use it. 😉

jacobq commented 5 years ago

@m93a I'm aware of how to specify a git repository directly in package.json but in the past this didn't work with prepublish scripts so it only worked when there was no processing/compiling needed. I will look into it again as it sounds like now the prepare script may help with this.