Better understanding MINUIT

To better understand MINUIT, I have tried to fit a line using a negative log likelihood method. I am only executing the MIGRAD command. Below is the output. The last four items in the output are the best fit values for the two parameters and the true values of the two parameters. I am not sure why MIGRAD would fail to converge on such a simple example so I am wondering what I am doing wrong that might be causing this. Any help is much appreciated. If a working version of the code would be helpful, please let me know and I will be happy to provide it. Thank you for your time!


** 1 **SET ERRDEF 0.5



** 2 **SET STR 2


NOW USING STRATEGY 2: MAKE SURE MINIMUM TRUE, ERRORS CORRECT
PARAMETER DEFINITIONS:
NO. NAME VALUE STEP SIZE LIMITS
1 a[0] 2.00000e+00 1.00000e-01 no limits
2 a[1] 1.60000e+01 1.00000e-01 no limits


** 3 **MIGRAD 1e+04 100


FIRST CALL TO USER FUNCTION AT NEW START POINT, WITH IFLAG=4.
START MIGRAD MINIMIZATION. STRATEGY 2. CONVERGENCE WHEN EDM .LT. 1.00e-01
EIGENVALUES OF SECOND-DERIVATIVE MATRIX:
-2.8605e-02 2.0286e+00
MINUIT WARNING IN HESSE
============== MATRIX FORCED POS-DEF BY ADDING 0.030634 TO DIAGONAL.
FCN=2549.04 FROM HESSE STATUS=NOT POSDEF 30 CALLS 31 TOTAL
EDM=50436.7 STRATEGY= 2 ERR MATRIX NOT POS-DEF
EXT PARAMETER APPROXIMATE STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 a[0] 2.00000e+00 7.13730e-08 1.00000e-06 -2.67286e+09
2 a[1] 1.60000e+01 3.80075e-07 7.62939e-06 -3.34107e+08
ERR DEF= 0.5
MIGRAD FAILS TO FIND IMPROVEMENT
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=2497.32 FROM HESSE STATUS=OK 14 CALLS 90 TOTAL
EDM=4495.17 STRATEGY= 2 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 a[0] 3.22085e+00 3.63636e-08 1.53582e-06 -1.62605e+09
2 a[1] 2.24987e+01 1.66290e-07 1.07282e-05 -2.32781e+08
ERR DEF= 0.5
MIGRAD FAILS TO FIND IMPROVEMENT
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=2497.32 FROM HESSE STATUS=OK 18 CALLS 111 TOTAL
EDM=10488.7 STRATEGY= 2 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 a[0] 3.22085e+00 5.32309e-08 1.53582e-06 -1.62605e+09
2 a[1] 2.24987e+01 2.54012e-07 1.07282e-05 -2.32781e+08
ERR DEF= 0.5
MIGRAD FAILS TO FIND IMPROVEMENT
MIGRAD TERMINATED WITHOUT CONVERGENCE.
FCN=2497.32 FROM MIGRAD STATUS=FAILED 114 CALLS 115 TOTAL
EDM=10488.7 STRATEGY= 2 ERR MATRIX APPROXIMATE
EXT PARAMETER APPROXIMATE STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 a[0] 3.22085e+00 5.32309e-08 0.00000e+00 -1.62605e+09
2 a[1] 2.24987e+01 2.54012e-07 0.00000e+00 -2.32781e+08
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 2 ERR DEF=0.5
2.834e-15 1.320e-14
1.320e-14 6.452e-14
ERR MATRIX APPROXIMATE
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 1 2
1 0.97590 1.000 0.976
2 0.97590 0.976 1.000
ERR MATRIX APPROXIMATE

Best a0 = 3.22085
Best a1 = 22.4987
a_true[0] = 2.68
a_true[1] = 16.74

Hi,

Your minimisation fails because most likely to some numerical problem evaluating the function. Minuit fails to find a better (lower value) point along a given direction. The common cause for this is that when repeated evaluation of f(x) gives different results or when you have discontinuities in the function
I would need anyway your running code to understand it better

Best Regards

Lorenzo

Dear Lorenzo,

