I am trying to use TVirtualFitter as in the example fit2dHist.C. According to what I read, minimization should exit if max calls (in my case, 1000000) is reached or a minimum with appropriate edm (<1) is found. Anyway, it seems that my code is exiting after only 11 calls without reaching appropriate edm value. The ouput is as follows.
In addition I want to perform minimization with SIMPLEX, MIGRAD and finally MINOS, Using MINOS anyway I get “TFitterMinuit::MINOS failed due to invalid function minimum” even if MIGRAD minimization exited correctly.
I see you are using TFitterMinuit, which is an old interface to Minuit2, which has been removed from ROOT starting from version 6.
I am not sure which version exactly you are using of ROOT, maybe the version of Minuit2 is very old and could contain still some bugs.
Otherwise what you observe could be cause by a failure during the minimisation (if you increase the print level you might see an error message).
This failure is typically caused by bad precision in computing the function to minimise.
Anyway, I am not able to get more information than the one in my first post, even using “3” as print level.
If you think this method is old, could you please link me an example of different way or fitting? Actually, what I want to do is determination of a x scale parameter between two histograms and I am using chi square as myFCN.
I checked again inside my code and I did not find anything that can explain why PrintLevel=3 is not working.
Actually my code is not a .C file, but a .cpp file compiled using a makefile. Is it a possible explanation or am I missing something?
Yes, this is very strange. Maybe you are re-directing the output somewhere else ?
Also it is strange you get a failure with status=4, which means that you have reached the call limit, but in reality you had only 55 iterations.
Can you post the code, so I can reproduce the problem ?
You are missing to set the minimiser option to the fitter (to the FitConfig object).
You need to add this line, before calling the Fit method:
fitter.Config().SetMinimizerOptions(opt);
After doing this I see the correct output. The fit does not converge for some precision problems, due in the FCN calculation. I can try to understand later the reason for this
Thank you for your suggestion. I attached the modified code. As you said there is still problem with conversion.
I guess this is a very basic question but… why I obtain a different result each time I run it? If you run it 10 times, you will get the correct value (0.5) at least once. Despite this, also in this case fit status is invalid (3).
I am really wondering how to solve my problem. Changing parameter like tolerance or step size did not clearly improve situations (of course, if we use 0.5 as initial value or a very narrow range, fit converges but in real situation I do not know this value). Do you have some other general suggestions that I can try? Thank you in advance. x_scale_fit.cpp (5.25 KB)
I am sorry to ask again about this problem, but yet I was not able to find some constraints on the fit in order to obtain convergence. Could you give me some more hints?
The problem is your function. Looking at how is defined the function can have discontinuities because a parameter is making a horizontal shifts in the bin. This can cause discontinuities in the function evaluations, which are not good for Minuit.
You should find a way to avoid this.
I am not completely sure of having understood your suggestion. I tried to use TGraph in the following way:
convert TH1 in TGraph
scale x of TGraph for the fitting parameter
normalize TGraph to the reference TH1
evaluate chi2 using TGraph::Eval
I expected to overcome discontinuities in this way. I am checking results of each calls. Distributions seem reasonable, but in the end I can not get convergence. Should I put some kind of constraints on derivatives?
It looks better with the Graph than before, but probably there are still some precision or discontinuities in the FCN function. You can try to plot the FCN as function of the parameter around the sound best minimum value to see how it behaves.
I checked function vs call and function vs parameter. I see some kind of quadratic relation, despite sometimes the function value is very high, but finally the minimization get stacked far away from correct value (0.5). x_scale_fit.cpp (6.88 KB)
Hi,
Can you attach a plot of the CHi2 function vs the parameter values, in particular close to the minimum ?
Or better adapt the macro to make this plot. At the moment your code is not working for me
I am sorry, I swapped x-y in the plot so even my conclusion was wrong. I don’t know if this was the problem (of course it is not a beautiful code…), anyway I updated it.
You can find the image your requested. The zoom is in [0,2] region (right value should be 0.5). The algorithm finds a very high chi2 just below 1. Maybe this is the reason why it is not moving to the right direction (the left one). x_scale_fit.cpp (7.18 KB) img.eps (54.2 KB)
Hi,
I see big jumps in chi2 vs par0, however this is not exactly the plot I meant. What I meant is chi vs par0 for grid values of par0 around the minimum, to see how it behaves, in particular using a very fine grid, Th plot you have is for the par0 values occurred during the minimisation.
If the function is not smooth for small changes of par0 then Minuit will not be able to work
Ok, finally I got what you were saying! This is the picture. As you said, it seems that the minimum around 0.5 is very narrow, so maybe that, if the fit does not try a value very near to it, it will exclude that region. Am I right? chi2vspar0_zoom.eps (17.2 KB) chi2vspar0.eps (14.4 KB) chi2vspar0.cpp (3.07 KB)