zfit

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.

https://github.com/zfit/zfit

Science Score: 77.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in README
  • Academic publication links
    Links to: sciencedirect.com
  • Committers with academic emails
    10 of 29 committers (34.5%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (16.1%) to scientific vocabulary

Keywords

high-energy-physics likelihood model-fitting scikit-hep tensorflow

Keywords from Contributors

hep particle-physics physics-simulation particles histogram hack distributed mesh hep-ex energy-system-model
Last synced: 6 months ago · JSON representation ·

Repository

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.

Basic Info
  • Host: GitHub
  • Owner: zfit
  • License: bsd-3-clause
  • Language: Python
  • Default Branch: develop
  • Homepage: http://zfit.readthedocs.io/
  • Size: 59.7 MB
Statistics
  • Stars: 193
  • Watchers: 8
  • Forks: 64
  • Open Issues: 34
  • Releases: 60
Topics
high-energy-physics likelihood model-fitting scikit-hep tensorflow
Created almost 8 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog Contributing License Citation Authors

README.rst

|zfit_logo|

*******************************
zfit: scalable pythonic fitting
*******************************

.. image:: https://scikit-hep.org/assets/images/Scikit--HEP-Affiliated-blue.svg
   :target: https://scikit-hep.org

.. image:: https://img.shields.io/badge/DOI-10.1016%2Fj.softx.2020.100508-yellow
   :target: https://www.sciencedirect.com/science/article/pii/S2352711019303851
   :alt: DOI 10.1016/j.softx.2020.100508

.. image:: https://img.shields.io/pypi/pyversions/zfit
   :target: https://pypi.org/project/zfit/
   :alt: PyPI - Python Version

.. image:: https://img.shields.io/pypi/v/zfit.svg
   :target: https://pypi.python.org/pypi/zfit

.. image:: https://img.shields.io/conda/vn/conda-forge/zfit
   :target: https://anaconda.org/conda-forge/zfit
   :alt: conda-forge

.. image:: https://img.shields.io/spack/v/py-zfit
   :target: https://github.com/spack/spack/blob/develop/var/spack/repos/builtin/packages/py-zfit/package.py

.. image:: https://github.com/zfit/zfit/workflows/build/badge.svg
   :target: https://github.com/zfit/zfit/actions





.. |zfit_logo| image:: docs/images/zfit-logo_hires.png
   :target: https://github.com/zfit/zfit
   :alt: zfit logo

.. |scikit-hep_logo| image:: docs/images/scikit-hep-logo_168x168.png
   :target: https://scikit-hep.org/affiliated
   :alt: scikit-hep logo

zfit is a highly scalable and customizable model manipulation and likelihood fitting library. It uses the same computational backend as
`TensorFlow `_ and is optimised for simple and direct manipulation of probability density functions. The project is affiliated with
and well integrated into `Scikit-HEP `_, the HEP Python ecosystem.

- **Tutorials**: `Interactive introduction and tutorials `_
- **Quick start**: `Example scripts `_
- **Documentation**: See `stable documentation`_ or `latest documentation`_
- **Questions**: see the `FAQ `_,
  `ask on StackOverflow `_ (with the **zfit** tag) or `contact`_ us directly.
- **Physics, HEP**: `zfit-physics `_ is the place to contribute and find more HEP
  related content
- **Statistical inference**: `hepstats `_ for limits, CI, sWeights and more


If you use zfit in **research**, please
consider `citing `_.

*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 to `contact`_ us.

Installation
=============

zfit is available on pip and conda-forge. To install it (recommended: use a virtual/conda env!) with all the dependencies (minimizers, uproot, ...), use

.. code-block:: bash

   pip install -U zfit[all]

(the ``-U`` just indicates to upgrade zfit, in case you have it already installed)
or for minimal dependencies

.. code-block:: bash

   pip install zfit

For conda/mamba, use

.. code-block:: bash

   conda install -c conda-forge zfit




How to use
==========

While the zfit library provides a model fitting and sampling framework for a broad list of applications,
we will illustrate its main features with a simple example by fitting a Gaussian distribution with an unbinned
likelihood fit and a parameter uncertainty estimation.


Example in short
----------------
.. code-block:: python

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

    # create the model
    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)

    # load the data
    data_np = np.random.normal(size=10_000)
    data = zfit.Data(obs=obs, data=data_np)
    # or sample from model
    data = gauss.sample(10_000)

    # build the loss
    nll = zfit.loss.UnbinnedNLL(model=gauss, data=data)

    # minimize (20+ interchangeable minimizers available!)
    minimizer = zfit.minimize.Minuit()
    result = minimizer.minimize(nll).update_params()

    # calculate errors
    sym_errors = result.hesse()
    asym_errors = result.errors()

