Package: iminuit
iminuitis a Jupyter-friendly Python interface for theMinuit2C++ library maintained by CERN’sROOT team.Minuit was designed to optimize statistical cost functions, for maximum-likelihood and least-squares fits. It provides the best-fit parameters and error estimates from likelihood profile analysis.The iminuit package brings additional features:Builtin cost functions for statistical fits to N-dimensional dataUnbinned and binned maximum-likelihood + extended versionsTemplate fits with error propagationLeast-squares (optionally robust to outliers)Gaussian penalty terms for parametersCost functions can be combined by adding them:total_cost = cost_1 + cost_2Visualization of the fit in Jupyter notebooksSupport for SciPy minimizers as alternatives to Minuit’s MIGRAD algorithm (optional)Support for Numba accelerated functions (optional)Minimal dependenciesiminuitis promised to remain a lean package which only depends onnumpy, but additional features are enabled if the following optional packages are installed.numba: Cost functions are partially JIT-compiled ifnumbais installed.matplotlib: Visualization of fitted model for builtin cost functionsipywidgets: Interactive fitting, see example below (also requiresmatplotlib)scipy: Compute Minos intervals for arbitrary confidence levelsunicodeitplus: Render names of model parameters in simple LaTeX as UnicodeDocumentationCheckout our large and comprehensive list oftutorialsthat take you all the way from beginner to power user. For help and how-to questions, please use thediscussionson GitHub orgitter.Lecture by Glen CowanIn the exercises to his lecture for the KMISchool 2022, Glen Cowan shows how to solve statistical problems in Python with iminuit. You can find the lectures and exercises on the Github page, which covers both frequentist and Bayesian methods.Glen Cowanis a known for his papers and international lectures on statistics in particle physics, as a member of the Particle Data Group, and as author of the popular bookStatistical Data Analysis.In a nutshelliminuitcan be used with a user-provided cost functions in form of a negative log-likelihood function or least-squares function. Standard functions are included iniminuit.cost, so you don’t have to write them yourself. The following example shows how to perform an unbinned maximum likelihood fit.importnumpyasnpfromiminuitimportMinuitfromiminuit.costimportUnbinnedNLLfromscipy.statsimportnormx=norm.rvs(size=1000,random_state=1)defpdf(x,mu,sigma):returnnorm.pdf(x,mu,sigma)# Negative unbinned log-likelihood, you can write your owncost=UnbinnedNLL(x,pdf)m=Minuit(cost,mu=0,sigma=1)m.limits["sigma"]=(0,np.inf)m.migrad()# find minimumm.hesse()# compute uncertaintiesInteractive fittingiminuitoptionally supports an interactive fitting mode in Jupyter notebooks.High performance when combined with numbaWheniminuitis used with cost functions that are JIT-compiled withnumba(JIT-compiled pdfs are provided bynumba_stats), the speed is comparable toRooFitwith the fastest backend.numbawith auto-parallelization is considerably faster than the parallel computation inRooFit.More information about this benchmark is givenin the Benchmark section of the documentation.Partner projectsnumba_statsprovides faster implementations of probability density functions than scipy, and a few specific ones used in particle physics that are not in scipy.boost-histogramfrom Scikit-HEP provides fast generalized histograms that you can use with the builtin cost functions.jacobiprovides a robust, fast, and accurate calculation of the Jacobi matrix of any transformation function and building a function for generic error propagation.VersionsThe current 2.x series has introduced breaking interfaces changes with respect to the 1.x series.All interface changes are documented in thechangelogwith recommendations how to upgrade. To keep existing scripts running, pin your major iminuit version to <2, i.e.pip install 'iminuit<2'installs the 1.x series.