Skip to main content

Jupyter-friendly Python frontend for MINUIT2 in C++

Project description

https://scikit-hep.org/assets/images/Scikit--HEP-Project-blue.svg https://img.shields.io/pypi/v/iminuit.svg https://img.shields.io/conda/vn/conda-forge/iminuit.svg https://coveralls.io/repos/github/scikit-hep/iminuit/badge.svg?branch=develop https://github.com/scikit-hep/iminuit/actions/workflows/docs.yml/badge.svg?branch=main https://zenodo.org/badge/DOI/10.5281/zenodo.3949207.svg ascl:2108.024 https://img.shields.io/gitter/room/Scikit-HEP/iminuit https://mybinder.org/badge_logo.svg

iminuit is a Jupyter-friendly Python interface for the Minuit2 C++ library maintained by CERN’s ROOT 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 data

    • Unbinned and binned maximum-likelihood + extended versions

    • Template fits with error propagation

    • Least-squares (optionally robust to outliers)

    • Gaussian penalty terms for parameters

    • Cost functions can be combined by adding them: total_cost = cost_1 + cost_2

    • Visualization of the fit in Jupyter notebooks

  • Support for SciPy minimizers as alternatives to Minuit’s MIGRAD algorithm (optional)

  • Support for Numba accelerated functions (optional)

Minimal dependencies

iminuit is promised to remain a lean package which only depends on numpy, but additional features are enabled if the following optional packages are installed.

  • numba: Cost functions are partially JIT-compiled if numba is installed.

  • matplotlib: Visualization of fitted model for builtin cost functions

  • ipywidgets: Interactive fitting, see example below (also requires matplotlib)

  • scipy: Compute Minos intervals for arbitrary confidence levels

  • unicodeitplus: Render names of model parameters in simple LaTeX as Unicode

Documentation

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.

Lecture by Glen Cowan

In 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 Cowan is 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 book Statistical Data Analysis.

In a nutshell

iminuit can be used with a user-provided cost functions in form of a 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 to perform an unbinned maximum likelihood fit.

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)

# Negative unbinned log-likelihood, you can write your own
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
Output of the demo in a Jupyter notebook

Interactive fitting

iminuit optionally supports an interactive fitting mode in Jupyter notebooks.

Animated demo of an interactive fit in a Jupyter notebook

High performance when combined with numba

When iminuit is used with cost functions that are JIT-compiled with numba (JIT-compiled pdfs are provided by numba_stats ), the speed is comparable to RooFit with the fastest backend. numba with auto-parallelization is considerably faster than the parallel computation in RooFit.

doc/_static/roofit_vs_iminuit+numba.svg

More information about this benchmark is given in the Benchmark section of the documentation.

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.

  • boost-histogram from Scikit-HEP provides fast generalized histograms that you can use with the builtin cost functions.

  • 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.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iminuit-2.25.2.tar.gz (2.9 MB view hashes)

Uploaded Source

Built Distributions

iminuit-2.25.2-cp312-cp312-win_amd64.whl (361.3 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

iminuit-2.25.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (423.9 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

iminuit-2.25.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (391.9 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

iminuit-2.25.2-cp312-cp312-macosx_10_9_universal2.whl (708.0 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ universal2 (ARM64, x86-64)

iminuit-2.25.2-cp311-cp311-win_amd64.whl (361.3 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

iminuit-2.25.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (426.3 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

iminuit-2.25.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (395.0 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

iminuit-2.25.2-cp311-cp311-macosx_10_9_universal2.whl (703.7 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

iminuit-2.25.2-cp310-cp310-win_amd64.whl (360.3 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

iminuit-2.25.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (424.9 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

iminuit-2.25.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (393.8 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

iminuit-2.25.2-cp310-cp310-macosx_10_9_universal2.whl (701.4 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

iminuit-2.25.2-cp39-cp39-win_amd64.whl (360.4 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

iminuit-2.25.2-cp39-cp39-win32.whl (311.0 kB view hashes)

Uploaded CPython 3.9 Windows x86

iminuit-2.25.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (394.2 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

iminuit-2.25.2-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (392.1 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

iminuit-2.25.2-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.whl (405.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ i686

iminuit-2.25.2-cp39-cp39-macosx_10_9_universal2.whl (701.7 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

iminuit-2.25.2-cp38-cp38-win_amd64.whl (360.2 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

iminuit-2.25.2-cp38-cp38-win32.whl (310.7 kB view hashes)

Uploaded CPython 3.8 Windows x86

iminuit-2.25.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (393.7 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

iminuit-2.25.2-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (391.8 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

iminuit-2.25.2-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.whl (404.9 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686

iminuit-2.25.2-cp38-cp38-macosx_10_9_universal2.whl (701.5 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64)

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page