{"id":13822223,"url":"https://github.com/zfit/zfit","last_synced_at":"2025-05-15T09:04:41.619Z","repository":{"id":30895414,"uuid":"126311570","full_name":"zfit/zfit","owner":"zfit","description":"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.","archived":false,"fork":false,"pushed_at":"2025-04-10T13:30:41.000Z","size":59914,"stargazers_count":187,"open_issues_count":22,"forks_count":57,"subscribers_count":8,"default_branch":"develop","last_synced_at":"2025-04-11T17:36:22.700Z","etag":null,"topics":["high-energy-physics","likelihood","model-fitting","scikit-hep","tensorflow"],"latest_commit_sha":null,"homepage":"http://zfit.readthedocs.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zfit.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.rst","dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-03-22T09:31:20.000Z","updated_at":"2025-04-10T13:11:45.000Z","dependencies_parsed_at":"2023-11-17T14:36:12.463Z","dependency_job_id":"bc221624-0158-4a7c-a26a-6bd06e01581a","html_url":"https://github.com/zfit/zfit","commit_stats":{"total_commits":3204,"total_committers":31,"mean_commits":"103.35483870967742","dds":0.1935081148564295,"last_synced_commit":"e1a4a9bdabf7ba0a76de2449d847c69c0d2964f8"},"previous_names":[],"tags_count":75,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfit%2Fzfit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfit%2Fzfit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfit%2Fzfit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zfit%2Fzfit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zfit","download_url":"https://codeload.github.com/zfit/zfit/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248909183,"owners_count":21181662,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["high-energy-physics","likelihood","model-fitting","scikit-hep","tensorflow"],"created_at":"2024-08-04T08:01:49.166Z","updated_at":"2025-04-14T15:48:55.334Z","avatar_url":"https://github.com/zfit.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":["Statistics and Fitting"],"readme":"|zfit_logo|\n\n*******************************\nzfit: scalable pythonic fitting\n*******************************\n\n.. image:: https://scikit-hep.org/assets/images/Scikit--HEP-Affiliated-blue.svg\n   :target: https://scikit-hep.org\n\n.. image:: https://img.shields.io/badge/DOI-10.1016%2Fj.softx.2020.100508-yellow\n   :target: https://www.sciencedirect.com/science/article/pii/S2352711019303851\n   :alt: DOI 10.1016/j.softx.2020.100508\n\n.. image:: https://img.shields.io/pypi/pyversions/zfit\n   :target: https://pypi.org/project/zfit/\n   :alt: PyPI - Python Version\n\n.. image:: https://img.shields.io/pypi/v/zfit.svg\n   :target: https://pypi.python.org/pypi/zfit\n\n.. image:: https://img.shields.io/conda/vn/conda-forge/zfit\n   :target: https://anaconda.org/conda-forge/zfit\n   :alt: conda-forge\n\n.. image:: https://img.shields.io/spack/v/py-zfit\n   :target: https://github.com/spack/spack/blob/develop/var/spack/repos/builtin/packages/py-zfit/package.py\n\n.. image:: https://github.com/zfit/zfit/workflows/build/badge.svg\n   :target: https://github.com/zfit/zfit/actions\n\n\n\n\n\n.. |zfit_logo| image:: docs/images/zfit-logo_hires.png\n   :target: https://github.com/zfit/zfit\n   :alt: zfit logo\n\n.. |scikit-hep_logo| image:: docs/images/scikit-hep-logo_168x168.png\n   :target: https://scikit-hep.org/affiliated\n   :alt: scikit-hep logo\n\nzfit is a highly scalable and customizable model manipulation and likelihood fitting library. It uses the same computational backend as\n`TensorFlow \u003chttps://www.tensorflow.org/\u003e`_ and is optimised for simple and direct manipulation of probability density functions. The project is affiliated with\nand well integrated into `Scikit-HEP \u003chttps://scikit-hep.org/\u003e`_, the HEP Python ecosystem.\n\n- **Tutorials**: `Interactive introduction and tutorials \u003chttps://zfit-tutorials.readthedocs.io/en/latest/\u003e`_\n- **Quick start**: `Example scripts \u003cexamples\u003e`_\n- **Documentation**: See `stable documentation`_ or `latest documentation`_\n- **Questions**: see the `FAQ \u003chttps://github.com/zfit/zfit/wiki/FAQ\u003e`_,\n  `ask on StackOverflow \u003chttps://stackoverflow.com/questions/ask?tags=zfit\u003e`_ (with the **zfit** tag) or `contact`_ us directly.\n- **Physics, HEP**: `zfit-physics \u003chttps://github.com/zfit/zfit-physics\u003e`_ is the place to contribute and find more HEP\n  related content\n- **Statistical inference**: `hepstats \u003chttps://github.com/scikit-hep/hepstats\u003e`_ for limits, CI, sWeights and more\n\n\nIf you use zfit in **research**, please\nconsider `citing \u003chttps://www.sciencedirect.com/science/article/pii/S2352711019303851\u003e`_.\n\n*N.B.*: zfit is currently in *beta stage*, so while most core parts are established,\nsome may still be missing and bugs may be encountered.\nIt is, however, mostly ready for production, and is being used in analyses projects.\nIf you want to use it for your project and you are not sure if all the needed functionality is there,\nfeel free to `contact`_ us.\n\nInstallation\n=============\n\nzfit is available on pip and conda-forge. To install it (recommended: use a virtual/conda env!) with all the dependencies (minimizers, uproot, ...), use\n\n.. code-block:: bash\n\n   pip install -U zfit[all]\n\n(the ``-U`` just indicates to upgrade zfit, in case you have it already installed)\nor for minimal dependencies\n\n.. code-block:: bash\n\n   pip install zfit\n\nFor conda/mamba, use\n\n.. code-block:: bash\n\n   conda install -c conda-forge zfit\n\n\n\n\nHow to use\n==========\n\nWhile the zfit library provides a model fitting and sampling framework for a broad list of applications,\nwe will illustrate its main features with a simple example by fitting a Gaussian distribution with an unbinned\nlikelihood fit and a parameter uncertainty estimation.\n\n\nExample in short\n----------------\n.. code-block:: python\n\n    obs = zfit.Space('x', -10, 10)\n\n    # create the model\n    mu    = zfit.Parameter(\"mu\"   , 2.4, -1, 5)\n    sigma = zfit.Parameter(\"sigma\", 1.3,  0, 5)\n    gauss = zfit.pdf.Gauss(obs=obs, mu=mu, sigma=sigma)\n\n    # load the data\n    data_np = np.random.normal(size=10_000)\n    data = zfit.Data(obs=obs, data=data_np)\n    # or sample from model\n    data = gauss.sample(10_000)\n\n    # build the loss\n    nll = zfit.loss.UnbinnedNLL(model=gauss, data=data)\n\n    # minimize (20+ interchangeable minimizers available!)\n    minimizer = zfit.minimize.Minuit()\n    result = minimizer.minimize(nll).update_params()\n\n    # calculate errors\n    sym_errors = result.hesse()\n    asym_errors = result.errors()\n\nThis follows the zfit workflow\n\n.. image:: docs/images/zfit_workflow_v2.png\n    :alt: zfit workflow\n\n\n\n\nFull explanation\n----------------\n\nThe default space (e.g. normalization range) of a PDF is defined by an *observable space*, which is created using the ``zfit.Space`` class:\n\n\n.. code-block:: python\n\n    obs = zfit.Space('x', -10, 10)\n\n\nTo create a simple Gaussian PDF, we define its parameters and their limits using the ``zfit.Parameter`` class.\n\n.. code-block:: python\n\n  # syntax: zfit.Parameter(\"any_name\", value, lower, upper)\n    mu    = zfit.Parameter(\"mu\"   , 2.4, -1, 5)\n    sigma = zfit.Parameter(\"sigma\", 1.3,  0, 5)\n    gauss = zfit.pdf.Gauss(obs=obs, mu=mu, sigma=sigma)\n\nFor 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:\n\n.. code-block:: python\n\n    mu_true = 0\n    sigma_true = 1\n    data_np = np.random.normal(mu_true, sigma_true, size=10000)\n    data = zfit.Data(obs=obs, data=data_np)\n\nFits are performed in three steps:\n\n1. Creation of a loss function, in our case a negative log-likelihood.\n2. Instantiation of our minimiser of choice, in the example the ``Minuit``.\n3. Minimisation of the loss function.\n\n.. code-block:: python\n\n    # Stage 1: create an unbinned likelihood with the given PDF and dataset\n    nll = zfit.loss.UnbinnedNLL(model=gauss, data=data)\n\n    # Stage 2: instantiate a minimiser (in this case a basic minuit)\n    minimizer = zfit.minimize.Minuit()\n\n    # Stage 3: minimise the given negative log-likelihood\n    result = minimizer.minimize(nll).update_params()\n\nThe ``.update_params()`` changes the default values of the parameters\n(*this is currently happen by default but won't anymore in the future*)\n\nSymmetric errors are calculated with a further function call to avoid running potentially expensive operations if not needed. Asymmetric errors using a\nprofiling method can also be obtained:\n\n.. code-block:: python\n\n    sym_errors = result.hesse()\n    asym_errors = result.errors()\n\nOnce we've performed the fit and obtained the corresponding uncertainties, we can examine the fit results by printing it or looking at individual parts\n\n.. code-block:: python\n\n    print(result)  # nice representation of a whole result\n\n    print(\"Function minimum:\", result.fmin)\n    print(\"Converged:\", result.converged)\n\n    # Information on all the parameters in the fit\n    params = result.params\n    print(params)\n\n    # Printing information on specific parameters, e.g. mu\n    print(\"mu={}\".format(params[mu]['value']))\n\nAnd that's it!\nFor more details and information of what you can do with zfit, checkout the `latest documentation`_.\n\nWhy?\n====\n\nThe basic idea behind zfit is to offer a Python oriented alternative to the very successful RooFit library\nfrom the `ROOT \u003chttps://root.cern.ch/\u003e`_ data analysis package that can integrate with the other packages\nthat are part if the scientific Python ecosystem.\nContrary to the monolithic approach of ROOT/RooFit, the aim of zfit is to be light and flexible enough t\no integrate with any state-of-art tools and to allow scalability going to larger datasets.\n\nThese core ideas are supported by two basic pillars:\n\n- The skeleton and extension of the code is minimalist, simple and finite:\n  the zfit library is exclusively designed for the purpose of model fitting and sampling with no attempt to extend its\n  functionalities to features such as statistical methods or plotting.\n\n- zfit is designed for optimal parallelisation and scalability by making use of TensorFlow as its backend.\n  The use of TensorFlow provides crucial features in the context of model fitting like taking care of the\n  parallelisation and analytic derivatives.\n\nPrerequisites\n=============\n\n``zfit`` works with Python versions 3.9 and above.\nThe main dependency is `tensorflow \u003chttps://www.tensorflow.org/\u003e`_: zfit follows a close version compatibility with TensorFlow.\n\nFor a full list of all dependencies, check the `requirements \u003crequirements.txt\u003e`_.\n\n\nContributing\n============\n\nAny idea of how to improve the library? Or interested to write some code?\nContributions are always welcome, please have a look at the `Contributing guide`_.\n\n.. _Contributing guide: CONTRIBUTING.rst\n\n\nContact\n========\n\nYou can contact us directly:\n - via e-mail: zfit@physik.uzh.ch\n - join our `Gitter channel \u003chttps://gitter.im/zfit/zfit\u003e`_\n\n\nOriginal Authors\n================\n\n| Jonas Eschle \u003cjonas.eschle@cern.ch\u003e\n| Albert Puig \u003calbert.puig@cern.ch\u003e\n| Rafael Silva Coutinho \u003crsilvaco@cern.ch\u003e\n\n\nSee here for `all authors and contributors`_\n\n..  _all authors and contributors: AUTHORS.rst\n\n\nAcknowledgements\n================\n\nzfit has been developed with support from the University of Zurich and the Swiss National Science Foundation (SNSF) under contracts 168169 and 174182.\n\nThe idea of zfit is inspired by the `TensorFlowAnalysis \u003chttps://gitlab.cern.ch/poluekt/TensorFlowAnalysis\u003e`_ framework\ndeveloped by Anton Poluektov and `TensorProb \u003chttps://github.com/tensorprob/tensorprob\u003e`_ by Chris Burr and Igor Babuschkin\nusing the TensorFlow open source library and more libraries.\n\n.. _`latest documentation`: https://zfit.readthedocs.io/en/latest/\n.. _`stable documentation`: https://zfit.readthedocs.io/en/stable/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzfit%2Fzfit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzfit%2Fzfit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzfit%2Fzfit/lists"}