def test_mnprofile(): m = Minuit(f1, x=0, y=0, pedantic=False, print_level=1) m.tol=1e-4 m.migrad() assert_less(m.fval, 1e-6) assert_almost_equal(m.values['x'], 1., places=3) assert_almost_equal(m.values['y'], 1., places=3) m.minos('x') m.draw_mnprofile('x')
from iminuit import Minuit def f(x, y, z): return (x - 1)**2 + (y - x)**2 + (z - 2)**2 m = Minuit(f, print_level=0, pedantic=False) m.migrad() m.draw_mnprofile('y')
from iminuit import Minuit def f(x, y, z): return (x-1)**2 + (y-x)**2 + (z-2)**2 m = Minuit(f, print_level=0, pedantic=False) m.migrad() m.draw_mnprofile('y')
from iminuit import Minuit def cost(x, y, z): return (x - 1) ** 2 + (y - x) ** 2 + (z - 2) ** 2 cost.errordef = Minuit.LEAST_SQUARES m = Minuit(cost, x=0, y=0, z=0) m.migrad() m.draw_mnprofile("y")
# definition of the cost function to minimize, examplary chisquare def chisquare_1d(a, b, c): resid = ydat - fit_fun(xdat, a, b, c) return (1.0 / (npts - 1.0)) * np.sum(resid**2 / yerr**2) print(chisquare_1d(-1.0 / 500, 250.0 / 500.0, 0)) m = Minuit( chisquare_1d, a=-1.0 / 750.0, # set start parameter #limit_a= (limit_lower,limit_upper) # if you want to limit things #fix_a = "True", # you can also fix it b=1000.0, c=200.0, errordef=1, print_level=1) m.migrad(ncall=500000) #m.minos(), if you need fancy mapping plt.plot(xdat, ydat) plt.plot(xdat, fit_fun(xdat, m.values["a"], m.values["b"], m.values["c"])) # plt.xlim(3500,4000) plt.show() m.draw_mnprofile('a', bound=5, bins=100) plt.show()