Open Jhsmit opened 4 years ago
I have a note somewhere that claims that MINPACK also has problems with VectorLeastSquares. Don't have an example atm.
Yeah I think that is a fundamental problem with the design of MINPACK (or the scipy wrapping of it, don't know at what level this occurs.)
Basically, the scipy API wants a function which returns the residual per data point: (y_i - f(x_i, *params))/sigma_i. It will then take the quadratic sum itself.
In order to do global fitting we compute the chi2 per component of the model, and minimize their sum: chi2 = \sum_{n=1}^{components} chi2_n
I guess we could redefine VectorLeastSquares such that it gives the residuals of each component appended to each other into a one dimensional list, since that should be equivalent. But if it also uses these residuals in the calculation of the jacobian, which it probably does, then we have to be careful to check that they are also equivalent on that level.
Running the fitting with multiple datasets doesnt work with the MINPACK minimizer. The example from the docs:
Gives:
Other minimizers do work and reducing the datasets to one also does work.