Skip to main content

A Python package for fitting data with iMinuit

Project description

pyminufit

Actions Status Documentation Status

PyPI version Conda-Forge PyPI platforms

GitHub Discussion

This package is an interface to iminuit to allow for fast simple fits and mimics the functionality of PyrooFit which is an interface on top of the ROOT.RooFit package.

The package allows for simple fits of standard PDFs and easy setup of custom PDFs in one or more fit dimensions.

Links

Description Link
Documentation pyminufit Documentation
GitHub Repository pyminufit GitHub Repository

This package is based on top of iminuit. For more information, you can refer to the iminuit documentation.

Example

Simple fit and plot of a Gaussian Distribution:

from pyminufit.models import Gauss
import numpy as np

data = np.random.normal(0, 1, 1000)

pdf = Gauss(("x", -3, 3), mean=(-1, 0, 1))
pdf.fit(data)
pdf.plot(
    "example_gauss.pdf",
)

pdf.get()

A more complex example on combination of Gauss pdf for signal and Polynomial for background:

import pyminufit as mnf
import numpy as np

data = np.append(
    np.random.random_sample(1000) * 10 + 745, np.random.normal(750, 1, 1000)
)

x = mnf.create_real_var(("mass", 745, 755), unit="GeV")

pdf_sig = mnf.Gauss(x, mean=(745, 755), sigma=(0.1, 1, 2), title="Signal")
pdf_bkg = mnf.Chebyshev(x, order=2, title="Background")

pdf = pdf_sig + pdf_bkg

pdf.fit(data)
pdf.plot(data, "02_add_pdf.png", dpi=150)
pdf.get()

Fitting multiple pdf to data.

Observables can be initialised by a list or tuple with the column name / variable name as first argument, followed by the range and/or with the initial value and range:

x = ('x', -3, 3)
x = ('mass', -3, 0.02, 3)

Parameters are initialised with a tuple: sigma=(0,1) or again including a starting parameter: sigma=(0.01, 0, 1) The order here is not important.

Installation

You can install pyminufit directly from PyPI using pip:

pip install pyminufit

Alternatively, if you want to install the development version directly from GitHub, you can do so with:

pip install git+https://github.com/simonuu/pyminufit.git

For a development installation, download the git reposityro and run:

pip install -e .

Development

If you have any questions or need help with this package, your contributions are greatly appreciated. This project is a side project, so any assistance is welcome. When contributing, please follow design principles that prioritize simplicity of the interface while preserving the complexity of the underlying functionality. You can contribute by submitting a pull request (PR) to the GitHub repository. For larger changes consider discussing ideas in GitHub Issues. Thank you for your support!

Planned Features

  • ProdPdf: Product pdf for multiple observables
  • Convolutions
  • Shared parameters
  • Backend options for the pdf calculation

This package was created using the scientific python template from https://scientific-python.org/.

Project details


Download files

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

Source Distribution

pyminufit-0.2.2.tar.gz (129.5 kB view details)

Uploaded Source

Built Distribution

pyminufit-0.2.2-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file pyminufit-0.2.2.tar.gz.

File metadata

  • Download URL: pyminufit-0.2.2.tar.gz
  • Upload date:
  • Size: 129.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pyminufit-0.2.2.tar.gz
Algorithm Hash digest
SHA256 876715b24e3970288523969eeedf0ca3f94204133d05c6c27a712e7fb83ff547
MD5 ac1c1ecebc9c78632ebadec9b6b83b36
BLAKE2b-256 c52296c2f188a84227ee3c59a7027da60197c796ede93644e05fd25731753afb

See more details on using hashes here.

File details

Details for the file pyminufit-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: pyminufit-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pyminufit-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b37b7a35937dc2817c45d343944b010ae758f63590fd9b64efd3483efc69e659
MD5 066bc73517327310ff0a6237270be7ba
BLAKE2b-256 43a40ab70a2924c6c4e66f39a8f0835a1b6b72a4a4524c5609aaa893107bf8d6

See more details on using hashes here.

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