ML-Kurs-SS2023/notebooks/02_fit_ex_4_sol.ipynb

891 lines
154 KiB
Plaintext
Raw Permalink Normal View History

2023-04-05 16:48:43 +02:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Exercise 4: Least square fit to data"
]
},
{
"cell_type": "code",
"execution_count": 1,
2023-04-05 16:48:43 +02:00
"metadata": {},
"outputs": [],
"source": [
"from matplotlib import pyplot as plt\n",
"plt.rcParams[\"font.size\"] = 20\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 2,
2023-04-05 16:48:43 +02:00
"metadata": {},
"outputs": [],
"source": [
"# data\n",
"x = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], dtype='d')\n",
"dx = np.array([0.1,0.1,0.5,0.1,0.5,0.1,0.5,0.1,0.5,0.1], dtype='d')\n",
"y = np.array([1.1 ,2.3 ,2.7 ,3.2 ,3.1 ,2.4 ,1.7 ,1.5 ,1.5 ,1.7 ], dtype='d')\n",
"dy = np.array([0.15,0.22,0.29,0.39,0.31,0.21,0.13,0.15,0.19,0.13], dtype='d')"
]
},
{
"cell_type": "code",
"execution_count": 3,
2023-04-05 16:48:43 +02:00
"metadata": {},
"outputs": [],
"source": [
"# define fit function \n",
"def pol3(a0, a1, a2, a3):\n",
" return a0 + x*a1 + a2*x**2 + a3*x**3"
]
},
{
"cell_type": "code",
"execution_count": 4,
2023-04-05 16:48:43 +02:00
"metadata": {},
"outputs": [],
"source": [
"# least-squares function = sum of data residuals squared\n",
"def LSQ(a0, a1, a2, a3):\n",
" return np.sum((y - pol3(a0, a1, a2, a3)) ** 2 / dy ** 2)"
]
},
{
"cell_type": "code",
"execution_count": 5,
2023-04-05 16:48:43 +02:00
"metadata": {},
"outputs": [],
"source": [
"# import Minuit object\n",
"from iminuit import Minuit"
]
},
{
"cell_type": "code",
"execution_count": 6,
2023-04-05 16:48:43 +02:00
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th colspan=\"5\" style=\"text-align:center\" title=\"Minimizer\"> Migrad </th>\n",
" </tr>\n",
" <tr>\n",
" <td colspan=\"2\" style=\"text-align:left\" title=\"Minimum value of function\"> FCN = 3.719 </td>\n",
" <td colspan=\"3\" style=\"text-align:center\" title=\"Total number of function and (optional) gradient evaluations\"> Nfcn = 103 </td>\n",
" </tr>\n",
" <tr>\n",
" <td colspan=\"2\" style=\"text-align:left\" title=\"Estimated distance to minimum and goal\"> EDM = 4.33e-16 (Goal: 0.0002) </td>\n",
" <td colspan=\"3\" style=\"text-align:center\" title=\"Total run time of algorithms\"> </td>\n",
" </tr>\n",
" <tr>\n",
" <td colspan=\"2\" style=\"text-align:center;background-color:#92CCA6;color:black\"> Valid Minimum </td>\n",
" <td colspan=\"3\" style=\"text-align:center;background-color:#92CCA6;color:black\"> No Parameters at limit </td>\n",
" </tr>\n",
" <tr>\n",
" <td colspan=\"2\" style=\"text-align:center;background-color:#92CCA6;color:black\"> Below EDM threshold (goal x 10) </td>\n",
" <td colspan=\"3\" style=\"text-align:center;background-color:#92CCA6;color:black\"> Below call limit </td>\n",
" </tr>\n",
" <tr>\n",
" <td style=\"text-align:center;background-color:#92CCA6;color:black\"> Covariance </td>\n",
" <td style=\"text-align:center;background-color:#92CCA6;color:black\"> Hesse ok </td>\n",
" <td style=\"text-align:center;background-color:#92CCA6;color:black\" title=\"Is covariance matrix accurate?\"> Accurate </td>\n",
" <td style=\"text-align:center;background-color:#92CCA6;color:black\" title=\"Is covariance matrix positive definite?\"> Pos. def. </td>\n",
" <td style=\"text-align:center;background-color:#92CCA6;color:black\" title=\"Was positive definiteness enforced by Minuit?\"> Not forced </td>\n",
" </tr>\n",
"</table><table>\n",
" <tr>\n",
" <td></td>\n",
" <th title=\"Variable name\"> Name </th>\n",
" <th title=\"Value of parameter\"> Value </th>\n",
" <th title=\"Hesse error\"> Hesse Error </th>\n",
" <th title=\"Minos lower error\"> Minos Error- </th>\n",
" <th title=\"Minos upper error\"> Minos Error+ </th>\n",
" <th title=\"Lower limit of the parameter\"> Limit- </th>\n",
" <th title=\"Upper limit of the parameter\"> Limit+ </th>\n",
" <th title=\"Is the parameter fixed in the fit\"> Fixed </th>\n",
" </tr>\n",
" <tr>\n",
" <th> 0 </th>\n",
" <td> a0 </td>\n",
" <td> -0.98 </td>\n",
" <td> 0.34 </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> 1 </th>\n",
" <td> a1 </td>\n",
" <td> 2.52 </td>\n",
" <td> 0.30 </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> 2 </th>\n",
" <td> a2 </td>\n",
" <td> -0.48 </td>\n",
" <td> 0.06 </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> 3 </th>\n",
" <td> a3 </td>\n",
" <td> 0.0259 </td>\n",
" <td> 0.0035 </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" </tr>\n",
"</table><table>\n",
" <tr>\n",
" <td></td>\n",
" <th> a0 </th>\n",
" <th> a1 </th>\n",
" <th> a2 </th>\n",
" <th> a3 </th>\n",
" </tr>\n",
" <tr>\n",
" <th> a0 </th>\n",
" <td> 0.119 </td>\n",
" <td style=\"background-color:rgb(129,129,250);color:black\"> -0.096 <strong>(-0.931)</strong> </td>\n",
" <td style=\"background-color:rgb(250,118,118);color:black\"> 0.0183 <strong>(0.878)</strong> </td>\n",
" <td style=\"background-color:rgb(141,141,250);color:black\"> -0.000997 <strong>(-0.835)</strong> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> a1 </th>\n",
" <td style=\"background-color:rgb(129,129,250);color:black\"> -0.096 <strong>(-0.931)</strong> </td>\n",
" <td> 0.0893 </td>\n",
" <td style=\"background-color:rgb(122,122,250);color:black\"> -0.0178 <strong>(-0.987)</strong> </td>\n",
" <td style=\"background-color:rgb(250,106,106);color:black\"> 0.000996 <strong>(0.962)</strong> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> a2 </th>\n",
" <td style=\"background-color:rgb(250,118,118);color:black\"> 0.0183 <strong>(0.878)</strong> </td>\n",
" <td style=\"background-color:rgb(122,122,250);color:black\"> -0.0178 <strong>(-0.987)</strong> </td>\n",
" <td> 0.00366 </td>\n",
" <td style=\"background-color:rgb(121,121,250);color:black\"> -0.000208 <strong>(-0.993)</strong> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> a3 </th>\n",
" <td style=\"background-color:rgb(141,141,250);color:black\"> -0.000997 <strong>(-0.835)</strong> </td>\n",
" <td style=\"background-color:rgb(250,106,106);color:black\"> 0.000996 <strong>(0.962)</strong> </td>\n",
" <td style=\"background-color:rgb(121,121,250);color:black\"> -0.000208 <strong>(-0.993)</strong> </td>\n",
" <td> 1.2e-05 </td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"┌─────────────────────────────────────────────────────────────────────────┐\n",
"│ Migrad │\n",
"├──────────────────────────────────┬──────────────────────────────────────┤\n",
"│ FCN = 3.719 │ Nfcn = 103 │\n",
"│ EDM = 4.33e-16 (Goal: 0.0002) │ │\n",
"├──────────────────────────────────┼──────────────────────────────────────┤\n",
"│ Valid Minimum │ No Parameters at limit │\n",
"├──────────────────────────────────┼──────────────────────────────────────┤\n",
"│ Below EDM threshold (goal x 10) │ Below call limit │\n",
"├───────────────┬──────────────────┼───────────┬─────────────┬────────────┤\n",
"│ Covariance │ Hesse ok │ Accurate │ Pos. def. │ Not forced │\n",
"└───────────────┴──────────────────┴───────────┴─────────────┴────────────┘\n",
"┌───┬──────┬───────────┬───────────┬────────────┬────────────┬─────────┬─────────┬───────┐\n",
"│ │ Name │ Value │ Hesse Err │ Minos Err- │ Minos Err+ │ Limit- │ Limit+ │ Fixed │\n",
"├───┼──────┼───────────┼───────────┼────────────┼────────────┼─────────┼─────────┼───────┤\n",
"│ 0 │ a0 │ -0.98 │ 0.34 │ │ │ │ │ │\n",
"│ 1 │ a1 │ 2.52 │ 0.30 │ │ │ │ │ │\n",
"│ 2 │ a2 │ -0.48 │ 0.06 │ │ │ │ │ │\n",
"│ 3 │ a3 │ 0.0259 │ 0.0035 │ │ │ │ │ │\n",
"└───┴──────┴───────────┴───────────┴────────────┴────────────┴─────────┴─────────┴───────┘\n",
"┌────┬─────────────────────────────────────────┐\n",
"│ │ a0 a1 a2 a3 │\n",
"├────┼─────────────────────────────────────────┤\n",
"│ a0 │ 0.119 -0.096 0.0183 -0.000997 │\n",
"│ a1 │ -0.096 0.0893 -0.0178 0.000996 │\n",
"│ a2 │ 0.0183 -0.0178 0.00366 -0.000208 │\n",
"│ a3 │ -0.000997 0.000996 -0.000208 1.2e-05 │\n",
"└────┴─────────────────────────────────────────┘"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
2023-04-05 16:48:43 +02:00
"source": [
"# create instance of Minuit and use LSQ function to minimize\n",
"LSQ.errordef = Minuit.LEAST_SQUARES\n",
"m = Minuit(LSQ,a0=-1.3, a1=2.6 ,a2=-0.24 ,a3=0.005)\n",
"# run migrad \n",
"m.migrad()"
]
},
{
"cell_type": "code",
"execution_count": 7,
2023-04-05 16:48:43 +02:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Chi2/ndof = 0.6198527004952333\n"
]
}
],
2023-04-05 16:48:43 +02:00
"source": [
"# get function value at the minimum, which is per definition a chi2\n",
"# obtain chi2 / degree of freedom (dof)\n",
"chi2 = m.fval / (len(y) - len(m.values))\n",
"print (\"Chi2/ndof =\" , chi2)"
]
},
{
"cell_type": "code",
"execution_count": 8,
2023-04-05 16:48:43 +02:00
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th colspan=\"5\" style=\"text-align:center\" title=\"Minimizer\"> Migrad </th>\n",
" </tr>\n",
" <tr>\n",
" <td colspan=\"2\" style=\"text-align:left\" title=\"Minimum value of function\"> FCN = 3.719 </td>\n",
" <td colspan=\"3\" style=\"text-align:center\" title=\"Total number of function and (optional) gradient evaluations\"> Nfcn = 128 </td>\n",
" </tr>\n",
" <tr>\n",
" <td colspan=\"2\" style=\"text-align:left\" title=\"Estimated distance to minimum and goal\"> EDM = 1.06e-17 (Goal: 0.0002) </td>\n",
" <td colspan=\"3\" style=\"text-align:center\" title=\"Total run time of algorithms\"> </td>\n",
" </tr>\n",
" <tr>\n",
" <td colspan=\"2\" style=\"text-align:center;background-color:#92CCA6;color:black\"> Valid Minimum </td>\n",
" <td colspan=\"3\" style=\"text-align:center;background-color:#92CCA6;color:black\"> No Parameters at limit </td>\n",
" </tr>\n",
" <tr>\n",
" <td colspan=\"2\" style=\"text-align:center;background-color:#92CCA6;color:black\"> Below EDM threshold (goal x 10) </td>\n",
" <td colspan=\"3\" style=\"text-align:center;background-color:#92CCA6;color:black\"> Below call limit </td>\n",
" </tr>\n",
" <tr>\n",
" <td style=\"text-align:center;background-color:#92CCA6;color:black\"> Covariance </td>\n",
" <td style=\"text-align:center;background-color:#92CCA6;color:black\"> Hesse ok </td>\n",
" <td style=\"text-align:center;background-color:#92CCA6;color:black\" title=\"Is covariance matrix accurate?\"> Accurate </td>\n",
" <td style=\"text-align:center;background-color:#92CCA6;color:black\" title=\"Is covariance matrix positive definite?\"> Pos. def. </td>\n",
" <td style=\"text-align:center;background-color:#92CCA6;color:black\" title=\"Was positive definiteness enforced by Minuit?\"> Not forced </td>\n",
" </tr>\n",
"</table><table>\n",
" <tr>\n",
" <td></td>\n",
" <th title=\"Variable name\"> Name </th>\n",
" <th title=\"Value of parameter\"> Value </th>\n",
" <th title=\"Hesse error\"> Hesse Error </th>\n",
" <th title=\"Minos lower error\"> Minos Error- </th>\n",
" <th title=\"Minos upper error\"> Minos Error+ </th>\n",
" <th title=\"Lower limit of the parameter\"> Limit- </th>\n",
" <th title=\"Upper limit of the parameter\"> Limit+ </th>\n",
" <th title=\"Is the parameter fixed in the fit\"> Fixed </th>\n",
" </tr>\n",
" <tr>\n",
" <th> 0 </th>\n",
" <td> a0 </td>\n",
" <td> -0.98 </td>\n",
" <td> 0.34 </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> 1 </th>\n",
" <td> a1 </td>\n",
" <td> 2.52 </td>\n",
" <td> 0.30 </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> 2 </th>\n",
" <td> a2 </td>\n",
" <td> -0.48 </td>\n",
" <td> 0.06 </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> 3 </th>\n",
" <td> a3 </td>\n",
" <td> 0.0259 </td>\n",
" <td> 0.0035 </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" </tr>\n",
"</table><table>\n",
" <tr>\n",
" <td></td>\n",
" <th> a0 </th>\n",
" <th> a1 </th>\n",
" <th> a2 </th>\n",
" <th> a3 </th>\n",
" </tr>\n",
" <tr>\n",
" <th> a0 </th>\n",
" <td> 0.119 </td>\n",
" <td style=\"background-color:rgb(129,129,250);color:black\"> -0.0961 <strong>(-0.931)</strong> </td>\n",
" <td style=\"background-color:rgb(250,118,118);color:black\"> 0.0183 <strong>(0.878)</strong> </td>\n",
" <td style=\"background-color:rgb(141,141,250);color:black\"> -0.000999 <strong>(-0.835)</strong> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> a1 </th>\n",
" <td style=\"background-color:rgb(129,129,250);color:black\"> -0.0961 <strong>(-0.931)</strong> </td>\n",
" <td> 0.0895 </td>\n",
" <td style=\"background-color:rgb(122,122,250);color:black\"> -0.0179 <strong>(-0.987)</strong> </td>\n",
" <td style=\"background-color:rgb(250,106,106);color:black\"> 0.000997 <strong>(0.962)</strong> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> a2 </th>\n",
" <td style=\"background-color:rgb(250,118,118);color:black\"> 0.0183 <strong>(0.878)</strong> </td>\n",
" <td style=\"background-color:rgb(122,122,250);color:black\"> -0.0179 <strong>(-0.987)</strong> </td>\n",
" <td> 0.00366 </td>\n",
" <td style=\"background-color:rgb(121,121,250);color:black\"> -0.000208 <strong>(-0.993)</strong> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> a3 </th>\n",
" <td style=\"background-color:rgb(141,141,250);color:black\"> -0.000999 <strong>(-0.835)</strong> </td>\n",
" <td style=\"background-color:rgb(250,106,106);color:black\"> 0.000997 <strong>(0.962)</strong> </td>\n",
" <td style=\"background-color:rgb(121,121,250);color:black\"> -0.000208 <strong>(-0.993)</strong> </td>\n",
" <td> 1.2e-05 </td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"┌─────────────────────────────────────────────────────────────────────────┐\n",
"│ Migrad │\n",
"├──────────────────────────────────┬──────────────────────────────────────┤\n",
"│ FCN = 3.719 │ Nfcn = 128 │\n",
"│ EDM = 1.06e-17 (Goal: 0.0002) │ │\n",
"├──────────────────────────────────┼──────────────────────────────────────┤\n",
"│ Valid Minimum │ No Parameters at limit │\n",
"├──────────────────────────────────┼──────────────────────────────────────┤\n",
"│ Below EDM threshold (goal x 10) │ Below call limit │\n",
"├───────────────┬──────────────────┼───────────┬─────────────┬────────────┤\n",
"│ Covariance │ Hesse ok │ Accurate │ Pos. def. │ Not forced │\n",
"└───────────────┴──────────────────┴───────────┴─────────────┴────────────┘\n",
"┌───┬──────┬───────────┬───────────┬────────────┬────────────┬─────────┬─────────┬───────┐\n",
"│ │ Name │ Value │ Hesse Err │ Minos Err- │ Minos Err+ │ Limit- │ Limit+ │ Fixed │\n",
"├───┼──────┼───────────┼───────────┼────────────┼────────────┼─────────┼─────────┼───────┤\n",
"│ 0 │ a0 │ -0.98 │ 0.34 │ │ │ │ │ │\n",
"│ 1 │ a1 │ 2.52 │ 0.30 │ │ │ │ │ │\n",
"│ 2 │ a2 │ -0.48 │ 0.06 │ │ │ │ │ │\n",
"│ 3 │ a3 │ 0.0259 │ 0.0035 │ │ │ │ │ │\n",
"└───┴──────┴───────────┴───────────┴────────────┴────────────┴─────────┴─────────┴───────┘\n",
"┌────┬─────────────────────────────────────────┐\n",
"│ │ a0 a1 a2 a3 │\n",
"├────┼─────────────────────────────────────────┤\n",
"│ a0 │ 0.119 -0.0961 0.0183 -0.000999 │\n",
"│ a1 │ -0.0961 0.0895 -0.0179 0.000997 │\n",
"│ a2 │ 0.0183 -0.0179 0.00366 -0.000208 │\n",
"│ a3 │ -0.000999 0.000997 -0.000208 1.2e-05 │\n",
"└────┴─────────────────────────────────────────┘"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
2023-04-05 16:48:43 +02:00
"source": [
"# run covariance \n",
"m.hesse()"
]
},
{
"cell_type": "code",
"execution_count": 9,
2023-04-05 16:48:43 +02:00
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <td></td>\n",
" <th> a0 </th>\n",
" <th> a1 </th>\n",
" <th> a2 </th>\n",
" <th> a3 </th>\n",
" </tr>\n",
" <tr>\n",
" <th> a0 </th>\n",
" <td> 0.119 </td>\n",
" <td style=\"background-color:rgb(129,129,250);color:black\"> -0.0961 <strong>(-0.931)</strong> </td>\n",
" <td style=\"background-color:rgb(250,118,118);color:black\"> 0.0183 <strong>(0.878)</strong> </td>\n",
" <td style=\"background-color:rgb(141,141,250);color:black\"> -0.000999 <strong>(-0.835)</strong> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> a1 </th>\n",
" <td style=\"background-color:rgb(129,129,250);color:black\"> -0.0961 <strong>(-0.931)</strong> </td>\n",
" <td> 0.0895 </td>\n",
" <td style=\"background-color:rgb(122,122,250);color:black\"> -0.0179 <strong>(-0.987)</strong> </td>\n",
" <td style=\"background-color:rgb(250,106,106);color:black\"> 0.000997 <strong>(0.962)</strong> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> a2 </th>\n",
" <td style=\"background-color:rgb(250,118,118);color:black\"> 0.0183 <strong>(0.878)</strong> </td>\n",
" <td style=\"background-color:rgb(122,122,250);color:black\"> -0.0179 <strong>(-0.987)</strong> </td>\n",
" <td> 0.00366 </td>\n",
" <td style=\"background-color:rgb(121,121,250);color:black\"> -0.000208 <strong>(-0.993)</strong> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> a3 </th>\n",
" <td style=\"background-color:rgb(141,141,250);color:black\"> -0.000999 <strong>(-0.835)</strong> </td>\n",
" <td style=\"background-color:rgb(250,106,106);color:black\"> 0.000997 <strong>(0.962)</strong> </td>\n",
" <td style=\"background-color:rgb(121,121,250);color:black\"> -0.000208 <strong>(-0.993)</strong> </td>\n",
" <td> 1.2e-05 </td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"┌────┬─────────────────────────────────────────┐\n",
"│ │ a0 a1 a2 a3 │\n",
"├────┼─────────────────────────────────────────┤\n",
"│ a0 │ 0.119 -0.0961 0.0183 -0.000999 │\n",
"│ a1 │ -0.0961 0.0895 -0.0179 0.000997 │\n",
"│ a2 │ 0.0183 -0.0179 0.00366 -0.000208 │\n",
"│ a3 │ -0.000999 0.000997 -0.000208 1.2e-05 │\n",
"└────┴─────────────────────────────────────────┘"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
2023-04-05 16:48:43 +02:00
"source": [
"#get covariance matrix\n",
"m.covariance"
]
},
{
"cell_type": "code",
"execution_count": 10,
2023-04-05 16:48:43 +02:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"┌────┬─────────────────────────────────────────┐\n",
"│ │ a0 a1 a2 a3 │\n",
"├────┼─────────────────────────────────────────┤\n",
"│ a0 │ 0.119 -0.0961 0.0183 -0.000999 │\n",
"│ a1 │ -0.0961 0.0895 -0.0179 0.000997 │\n",
"│ a2 │ 0.0183 -0.0179 0.00366 -0.000208 │\n",
"│ a3 │ -0.000999 0.000997 -0.000208 1.2e-05 │\n",
"└────┴─────────────────────────────────────────┘\n"
]
}
],
2023-04-05 16:48:43 +02:00
"source": [
"#get correlation matrix in numpy array\n",
"cov = m.covariance\n",
"print (cov)"
]
},
{
"cell_type": "code",
"execution_count": 11,
2023-04-05 16:48:43 +02:00
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<table>\n",
" <tr>\n",
" <th colspan=\"5\" style=\"text-align:center\" title=\"Minimizer\"> Migrad </th>\n",
" </tr>\n",
" <tr>\n",
" <td colspan=\"2\" style=\"text-align:left\" title=\"Minimum value of function\"> FCN = 3.719 </td>\n",
" <td colspan=\"3\" style=\"text-align:center\" title=\"Total number of function and (optional) gradient evaluations\"> Nfcn = 300 </td>\n",
" </tr>\n",
" <tr>\n",
" <td colspan=\"2\" style=\"text-align:left\" title=\"Estimated distance to minimum and goal\"> EDM = 1.06e-17 (Goal: 0.0002) </td>\n",
" <td colspan=\"3\" style=\"text-align:center\" title=\"Total run time of algorithms\"> </td>\n",
" </tr>\n",
" <tr>\n",
" <td colspan=\"2\" style=\"text-align:center;background-color:#92CCA6;color:black\"> Valid Minimum </td>\n",
" <td colspan=\"3\" style=\"text-align:center;background-color:#92CCA6;color:black\"> No Parameters at limit </td>\n",
" </tr>\n",
" <tr>\n",
" <td colspan=\"2\" style=\"text-align:center;background-color:#92CCA6;color:black\"> Below EDM threshold (goal x 10) </td>\n",
" <td colspan=\"3\" style=\"text-align:center;background-color:#92CCA6;color:black\"> Below call limit </td>\n",
" </tr>\n",
" <tr>\n",
" <td style=\"text-align:center;background-color:#92CCA6;color:black\"> Covariance </td>\n",
" <td style=\"text-align:center;background-color:#92CCA6;color:black\"> Hesse ok </td>\n",
" <td style=\"text-align:center;background-color:#92CCA6;color:black\" title=\"Is covariance matrix accurate?\"> Accurate </td>\n",
" <td style=\"text-align:center;background-color:#92CCA6;color:black\" title=\"Is covariance matrix positive definite?\"> Pos. def. </td>\n",
" <td style=\"text-align:center;background-color:#92CCA6;color:black\" title=\"Was positive definiteness enforced by Minuit?\"> Not forced </td>\n",
" </tr>\n",
"</table><table>\n",
" <tr>\n",
" <td></td>\n",
" <th title=\"Variable name\"> Name </th>\n",
" <th title=\"Value of parameter\"> Value </th>\n",
" <th title=\"Hesse error\"> Hesse Error </th>\n",
" <th title=\"Minos lower error\"> Minos Error- </th>\n",
" <th title=\"Minos upper error\"> Minos Error+ </th>\n",
" <th title=\"Lower limit of the parameter\"> Limit- </th>\n",
" <th title=\"Upper limit of the parameter\"> Limit+ </th>\n",
" <th title=\"Is the parameter fixed in the fit\"> Fixed </th>\n",
" </tr>\n",
" <tr>\n",
" <th> 0 </th>\n",
" <td> a0 </td>\n",
" <td> -0.98 </td>\n",
" <td> 0.35 </td>\n",
" <td> -0.34 </td>\n",
" <td> 0.34 </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> 1 </th>\n",
" <td> a1 </td>\n",
" <td> 2.52 </td>\n",
" <td> 0.30 </td>\n",
" <td> -0.30 </td>\n",
" <td> 0.30 </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> 2 </th>\n",
" <td> a2 </td>\n",
" <td> -0.48 </td>\n",
" <td> 0.06 </td>\n",
" <td> -0.06 </td>\n",
" <td> 0.06 </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> 3 </th>\n",
" <td> a3 </td>\n",
" <td> 0.0259 </td>\n",
" <td> 0.0035 </td>\n",
" <td> -0.0035 </td>\n",
" <td> 0.0035 </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" <td> </td>\n",
" </tr>\n",
"</table><table>\n",
" <tr>\n",
" <td></td>\n",
" <th colspan=\"2\" style=\"text-align:center\" title=\"Parameter name\"> a0 </th>\n",
" <th colspan=\"2\" style=\"text-align:center\" title=\"Parameter name\"> a1 </th>\n",
" <th colspan=\"2\" style=\"text-align:center\" title=\"Parameter name\"> a2 </th>\n",
" <th colspan=\"2\" style=\"text-align:center\" title=\"Parameter name\"> a3 </th>\n",
" </tr>\n",
" <tr>\n",
" <th title=\"Lower and upper minos error of the parameter\"> Error </th>\n",
" <td> -0.34 </td>\n",
" <td> 0.34 </td>\n",
" <td> -0.3 </td>\n",
" <td> 0.3 </td>\n",
" <td> -0.06 </td>\n",
" <td> 0.06 </td>\n",
" <td> -0.0035 </td>\n",
" <td> 0.0035 </td>\n",
" </tr>\n",
" <tr>\n",
" <th title=\"Validity of lower/upper minos error\"> Valid </th>\n",
" <td style=\"background-color:#92CCA6;color:black\"> True </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> True </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> True </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> True </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> True </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> True </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> True </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> True </td>\n",
" </tr>\n",
" <tr>\n",
" <th title=\"Did scan hit limit of any parameter?\"> At Limit </th>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" </tr>\n",
" <tr>\n",
" <th title=\"Did scan hit function call limit?\"> Max FCN </th>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" </tr>\n",
" <tr>\n",
" <th title=\"New minimum found when doing scan?\"> New Min </th>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" <td style=\"background-color:#92CCA6;color:black\"> False </td>\n",
" </tr>\n",
"</table><table>\n",
" <tr>\n",
" <td></td>\n",
" <th> a0 </th>\n",
" <th> a1 </th>\n",
" <th> a2 </th>\n",
" <th> a3 </th>\n",
" </tr>\n",
" <tr>\n",
" <th> a0 </th>\n",
" <td> 0.119 </td>\n",
" <td style=\"background-color:rgb(129,129,250);color:black\"> -0.0961 <strong>(-0.931)</strong> </td>\n",
" <td style=\"background-color:rgb(250,118,118);color:black\"> 0.0183 <strong>(0.878)</strong> </td>\n",
" <td style=\"background-color:rgb(141,141,250);color:black\"> -0.000999 <strong>(-0.835)</strong> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> a1 </th>\n",
" <td style=\"background-color:rgb(129,129,250);color:black\"> -0.0961 <strong>(-0.931)</strong> </td>\n",
" <td> 0.0895 </td>\n",
" <td style=\"background-color:rgb(122,122,250);color:black\"> -0.0179 <strong>(-0.987)</strong> </td>\n",
" <td style=\"background-color:rgb(250,106,106);color:black\"> 0.000997 <strong>(0.962)</strong> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> a2 </th>\n",
" <td style=\"background-color:rgb(250,118,118);color:black\"> 0.0183 <strong>(0.878)</strong> </td>\n",
" <td style=\"background-color:rgb(122,122,250);color:black\"> -0.0179 <strong>(-0.987)</strong> </td>\n",
" <td> 0.00366 </td>\n",
" <td style=\"background-color:rgb(121,121,250);color:black\"> -0.000208 <strong>(-0.993)</strong> </td>\n",
" </tr>\n",
" <tr>\n",
" <th> a3 </th>\n",
" <td style=\"background-color:rgb(141,141,250);color:black\"> -0.000999 <strong>(-0.835)</strong> </td>\n",
" <td style=\"background-color:rgb(250,106,106);color:black\"> 0.000997 <strong>(0.962)</strong> </td>\n",
" <td style=\"background-color:rgb(121,121,250);color:black\"> -0.000208 <strong>(-0.993)</strong> </td>\n",
" <td> 1.2e-05 </td>\n",
" </tr>\n",
"</table>"
],
"text/plain": [
"┌─────────────────────────────────────────────────────────────────────────┐\n",
"│ Migrad │\n",
"├──────────────────────────────────┬──────────────────────────────────────┤\n",
"│ FCN = 3.719 │ Nfcn = 300 │\n",
"│ EDM = 1.06e-17 (Goal: 0.0002) │ │\n",
"├──────────────────────────────────┼──────────────────────────────────────┤\n",
"│ Valid Minimum │ No Parameters at limit │\n",
"├──────────────────────────────────┼──────────────────────────────────────┤\n",
"│ Below EDM threshold (goal x 10) │ Below call limit │\n",
"├───────────────┬──────────────────┼───────────┬─────────────┬────────────┤\n",
"│ Covariance │ Hesse ok │ Accurate │ Pos. def. │ Not forced │\n",
"└───────────────┴──────────────────┴───────────┴─────────────┴────────────┘\n",
"┌───┬──────┬───────────┬───────────┬────────────┬────────────┬─────────┬─────────┬───────┐\n",
"│ │ Name │ Value │ Hesse Err │ Minos Err- │ Minos Err+ │ Limit- │ Limit+ │ Fixed │\n",
"├───┼──────┼───────────┼───────────┼────────────┼────────────┼─────────┼─────────┼───────┤\n",
"│ 0 │ a0 │ -0.98 │ 0.35 │ -0.34 │ 0.34 │ │ │ │\n",
"│ 1 │ a1 │ 2.52 │ 0.30 │ -0.30 │ 0.30 │ │ │ │\n",
"│ 2 │ a2 │ -0.48 │ 0.06 │ -0.06 │ 0.06 │ │ │ │\n",
"│ 3 │ a3 │ 0.0259 │ 0.0035 │ -0.0035 │ 0.0035 │ │ │ │\n",
"└───┴──────┴───────────┴───────────┴────────────┴────────────┴─────────┴─────────┴───────┘\n",
"┌──────────┬───────────────────────┬───────────────────────┬───────────────────────┬───────────────────────┐\n",
"│ │ a0 │ a1 │ a2 │ a3 │\n",
"├──────────┼───────────┬───────────┼───────────┬───────────┼───────────┬───────────┼───────────┬───────────┤\n",
"│ Error │ -0.34 │ 0.34 │ -0.3 │ 0.3 │ -0.06 │ 0.06 │ -0.0035 │ 0.0035 │\n",
"│ Valid │ True │ True │ True │ True │ True │ True │ True │ True │\n",
"│ At Limit │ False │ False │ False │ False │ False │ False │ False │ False │\n",
"│ Max FCN │ False │ False │ False │ False │ False │ False │ False │ False │\n",
"│ New Min │ False │ False │ False │ False │ False │ False │ False │ False │\n",
"└──────────┴───────────┴───────────┴───────────┴───────────┴───────────┴───────────┴───────────┴───────────┘\n",
"┌────┬─────────────────────────────────────────┐\n",
"│ │ a0 a1 a2 a3 │\n",
"├────┼─────────────────────────────────────────┤\n",
"│ a0 │ 0.119 -0.0961 0.0183 -0.000999 │\n",
"│ a1 │ -0.0961 0.0895 -0.0179 0.000997 │\n",
"│ a2 │ 0.0183 -0.0179 0.00366 -0.000208 │\n",
"│ a3 │ -0.000999 0.000997 -0.000208 1.2e-05 │\n",
"└────┴─────────────────────────────────────────┘"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
2023-04-05 16:48:43 +02:00
"source": [
"# run minos error analysis\n",
"# The Minos algorithm uses the profile likelihood method to compute\n",
"# (generally asymmetric) confidence intervals.\n",
"m.minos()"
]
},
{
"cell_type": "code",
"execution_count": 12,
2023-04-05 16:48:43 +02:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.contour.ContourSet at 0x7fa018346ee0>"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAm0AAAHMCAYAAACHo59oAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/P9b71AAAACXBIWXMAAA9hAAAPYQGoP6dpAADfD0lEQVR4nOzddZhU1R/H8feZmd3Zbrq7u0u6GwFJAQHpH42A0tKgEhIiEgIS0ilKSXd3dy3bMX1+f9xlEcldFgT2vJ6H51nv3LnnzIjy4d5zvl8hpZQoiqIoiqIo7zXdfz0BRVEURVEU5dVUaFMURVEURfkAqNCmKIqiKIryAVChTVEURVEU5QOgQpuiKIqiKMoHQIU2RVEURVGUD4AKbYqiKIqiKB8Aw389ASVhOBwO7ty5g6enJ0KI/3o6iqIoiqK8Bikl4eHhpEyZEp3u5ffSVGj7SNy5c4c0adL819NQFEVRFCUebt68SerUqV96jgptHwlPT08Arp+oh5dfcTCtAce9JycYsiNc6oFrNYTO+7+ZpKIoiqIoTwkLCyNNmjSxf46/jFBtrD4OYWFheHt7E3yxEN4ZNoHOFyx7kdHLwPQXYI050xlcqiJcPwXn4gihljUqiqIoyn/l8Z/foaGheHl5vfRc9Sf2x0YGI8O+AXQIY2l0PpMQSXchPL8GQzbAAqa1yODWyMBKyIipSPud/3rWiqIoiqK8ggptHx0nMG+F6OWxR4TOF+HeCuG/BuG/HFybgvAA+y1kxGTkw/I4gtoiozcgpeU/nLuiKIqiKC/yUYS2Gzdu0KdPH3LkyIG7uzt+fn4ULVqUCRMmEBUVlWDjLF68mKpVq5IiRQpcXFxInz49LVu2ZN++ffG+5rRp0xBCxP6aO3fuG81RuHcGQIaPRNpuPv2aEAinPOi8hyGS7kZ4jwfnYoAEy05kaA/kgzLIyHkqvCmKoij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OPH5uGhITQokWLV445Y8YMZsyYAcC2bdveSmgDEIZ04DcPGdQSbGeRQV/EBDfPV7/5tcdID74/g3kzMmyUtpYupBMYy4HnNwhD2gQbS1EURVE+dh/k41GA0qVLA9pjycOHD7/wvB07dsT+XKpUqTiNUaRIkdgNCP+8zr9ZLBb27dv3zHved9o6tLkxXRNOIYO/TPBHmNoj06qIgI3g3gFwAvN2rSVW+GSkNL3yGoqiKIqifMChrV69erE/z5kz57nnOBwO5s+fD4CPjw/ly5eP0xienp5UrFgRgL/++uuFj2JXrFgRWyetfv36T702dOhQpJQv/fXP+c+ZMyf2eLly5eI03/gQTlkRfnNBeIL1MDK4W5z6lL72ODo3dJ69EQFrwbkkYIHIqcjAmkjTtgQfT1EURVE+Nh9saCtatChlypQBYPbs2ezdu/eZcyZOnBjb1aB79+44OTk99frcuXO1O0FCMHTo0OeO83gTgc1mo0uXLtjt9qdeDwwM5KuvvgK0YNiuXbs3+lz/BeGUE+H7E+AClr+Rof2Q0v7K98VrLENGhO8chM8krauC/SYypENMYd74F/1VFEVRlI/dBxvaACZNmoSrqys2m40qVaowevRo9u3bx7Zt2+jQoQP9+vUDIGvWrPTu3TteY1SoUIEmTZoAsGbNGipXrsyaNWs4dOgQc+bMoXjx4ty4cQOAMWPG4OvrmzAf7h0TzoUQvj8CTmDagAwb+tZqrGmPTKsjAjaBe3vAEFOYtwYyYiZSvrh3q6IoiqIkVh/sRgSAAgUKsGTJElq0aEFYWBgDBw585pysWbOyfv36p8p3xNUvv/xCWFgYGzZsYNu2bWzb9vTjPJ1Ox6BBg+jQoUO8x3gfCGMZ8JmADOkJ0UuQOi+EZ9+3N57OHeHZN2aX6XCw7ENGTATTOvAagXDO/9bGVhRFUZQPzQd
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
2023-04-05 16:48:43 +02:00
"source": [
"# Get a 2D contour of the function around the minimum for 2 parameters\n",
"# and draw a 2 D contours up to 4 sigma of a1 and a2 \n",
"#m.draw_profile(\"a1\")\n",
"m.draw_mncontour(\"a2\", \"a3\", cl=[1, 2, 3, 4])"
]
},
{
"cell_type": "code",
"execution_count": 13,
2023-04-05 16:48:43 +02:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<ValueView a0=-0.9807363849012718 a1=2.520457666696189 a2=-0.484056651556402 a3=0.02590585286811066> <ErrorView a0=0.3452141046758837 a1=0.2991369099052406 a2=0.06052732413714454 a3=0.003463469704203838>\n"
]
}
],
2023-04-05 16:48:43 +02:00
"source": [
"print(m.values,m.errors)\n",
"a0_fit = m.values[\"a0\"]\n",
"a1_fit = m.values[\"a1\"]\n",
"a2_fit = m.values[\"a2\"]\n",
"a3_fit = m.values[\"a3\"]"
]
},
{
"cell_type": "code",
"execution_count": 14,
2023-04-05 16:48:43 +02:00
"metadata": {},
"outputs": [],
"source": [
"# display fitted function \n",
"x_plot = np.linspace( 0.1, 10.1 , 200 )\n",
"y_fit = a0_fit + a1_fit * x_plot + a2_fit * x_plot**2 + a3_fit * x_plot**3"
]
},
{
"cell_type": "code",
"execution_count": 15,
2023-04-05 16:48:43 +02:00
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAloAAAHvCAYAAACMtHGxAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/P9b71AAAACXBIWXMAAA9hAAAPYQGoP6dpAABgd0lEQVR4nO3dd3gU5f7+8femk4SE3kMnFEGQElFAegcRUCxUBQtHLEex/yTY0aOox/MVBRFUEERRRECkSQcJvffeewKkJ/P7Y8hCIAkpu5ndzf26rr12dnd25pPdbPbO88w8j80wDAMRERERcTgvqwsQERER8VQKWiIiIiJOoqAlIiIi4iQKWiIiIiJOoqAlIiIi4iQKWiIiIiJOoqAlIiIi4iQKWiIiIiJOoqAlIiIi4iQKWiK3ULlyZWw2GzabjYMHD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oXLnzT+pmFF2f7+eef6du3L0lJSQAEBATQtGlTKleujLe3N7t372bVqlUkJyezevVq7rrrLqKioihduvRN2xo+fHi6kFW+fHkiIiIoUaIEhmFw7tw5tm/fzq5duzKsJe31+u233zh+/DgA9913X4avTe3atfP8s4s4jCEiWapUqZIBGIBx4MCBDNdp2bKlfR0/Pz/Dz8/PGDdunJGamppuvenTpxs+Pj72dUePHm14eXkZYWFhxooVK9Ktm5KSYrz00kv2dYODg43Lly9nuP+///7bvl7Lli0zXOfAgQPparTZbEa1atWMf/7556Z1p02bZvj6+trX/+677265zUqVKmW4zo1y+nr+/fffGa4TGRlpXycyMjJb+86J62vIzfaz+9pk5/VwtOv3OWHChAzX2bp1qxEYGGhf7/nnnzfOnTt303r79u0zmjdvbl+vc+fON61z5swZ+++9t7e3MXHixJs+G2mOHz9u/Pe//zW++eabDB/Pzu+GiCtRi5aIgyUmJjJx4kQGDhx402O9evVi8ODBfP311wC88MILBAYGMn/+fGrWrJluXS8vL0aNGsWsWbPYsWMHly9fZtasWTz44IMOqbF48eIsXbqUcuXK3fT4Aw88wJo1a/j4448BmDJlCgMGDMjzft3VnDlzOHv27C3Xe+211yxrfXK0Z599ltjYWADefffdTFtTq1atyty5c2nSpAk7duzgzz//5J9//uHOO++0r7N69WqSk5MBeOihhzL8bKQpW7YszzzzjAN/EhFrKWiJONgdd9yR5RfJgw8+aA9aAE899dRNISuNl5cXDzzwgL2LLyoqyiFBC+D111/PMGSleeyxx+xBK62LrqBKO2btVoYMGeIRQWvTpk0sWrQIgPDwcF599dUs1w8KCmLEiBE8/PDDAEyePDld0IqJibEvWz2gq0h+01mHIg7Wu3fvLB+vW7durtc/cOBA7gu7wQMPPJDl47Vq1aJQoUIAnDt3jsuXLzts3+La5syZY19+4IEHsnUSRps2bezLy5cvT/dYxYoV7cvTp0/n5MmTDqhSxD2oRUvEwW677bYsH0870zBNnTp1sr3+9S0DeREaGkpYWFiW69hsNooWLWo/zT46Oprg4GCH7N/dREZGuvV8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8OGDQkMDLSvM3ToUKpVq5avddWtW5cpU6bw4IMPEhsby65du2jfvj1hYWE0adKEEiVKkJiYyJkzZ9i0aRNHjx7NcnubNm3i6aefZtiwYVSrVo26detSokQJkpKSOH78OCtXruTKlSv29V999dUMB9Xt1asXr732GoZhMHv2bG6//XbuvvvudMcLPvTQQzRu3NhxL4ZIHihoiUie+Pj48Ntvv9GuXTv2798PwPr161m/fr19HZvNxuuvv86IESOYMGGCQ/br5eXFmDFj6NW
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
2023-04-05 16:48:43 +02:00
"source": [
"# plot data \n",
"plt.figure()\n",
"plt.errorbar(x, y, dy , dx, fmt=\"o\")\n",
"plt.plot(x_plot,y_fit )\n",
"plt.title(\"iminuit Fit Test\")\n",
"plt.xlabel('x')\n",
"plt.ylabel('f(x)')\n",
"plt.xlim(-0.1, 10.1)\n",
"\n",
"# show the plot\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.16"
}
},
"nbformat": 4,
"nbformat_minor": 4
}