Thank you very much for your response. To this post, I have included a working copy of the code that I am running. I have commented it as best I can, but if there is something that is unclear please let me know. You will need to change the path for the output ROOT file on line 25. I’m beginning to think that implementing a line is not the best way to go, but I would like to hear your thoughts before I scrap the idea. Thank you again for your generous help.
likelihood_test.cxx (7.06 KB)

HI

There is an error in your code (actually it worked if compiled with -O2). You need to initialise to zero the variable logL inside your likelihood function implementation.
double logL; --> doubnle logL = 0;

Attached is the correct code. You can see I have modified it to use it the new MInimizer interface, which is now the recommended way to do the minimization instead of using the TFitter class, which will be deprecated in future ROOT versions

Cheers

Lorenzo
likelihood_test.cxx (7.55 KB)

Hi Lorenzo,

Thank you very much for taking the time to review my code and send me the errors I was making. I compiled and ran the code and it finds good agreement with the true value I set. However, after the minimization the code prints out the true values for the two parameters and then there is a segmentation fault. The only line after the cout statements for the true values is a return 0 in the main function. Below is the print out of the whole process without the text that usually comes after the “Break segmentation violation” statement:

Minuit2Minimizer: Minimize with max-calls 420 convergence for edm < 0.01 strategy 1
MnSeedGenerator: for initial parameters FCN = 2959.23
MnSeedGenerator: Initial state: - FCN = 2959.231924955 Edm = 784.96 NCalls = 9
VariableMetric: start iterating until Edm is < 2e-05
VariableMetric: Initial state - FCN = 2959.231924955 Edm = 784.96 NCalls = 9
VariableMetric: Iteration # 1 - FCN = 2222.552558332 Edm = 0.00962639 NCalls = 15
VariableMetric: Iteration # 2 - FCN = 2222.542256653 Edm = 2.36729e-23 NCalls = 21
VariableMetric: After Hessian - FCN = 2222.542256653 Edm = 2.44856e-23 NCalls = 31
Number of iterations 4
----------> Iteration 0
FVAL = 2959.23192496 Edm = 784.960063823 Nfcn = 9
Error matrix change = 1
Parameters : p0 = 2 p1 = 2
----------> Iteration 1
FVAL = 2222.55255833 Edm = 0.00962638977077 Nfcn = 15
Error matrix change = 0.515697
Parameters : p0 = 2.68288 p1 = 16.6844
----------> Iteration 2
FVAL = 2222.54225665 Edm = 2.36729279864e-23 Nfcn = 21
Error matrix change = 0.275248
Parameters : p0 = 2.68 p1 = 16.74
----------> Iteration 3
FVAL = 2222.54225665 Edm = 2.44855802448e-23 Nfcn = 31
Error matrix change = 0
Parameters : p0 = 2.68 p1 = 16.74
Minuit2Minimizer : Valid minimum - status = 0
FVAL = 2222.54225665287731
Edm = 2.44855802447509676e-23
Nfcn = 31
a[0] = 2.68 +/- 0.0379008
a[1] = 16.74 +/- 0.769926
a_true[0] = 2.68
a_true[1] = 16.74
OBJ: TObject TObject Basic ROOT object

*** Break *** segmentation violation

Do you have any ideas why this might be happening?

Hi,

I don’t have a seg fault with the program I have attached. If you have you modified the code, please send me the new version so I can check it

Lorenzo

Hi Lorenzo,

I have attached the code to this post. The only thing that I changed was the directory to store the output root file. I also noticed that the seg fault does not occur if I comment out the Write() statements on lines 84, 119, and 120. However, if I uncomment any one of them the program seg faults.
likelihood_test2.cxx (8.08 KB)

Hi,

I cannot reproduce the problem even with your macro. It is maybe something related to your system and the directory you are writing. Anyway, this has nothing to do with Minuit. If you have a problem writing to I/O I would suggest to open a new post (without Minuit) on this, with a simpler example reproducing your crash

Lorenzo

Hi Lorenzo,

Thank you very much for your help with everything. I greatly appreciate it. I will check with my colleagues to see if they have encountered this problem.

I had some further questions about the output of the macro from Minuit. Shall I post those questions here or in another post?