Closed opatiny closed 1 year ago
Interesting...it looks like omitting initialValues
is supposed to be equivalent to setting all parameters to 1, but this line seems to assume the parameters are separate arguments, not a single array containing the parameters:
https://github.com/mljs/levenberg-marquardt/blob/c8317bc28753976e1182cf9b381080a361d56aaa/src/checkOptions.js#L38
If that's indeed incorrect then it's been a latent bug for a very long time (>5 years if I'm interpreting git blame accurately). Furthermore, I don't see any test cases that omit the initial values. I suggest converting your example into a test case and then making it pass. There will need to be some way for LM to determine how many parameters there are (length of array), and it's not obvious to me what that should be. For now the work-around is to supply initialValues
whenever there is more than 1 parameter. It seems a shame to me that an array is passed to the function instead of making each parameter an argument since it is easy to go the other way (parameterizedFunction(...arrayOfParams)
vs parameterizedFunction(arrayOfParams)
), but everything appears to be already set up to do it this way (and maybe it's also more performant like this) so would be a royal pain & major breaking change to alter that at this point.
initialValues
option is optional
BTW, could you tell me where you found that information? I see in the code that a default value is supplied if it is omitted, but I didn't see any documentation beyond the jsdoc comment, which does not show it as optional. The simplest way forward may be to make the current behavior explicit, i.e. show that default value is [1] (replacing code that tries to get using function.length) and document that it is not optional when there is more than 1 parameter.
@opatiny Thanks for reporting this. initialValues
was not supposed to be optional. PR #53 makes it so that now an error will be thrown if it is missing.
@opatiny Thanks for reporting this.
initialValues
was not supposed to be optional. PR #53 makes it so that now an error will be thrown if it is missing.
Thank you very much for the fix! :)
initialValues
option is optional, but if it is not passed, the algorithm systematically returns{ parameterValues: [ 1 ], parameterError: NaN, iterations: 0 }
as shown in the below example: