Minuit.draw_mnmatrix使用学习笔记
import numpy as np
from iminuit import Minuit
from iminuit.cost import UnbinnedNLL
from scipy.stats import norm
x = norm.rvs(size=1000, random_state=1)
def pdf(x, mu, sigma):
return norm.pdf(x, mu, sigma)
cost = UnbinnedNLL(x, pdf)
m = Minuit(cost, mu=0, sigma=1)
m.limits["sigma"] = (0, np.inf)
m.migrad() # find minimum
m.hesse() # compute uncertainties
m.migrad()
m.draw_mnmatrix();
m.draw_mncontour("α", "β", cl=(0.68, 0.9, 0.99));
pts = m.mncontour("α", "β", cl=0.68, size=20)
x, y = np.transpose(pts)
plt.plot(x, y, "o-");
为了使轮廓看起来更好,可以增加size参数或使用插值参数进行三次样条插值或使用实验算法。
# draw original points
plt.plot(x, y, ".", label="size=20")
# draw interpolated points
pts2 = m.mncontour("α", "β", cl=0.68, size=20, interpolated=100)
x2, y2 = np.transpose(pts2)
plt.plot(x2, y2, label="size=20, interpolated")
# actual curve at higher resolution
pts = m.mncontour("α", "β", cl=0.68, size=100)
x3, y3 = np.transpose(pts)
plt.plot(x3, y3, "-", label="size=100")
plt.legend()
①、绘制1D图
m.draw_mnprofile("α")
②、绘制2D图
m.draw_contour("α", "β")