mljs / curve-fitting

Levenberg Marquardt curve-fitting: minimize sum of weighted squared residuals
MIT License
14 stars 7 forks source link

Generalize the code #8

Open opatiny opened 1 year ago

opatiny commented 1 year ago

The main issue is with the error computation (I think), which has to be generalized to N dimensions. It is this line that makes no sense if the data has N dimensions: https://github.com/mljs/curve-fitting/blob/3e4b93a6af30a00d5d1fe8515cc229f5369dcff4/src/LM.js#L530

opatiny commented 1 year ago

In the lm_matx function, the t argument can be a matrix, but not the y_dat!! So basically we can have multi-dimensional input, but not output (it is the trilateration example, which works indeed).

https://github.com/mljs/curve-fitting/blob/3e4b93a6af30a00d5d1fe8515cc229f5369dcff4/src/LM.js#L492

https://github.com/mljs/curve-fitting/blob/3e4b93a6af30a00d5d1fe8515cc229f5369dcff4/src/LM.js#L498

The doc of lm-matx is not coherent with the doc of LM though -> I don't know if the algo is supposed to work from N dimensions to N dimensions.

https://github.com/mljs/curve-fitting/blob/3e4b93a6af30a00d5d1fe8515cc229f5369dcff4/src/LM.js#L10-L11

opatiny commented 1 year ago

I compared with levenberg-marquardt and there is the same issue there: data and estimated data are subtracted and yield to an error value that can be positive or negative -> how to extend that to many dimensions??

https://github.com/opatiny/levenberg-marquardt/blob/65ec7d926553c1fb7fd85e94e139619c608d7535/src/gradientFunction.js#L35-L39

opatiny commented 1 year ago

Interesting ressources for error generalization:

opatiny commented 1 year ago

The main issue is with the error computation (I think), which has to be generalized to N dimensions. It is this line that makes no sense if the data has N dimensions:

https://github.com/mljs/curve-fitting/blob/3e4b93a6af30a00d5d1fe8515cc229f5369dcff4/src/LM.js#L530

After some thought, I think that the error is generalizable in many dimensions, for each dimension, you'll have a positive or negative error. The problem would therefore be further. I now get an error "Lu matrix is singular" here https://github.com/mljs/curve-fitting/blob/3e4b93a6af30a00d5d1fe8515cc229f5369dcff4/src/LM.js#L201-L205