ksw/enhance image fitting performance by switching the solver from qr to cholesky #1114
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is to address the performance concern from @Jordatious about the current 2D image fitting implementation by switching the default solver "qr" to "cholesky". You may refer to
https://www.gnu.org/software/gsl/doc/html/nls.html#c.gsl_multilarge_nlinear_solver.gsl_multifit_nlinear_solver_qr
https://www.gnu.org/software/gsl/doc/html/nls.html#c.gsl_multilarge_nlinear_solver.gsl_multifit_nlinear_solver_cholesky
to see the differences as also mentioned in the comment chain of the PR #1055.
With some tests, the performance boost in terms of elapsed time is reduced by ~66%. This is measured by testing single and triple gaussian fit with different image sizes. As for the fitting result accuracy, it appears to me that the two solvers give very similar solutions.
I also tried other methods to solve the trust region subproblem (https://www.gnu.org/software/gsl/doc/html/nls.html#solving-the-trust-region-subproblem-trs)
We use
gsl_multifit_nlinear_trs_lm
: Levenberg-Marquardt algorithm now:gsl_multifit_nlinear_trs_lmaccel
: Levenberg-Marquardt algorithm with geodesic acceleration --> slower. I don't provide the second directional derivative vector so it is using finite difference method for approximationgsl_multifit_nlinear_trs_dogleg
: dogleg algorithm --> slowergsl_multifit_nlinear_trs_ddogleg
: double dogleg algorithm --> slowergsl_multifit_nlinear_trs_subspace2D
: 2D subspace algorithm --> super fast and converged with just 1 iteration but the result is not correct. Not sure if I miss something configurable hereThis PR is considered as a quick-and-dirty improvement of the fitting performance for the final v3 release. Open for comments on whether or not merging this.