This follows the zfit workflow

.. image:: docs/images/zfit_workflow_v2.png
    :alt: zfit workflow




Full explanation
----------------

The default space (e.g. normalization range) of a PDF is defined by an *observable space*, which is created using the ``zfit.Space`` class:


.. code-block:: python

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


To create a simple Gaussian PDF, we define its parameters and their limits using the ``zfit.Parameter`` class.

.. code-block:: python

  # syntax: zfit.Parameter("any_name", value, lower, upper)
    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:

.. code-block:: python

    mu_true = 0
    sigma_true = 1
    data_np = np.random.normal(mu_true, sigma_true, size=10000)
    data = zfit.Data(obs=obs, data=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 ``Minuit``.
3. Minimisation of the loss function.

.. code-block:: python

    # 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.Minuit()

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

The ``.update_params()`` changes the default values of the parameters
(*this is currently happen by default but won't anymore in the future*)

Symmetric errors are calculated with a further function call to avoid running potentially expensive operations if not needed. Asymmetric errors using a
profiling method can also be obtained:

.. code-block:: python

    sym_errors = result.hesse()
    asym_errors = result.errors()

Once we've performed the fit and obtained the corresponding uncertainties, we can examine the fit results by printing it or looking at individual parts

.. code-block:: python

    print(result)  # nice representation of a whole result

    print("Function minimum:", result.fmin)
    print("Converged:", result.converged)

    # 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, checkout the `latest documentation`_.

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 t
o 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.

Prerequisites
=============

``zfit`` works with Python versions 3.10 and above.
The main dependency is `tensorflow `_: zfit follows a close version compatibility with TensorFlow.


Contributing
============

Any idea of how to improve the library? Or interested to write some code?
Contributions are always welcome, please have a look at the `Contributing guide`_.

.. _Contributing guide: CONTRIBUTING.rst


Contact
========

You can contact us directly:
 - via e-mail: zfit@physik.uzh.ch
 - join our `Gitter channel `_


Original Authors
================

| Jonas Eschle 
| Albert Puig 
| Rafael Silva Coutinho 


See here for `all authors and contributors`_

..  _all authors and contributors: AUTHORS.rst


Acknowledgements
================

zfit has been developed with support from the University of Zurich 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 and `TensorProb `_ by Chris Burr and Igor Babuschkin
using the TensorFlow open source library and more libraries.

.. _`latest documentation`: https://zfit.readthedocs.io/en/latest/
.. _`stable documentation`: https://zfit.readthedocs.io/en/stable/

Owner

  • Name: zfit
  • Login: zfit
  • Kind: organization
  • Email: zfit@physik.uzh.ch

Citation (CITATION.cff)

# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0

title: zfit
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: software
authors:
  - given-names: Jonas
    family-names: Eschle
    email: jonas.eschle@cern.ch
    orcid: 'https://orcid.org/0000-0002-7312-3699'
  - given-names: Albert Puig
    family-names: Navarro
    orcid: 'https://orcid.org/0000-0001-8868-2947'
    email: albert.puig.navarro@gmail.com
  - given-names: Rafael Silva
    family-names: Coutinho
    orcid: 'https://orcid.org/0000-0002-1545-959X'
    email: rafael.silva.coutinho@cern.ch
  - given-names: Nicola
    family-names: Serra
    email: Nicola.Serra@cern.ch
    orcid: 'https://orcid.org/0000-0002-5033-0580'
  - given-names: Matthieu
    family-names: Marinangeli
    email: matthieu.marinangeli@gmail.com
    orcid: 'https://orcid.org/0000-0002-8361-9356'
  - given-names: Iason Krommydas
    email: ik23@rice.edu
    orcid: https://orcid.org/0000-0001-7849-8863

doi: 10.5281/zenodo.2602042
type: software
repository-code: 'https://github.com/zfit/zfit'
url: 'https://zfit.readthedocs.io/en/latest/'
abstract: >-
  Statistical modeling is a key element in many scientific
  fields and especially in High-Energy Physics (HEP)
  analysis. The standard framework to perform this task in
  HEP is the C++ ROOT/RooFit toolkit; with Python bindings
  that are only loosely integrated into the scientific
  Python ecosystem. In this paper, zfit, a new alternative
  to RooFit written in pure Python, is presented. Most of
  all, zfit provides a well defined high-level API and
  workflow for advanced model building and fitting, together
  with an implementation on top of TensorFlow, allowing a
  transparent usage of CPUs and GPUs. It is designed to be
  extendable in a very simple fashion, allowing the usage of
  cutting-edge developments from the scientific Python
  ecosystem in a transparent way.
keywords:
  - HEP
  - likelihood
  - model fitting
  - statistical inference
license: Apache-2.0
version: '0.22.1'
date-released: '2023-02-25'

preferred-citation:
    authors:
      - given-names: Jonas
        family-names: Eschle
        email: jonas.eschle@cern.ch
        orcid: 'https://orcid.org/0000-0002-7312-3699'
      - given-names: Albert Puig
        family-names: Navarro
        orcid: 'https://orcid.org/0000-0001-8868-2947'
        email: albert.puig.navarro@gmail.com
      - given-names: Rafael Silva
        family-names: Coutinho
        orcid: 'https://orcid.org/0000-0002-1545-959X'
        email: rafael.silva.coutinho@cern.ch
      - given-names: Nicola
        family-names: Serra
        email: Nicola.Serra@cern.ch
        orcid: 'https://orcid.org/0000-0002-5033-0580'
      - given-names: Matthieu
        family-names: Marinangeli
        email: matthieu.marinangeli@gmail.com
        orcid: 'https://orcid.org/0000-0002-8361-9356'
    identifiers:
      - type: doi
        value: 10.1016/j.softx.2020.100508
        description: Paper

GitHub Events

Total
  • Create event: 51
  • Commit comment event: 7
  • Release event: 8
  • Issues event: 39
  • Watch event: 11
  • Delete event: 55
  • Issue comment event: 110
  • Push event: 246
  • Pull request review comment event: 19
  • Pull request review event: 36
  • Pull request event: 67
  • Fork event: 10
Last Year
  • Create event: 51
  • Commit comment event: 7
  • Release event: 8
  • Issues event: 39
  • Watch event: 11
  • Delete event: 55
  • Issue comment event: 110
  • Push event: 246
  • Pull request review comment event: 19
  • Pull request review event: 36
  • Pull request event: 67
  • Fork event: 10

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 3,403
  • Total Committers: 29
  • Avg Commits per committer: 117.345
  • Development Distribution Score (DDS): 0.174
Past Year
  • Commits: 225
  • Committers: 5
  • Avg Commits per committer: 45.0
  • Development Distribution Score (DDS): 0.151
Top Committers
Name Email Commits
Jonas Eschle 'Mayou36 m****6@j****m 2,810
SebastianJL j****e@y****m 159
Matthieu Marinangeli m****i@e****h 118
pre-commit-ci[bot] 6****] 76
Albert Puig a****g@c****h 61
dependabot[bot] 4****] 52
iasonkrom i****m@g****m 29
Rafael Silva Coutinho r****o@c****h 23
rsilvaco r****o@c****h 18
Andrea Mauri a****i@c****h 16
Marc Steiner a****g@p****m 7
Sebastian Schmitt s****5@w****e 7
Connor Stone c****8@g****m 5
Oliver Lantwin o****n@c****h 4
Niklas Nolte n****e 2
abhijitm08 a****8 2
EPFL e****l@t****h 2
sleepyowl s****2@y****m 1
mashelll 4****l 1
fchinu f****1@g****m 1
Simon Thor s****r@h****e 1
Remco de Boer 2****r 1
ImgBotApp I****p@g****m 1
Henry Schreiner H****I@g****m 1
Donal Hill d****l@c****h 1
Chris Burr c****r 1
Axel Buß a****9@u****e 1
Albert Puig a****g@e****h 1
Anja Beck 1****k 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 66
  • Total pull requests: 315
  • Average time to close issues: 6 months
  • Average time to close pull requests: 10 days
  • Total issue authors: 26
  • Total pull request authors: 18
  • Average comments per issue: 2.08
  • Average comments per pull request: 0.69
  • Merged pull requests: 275
  • Bot issues: 0
  • Bot pull requests: 79
