Skip to content

rhoef/iminuit

 
 

Repository files navigation

iminuit

https://coveralls.io/repos/github/scikit-hep/iminuit/badge.svg?branch=develop https://readthedocs.org/projects/iminuit/badge/?version=latest ascl:2108.024 https://img.shields.io/gitter/room/Scikit-HEP/iminuit

iminuit is a Jupyter-friendly Python interface for the Minuit2 C++ library maintained by CERN's ROOT team.

Minuit was designed to minimise statistical cost functions, for likelihood and least-squares fits of parametric models to data. It provides the best-fit parameters and error estimates from likelihood profile analysis.

  • Supported CPython versions: 3.6+
  • Supported PyPy versions: 3.6+
  • Supported platforms: Linux, OSX and Windows.

The iminuit package comes with additional features:

  • Builtin cost functions for statistical fits
    • Binned and unbinned maximum-likelihood
    • Non-linear regression with (optionally robust) weighted least-squares
    • Gaussian penalty terms
    • Cost functions can be combined by adding them: total_cost = cost_1 + cost_2
  • Support for SciPy minimisers as alternatives to Minuit's Migrad algorithm (optional)
  • Support for Numba accelerated functions (optional)

Checkout our large and comprehensive list of tutorials that take you all the way from beginner to power user. For help and how-to questions, please use the discussions on GitHub or gitter.

In a nutshell

iminuit is intended to be used with a user-provided negative log-likelihood function or least-squares function. Standard functions are included in iminuit.cost, so you don't have to write them yourself. The following example shows how iminuit is used with a dummy least-squares function.

from iminuit import Minuit

def cost_function(x, y, z):
    return (x - 2) ** 2 + (y - 3) ** 2 + (z - 4) ** 2

m = Minuit(cost_function, x=0, y=0, z=0)

m.migrad()  # run optimiser
m.hesse()   # run covariance estimator

print(m.values)  # x: 2, y: 3, z: 4
print(m.errors)  # x: 1, y: 1, z: 1

Interactive fitting

iminuit optionally supports an interactive fitting mode in Jupyter notebooks.

Animated demo of an interactive fit in a Jupyter notebook

Partner projects

  • numba_stats provides faster implementations of probability density functions than scipy, and a few specific ones used in particle physics that are not in scipy.
  • jacobi provides a robust, fast, and accurate calculation of the Jacobi matrix of any transformation function and building a function for generic error propagation.

Versions

The current 2.x series has introduced breaking interfaces changes with respect to the 1.x series.

All interface changes are documented in the changelog with 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.

About

Interactive Minimization Tools based on Minuit

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 86.2%
  • C++ 10.5%
  • HTML 1.9%
  • Other 1.4%