[quote=“moneta”]Hi,
you are using the algorithm in the proper way and it is supposed to work.
The Levenberg-Marquardt algorithm is a good and efficient algorithm for non linear least square fitting. It works well and it is very fast if you are not too far away from the solution.
[/quote]
Hehe, according to wikipedia, this algorithm: “The LMA is more robust than the GNA, which means that in many cases it finds a solution even if it starts very far off the final minimum.”
However, it’s not the first time when wiki is wrong. Anyway, I just wanted to try and perhaps if there is a bug, help to find it.
[quote]
Your problem might be caused by a numerical error in the derivative calculation, but I would need to understand it better.
Normally it cannot go in infinite loop because there is a maximum number of iteration set to something like ~ 100. I would eventually decrease this value with ROOT::Math::MinimizerOPtions::SetDefaultMaxIterations(n).
Could you send me also the output you get from the GSL fitter when running with option “V” ? [/quote]
Indeed, there may be a problem in derivative or a kind of a bug in function itself, a bug which does not (at least visibly) affect other fitting methods. The function is quite complicated (numerical integration, than numerical convolution, everything with a finite number of points) and there may be some special, unstable cases. However, I have doubts that any fitting algorithm should behave like that, which I describe below.
The output when fitting just 2D centre position, scaling parameter and constant background is like that:
<TCanvas::MakeDefCanvas>: created default TCanvas with name c1
Fitting!
Minimize using GSLNLSMinimizer lmsder
----------> Iteration 0 / 100 status success
FVAL = 435.719635354222021
X Values : x = 0 y = 600 dx = 0 dy = 40.8317670854359 z = 0.085 ast = 0 coma = -8.41e-05 spher = 0 spher1 = -0 scale = 37.9333080069766 bg = 0.0495324967614449
after Gradient and Delta tests: the iteration has not converged yet
than, after a number of iterations it does not converge (which is strange but normal for my function for any fitting algorithm), but finishes with a solution. However, than I start a next fit, releasing one of the shape parameters, and it does not even come to “Minimize using GSLNLSMinimizer lmsder” message. It just, depending on the limits, starts with just 2 parameter values which it changes one to another in a loop, or quickly comes to this stage (I know that from the output from the fitted function). There is no output from the fitter (fcourse with “V” option). I guess the loop is infinite - I had it running for a few hours without change:
<TCanvas::MakeDefCanvas>: created default TCanvas with name c1
Fitting!
Change in parameter 6. Old value: -8.41e-05, new value: -8.40963452435962e-05 other: 0 41 60 0.0101667202426
Change in parameter 6. Old value: -8.40963452435962e-05, new value: -8.41e-05 other: 0 41 60.01200044998 0.0101667202426
Change in parameter 6. Old value: -8.41e-05, new value: -8.40963452435962e-05 other: 0 41 60 0.0101667202426
Change in parameter 6. Old value: -8.40963452435962e-05, new value: -8.41e-05 other: 0 41 60.01200044998 0.0101667202426
If it helps, I can send the output from the position+scale+background fit which comes to an end. I can also send my code, which is rather long and dirty, but I would not want to waste your time debugging my function… 