Past Year
  • Issues: 30
  • Pull requests: 85
  • Average time to close issues: 29 days
  • Average time to close pull requests: 1 day
  • Issue authors: 8
  • Pull request authors: 6
  • Average comments per issue: 1.73
  • Average comments per pull request: 0.35
  • Merged pull requests: 70
  • Bot issues: 0
  • Bot pull requests: 16
Top Authors
Issue Authors
  • jonas-eschle (20)
  • acampove (19)
  • fchinu (4)
  • mzks (1)
  • Tristan63170 (1)
  • sbysiak (1)
  • TAOYi92 (1)
  • ikrommyd (1)
  • AlexanderHeidelbach (1)
  • maxnoe (1)
  • LHUecker (1)
  • fabnap (1)
  • andresailer (1)
  • mashelll (1)
  • schmitse (1)
Pull Request Authors
  • jonas-eschle (192)
  • dependabot[bot] (58)
  • ikrommyd (22)
  • pre-commit-ci[bot] (20)
  • iasonkrom (3)
  • marinang (3)
  • ConnorStoneAstro (2)
  • fchinu (2)
  • Copilot (2)
  • anjabeck (2)
  • tinnuche (2)
  • LarsHebenstiel (1)
  • mmaehring (1)
  • redeboer (1)
  • imgbot[bot] (1)
