Using external minimizers
We show how to use an external minimizer to find the minimum of a function and then use iminuit to compute the parameter uncertainties.
We will demonstrate this with a maximum-likelihood fit of a normal distribution, which is carried out with scipy.optimize.minimize
. iminuit is then used to compute the parameter uncertainties.
Note: iminuit can call the scipy minimizers directly with Minuit.scipy
, so scipy.optimize.minimize
is only used here to demonstrate the general approach.
fun: 1405.1044194490182
hess_inv: array([[0.00126239, 0.00010286],
[0.00010286, 0.00041427]])
jac: array([ 3.05175781e-05, -1.52587891e-05])
message: 'Desired error not necessarily achieved due to precision loss.'
nfev: 129
nit: 11
njev: 39
status: 2
success: False
x: array([-0.05425323, 0.98626112])
External |
FCN = 1405 |
Nfcn = 25 |
EDM = 3.03e-13 (Goal: 0.0001) |
|
Valid Minimum |
No Parameters at limit |
Below EDM threshold (goal x 10) |
Below call limit |
Covariance |
Hesse ok |
Accurate |
Pos. def. |
Not forced |
|
Name |
Value |
Hesse Error |
Minos Error- |
Minos Error+ |
Limit- |
Limit+ |
Fixed |
0 |
x0 |
-0.054 |
0.031 |
|
|
|
|
|
1 |
x1 |
0.986 |
0.022 |
|
|
|
|
|
|
x0 |
x1 |
x0 |
0.000973 |
0 |
x1 |
0 |
0.000486 |
We can also compute the “Hesse errors” at any other point than the minimum. These cannot be interpreted as parameter uncertainties, they are just some numbers related to the second derivative of the cost function at that point.
External |
FCN = 4394 |
Nfcn = 48 |
EDM = 2.42e+03 (Goal: 0.0001) |
|
INVALID Minimum |
No Parameters at limit |
ABOVE EDM threshold (goal x 10) |
Below call limit |
Covariance |
Hesse ok |
Accurate |
Pos. def. |
Not forced |
|
Name |
Value |
Hesse Error |
Minos Error- |
Minos Error+ |
Limit- |
Limit+ |
Fixed |
0 |
x0 |
1.000 |
0.031 |
|
|
|
|
|
1 |
x1 |
0.500 |
0.006 |
|
|
|
|
|
|
x0 |
x1 |
x0 |
0.000964 |
0.000169 (0.861) |
x1 |
0.000169 (0.861) |
4.01e-05 |
Minuit now reports that the minimum is invalid, which is correct, but it does not matter for the Hesse errors, which are computed anyway.
Likewise, it one can also run MINOS to get MINOS estimates. Note that MINOS can fail if the starting point is not actually a minimum. So here we reset the values to the solution found by scipy.optimize.
External |
FCN = 1405 |
Nfcn = 99 |
EDM = 3.03e-13 (Goal: 0.0001) |
|
Valid Minimum |
No Parameters at limit |
Below EDM threshold (goal x 10) |
Below call limit |
Covariance |
Hesse ok |
Accurate |
Pos. def. |
Not forced |
|
Name |
Value |
Hesse Error |
Minos Error- |
Minos Error+ |
Limit- |
Limit+ |
Fixed |
0 |
x0 |
-0.054 |
0.031 |
-0.031 |
0.031 |
|
|
|
1 |
x1 |
0.986 |
0.022 |
-0.022 |
0.022 |
|
|
|
|
x0 |
x1 |
Error |
-0.031 |
0.031 |
-0.022 |
0.022 |
Valid |
True |
True |
True |
True |
At Limit |
False |
False |
False |
False |
Max FCN |
False |
False |
False |
False |
New Min |
False |
False |
False |
False |
|
x0 |
x1 |
x0 |
0.000973 |
0 |
x1 |
0 |
0.000486 |
We can see that MINOS ran successfully. The Hesse Errors were also updated, because MINOS needs HESSE to run first. HESSE is called automatically in this case.