Skip to main content

Scalable, pythonic fitting for high energy physics

Reason this release was yanked:

Has no upper Python bound -> installs if new, unsupported Python version out

Project description

zfit: scalable pythonic fitting

https://img.shields.io/pypi/v/zfit.svg https://img.shields.io/travis/zfit/zfit.svg https://coveralls.io/repos/github/zfit/zfit/badge.svg?branch=meta_changes CodeFactor

The zfit package is a model manipulation and fitting library based on TensorFlow and optimised for simple and direct manipulation of probability density functions. Its main focus is on scalability, parallelisation and user friendly experience.

Detailed documentation, including the API, can be found in https://zfit.github.io/zfit.

It is released as free software following the BSD-3-Clause License.

N.B.: zfit is currently in beta stage, so while most core parts are established, some may still be missing and bugs may be encountered. It is, however, mostly ready for production, and is being used in analyses projects. If you want to use it for your project and you are not sure if all the needed functionality is there, feel free contact us in our Gitter channel.

Why?

The basic idea behind zfit is to offer a Python oriented alternative to the very successful RooFit library from the ROOT data analysis package that can integrate with the other packages that are part if the scientific Python ecosystem. Contrary to the monolithic approach of ROOT/RooFit, the aim of zfit is to be light and flexible enough to integrate with any state-of-art tools and to allow scalability going to larger datasets.

These core ideas are supported by two basic pillars:

  • The skeleton and extension of the code is minimalist, simple and finite: the zfit library is exclusively designed for the purpose of model fitting and sampling with no attempt to extend its functionalities to features such as statistical methods or plotting.

  • zfit is designed for optimal parallelisation and scalability by making use of TensorFlow as its backend. The use of TensorFlow provides crucial features in the context of model fitting like taking care of the parallelisation and analytic derivatives.

Installing

To install zfit, run this command in your terminal:

$ pip install zfit

This is the preferred method to install zfit, as it will always install the most recent stable release.

For the newest development version (in case you really need it), you can install the version from git with

$ pip install git+https://github.com/zfit/zfit

How to use

While the zfit library provides a simple model fitting and sampling framework for a broad list of applications, we will illustrate its main features by generating, fitting and ploting a Gaussian distribution.

import tensorflow as tf
import zfit
from zfit import ztf

The domain of the PDF is defined by an observable space, which is created using the zfit.Space class:

obs = zfit.Space('x', limits=(-10, 10))

Using this domain, we can now create a simple Gaussian PDF. To do this, we define its parameters and their limits using the zfit.Parameter class and we instantiate the PDF from the zfit library:

mu    = zfit.Parameter("mu"   , 2.4, -1, 5)
sigma = zfit.Parameter("sigma", 1.3,  0, 5)
gauss = zfit.pdf.Gauss(obs=obs, mu=mu, sigma=sigma)

For simplicity, we create the dataset to be fitted starting from a numpy array, but zfit allows for the use of other sources such as ROOT files:

mu_true = 0
sigma_true = 1
data_np = np.random.normal(mu_true, sigma_true, size=10000)
data = zfit.data.Data.from_numpy(obs=obs, array=data_np)

Fits are performed in three steps:

  1. Creation of a loss function, in our case a negative log-likelihood.

  2. Instantiation of our minimiser of choice, in the example the MinuitMinimizer.

  3. Minimisation of the loss function.

# Stage 1: create an unbinned likelihood with the given PDF and dataset
nll = zfit.loss.UnbinnedNLL(model=gauss, data=data)

# Stage 2: instantiate a minimiser (in this case a basic minuit)
minimizer = zfit.minimize.MinuitMinimizer()

# Stage 3: minimise the given negative log-likelihood
result = minimizer.minimize(nll)

Errors are calculated with a further function call to avoid running potentially expensive operations if not needed:

param_errors = result.error()

Once we’ve performed the fit and obtained the corresponding uncertainties, we can examine the fit results:

print("Function minimum:", result.fmin)
print("Converged:", result.converged)
print("Full minimizer information:", result.info)

# Information on all the parameters in the fit
params = result.params
print(params)

# Printing information on specific parameters, e.g. mu
print("mu={}".format(params[mu]['value']))

And that’s it! For more details and information of what you can do with zfit, please see the documentation page.

Contributing

Contributions are always welcome, please have a look at the Contributing guide.

Acknowledgements

zfit has been developed with support from the University of Zürich and the Swiss National Science Foundation (SNSF) under contracts 168169 and 174182.

The idea of zfit is inspired by the TensorFlowAnalysis framework developed by Anton Poluektov using the TensorFlow open source library.

History

0.3.0 (2019-03-20)

Beta stage and first pip release

0.0.1 (2018-03-22)

  • First creation of the package.

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

zfit-0.3.0.tar.gz (162.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zfit-0.3.0-py2.py3-none-any.whl (118.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file zfit-0.3.0.tar.gz.

File metadata

  • Download URL: zfit-0.3.0.tar.gz
  • Upload date:
  • Size: 162.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3

File hashes

Hashes for zfit-0.3.0.tar.gz
Algorithm Hash digest
SHA256 bbe6d7df1f59da205b5c22d6776044ec2781a643ca0f98e39c9a320b22c5fc45
MD5 52996c9313231262292471f3d68ebb8c
BLAKE2b-256 3e09e4caeea0b479cd8c51edd3e548145ad222b01e288267365ef1744f57dd8f

See more details on using hashes here.

File details

Details for the file zfit-0.3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: zfit-0.3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 118.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3

File hashes

Hashes for zfit-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3a6021a29bf4ed7cc7c28e4e87e1590c024ab9f155d431c2a29fe45a9e8a6b6a
MD5 46e0267c0ae277d8278be5cba1abf836
BLAKE2b-256 fc54bebc0d749bbd3a11f1ea8c13c8e28eed5718a111a242defedab40ac0b118

See more details on using hashes here.

Supported by

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