Top Labels
Issue Labels
bug (36) discussion (12) help wanted (2) good first issue (2) enhancement (1)
Pull Request Labels
dependencies (58) github_actions (8) enhancement (2)

Packages

  • Total packages: 3
  • Total downloads:
    • pypi 158,438 last-month
  • Total docker downloads: 172
  • Total dependent packages: 12
    (may contain duplicates)
  • Total dependent repositories: 18
    (may contain duplicates)
  • Total versions: 101
  • Total maintainers: 2
pypi.org: zfit

scalable pythonic model fitting for high energy physics

  • Versions: 72
  • Dependent Packages: 11
  • Dependent Repositories: 17
  • Downloads: 158,438 Last month
  • Docker Downloads: 172
Rankings
Dependent packages count: 1.0%
Downloads: 1.4%
Docker downloads count: 2.5%
Average: 3.3%
Dependent repos count: 3.5%
Stargazers count: 5.7%
Forks count: 6.0%
Maintainers (1)
Last synced: 6 months ago
conda-forge.org: zfit
  • Versions: 8
  • Dependent Packages: 1
  • Dependent Repositories: 1
Rankings
Dependent repos count: 24.3%
Forks count: 26.5%
Average: 27.4%
Dependent packages count: 29.0%
Stargazers count: 29.7%
Last synced: 6 months ago
spack.io: py-zfit

scalable pythonic model fitting for high energy physics

  • Versions: 21
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Average: 27.8%
Dependent packages count: 55.7%
Maintainers (1)
Last synced: 6 months ago

Dependencies

.github/workflows/cd.yml actions
  • actions/checkout v3 composite
  • actions/download-artifact v3 composite
  • actions/setup-python v4 composite
  • actions/upload-artifact v3 composite
  • pypa/gh-action-pypi-publish v1.6.4 composite
.github/workflows/ci.yml actions
  • actions/cache v3.2.2 composite
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • actions/setup-python v3 composite
  • coverallsapp/github-action 1.1.3 composite
.github/workflows/codeql-analysis.yml actions
  • actions/checkout v3 composite
  • github/codeql-action/analyze v2 composite
  • github/codeql-action/init v2 composite
examples/example_requirements.txt pypi
  • matplotlib *
  • mplhep *
requirements.txt pypi
  • boost-histogram *
  • colorama *
  • colored *
  • colorlog *
  • deprecated *
  • dotmap *
  • hist *
  • iminuit >=2.3
  • importlib-metadata *
  • jacobi *
  • numdifftools *
  • numpy >=1.16
  • ordered-set *
  • pandas *
  • pydantic *
  • scipy >=1.2
  • tabulate *
  • tensorflow >=2.10,<2.12
  • tensorflow-addons *
  • tensorflow_probability >=0.18,<0.20
  • texttable *
  • tf_quant_finance >=v0.0.1
  • uhi *
  • uproot >=4,<5
  • xxhash *
  • zfit_interface *
requirements_dev.txt pypi
  • Jinja2 * development
  • Sphinx >=3.5.4 development
  • bumpversion >=0.5.3 development
  • check-manifest * development
  • coverage >=4.5.1 development
  • docformatter * development
  • flake8 >=3.5.0 development
  • jax * development
  • jaxlib * development
  • jupyter-sphinx * development
  • matplotlib * development
  • mplhep * development
  • myst-nb * development
  • pip >=9.0.1 development
  • pre-commit * development
  • progressbar2 * development
  • pydata-sphinx-theme >=0.9 development
  • pygit2 * development
  • pyhf >=0.7 development
  • pytest-benchmark * development
  • pyyaml * development
  • seed_intersphinx_mapping * development
  • setupext-janitor * development
  • setuptools >=30.3.0 development
  • setuptools_scm >=3.4 development
  • setuptools_scm_git_archive * development
  • sphinx-autodoc-typehints * development
  • sphinx-copybutton * development
  • sphinx-panels * development
  • sphinx_togglebutton * development
  • sphinxcontrib-bibtex * development
  • sphinxcontrib-images * development
  • sphinxcontrib-youtube >=1.0.0,<1.2.0 development
  • tox >=2.9.1 development
  • twine >=1.10.0 development
  • watchdog >=0.8.3 development
  • wheel >=0.29.0 development
pyproject.toml pypi
setup.py pypi