symbolfit

Automatic parametric modeling with symbolic regression [Comput Softw Big Sci 9, 12 (2025)]

https://github.com/hftsoi/symbolfit

Science Score: 67.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 4 DOI reference(s) in README
  • Academic publication links
    Links to: arxiv.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.1%) to scientific vocabulary

Keywords

automation curve-fitting high-energy-physics interpolation lmfit machine-learning nonlinear-optimization parametric-modelling pysr python symbolic-regression uncertainty-estimations
Last synced: 6 months ago · JSON representation ·

Repository

Automatic parametric modeling with symbolic regression [Comput Softw Big Sci 9, 12 (2025)]

Basic Info
Statistics
  • Stars: 51
  • Watchers: 2
  • Forks: 4
  • Open Issues: 35
  • Releases: 9
Topics
automation curve-fitting high-energy-physics interpolation lmfit machine-learning nonlinear-optimization parametric-modelling pysr python symbolic-regression uncertainty-estimations
Created over 1 year ago · Last pushed 8 months ago
Metadata Files
Readme License Citation

README.md

![Animation](docs/demo/animation.gif)
Docs | Paper | Slides | Colab | |:-:|:-:|:-:|:-:| [![Read the Docs](https://img.shields.io/readthedocs/symbolfit?color=blue&style=flat-square)](https://symbolfit.readthedocs.io) | [![arXiv](https://img.shields.io/badge/arXiv-2411.09851-b31b1b.svg?style=flat-square)](https://arxiv.org/abs/2411.09851)
[![doi](https://img.shields.io/badge/journal-doi-informational?style=flat-square&color=teal)](https://doi.org/10.1007/s41781-025-00140-9) | [![slides](https://img.shields.io/badge/talk-slides-informational?style=flat-square&color=purple)](https://github.com/hftsoi/symbolfit/blob/main/symbolfit.pdf) | [![Open in Colab](https://img.shields.io/badge/Colab-notebook-informational?style=flat-square&color=gold)](https://colab.research.google.com/github/hftsoi/symbolfit/blob/main/colab_demo/symbolfit_colab.ipynb) |
GitHub | pip | conda | |:-:|:-:|:-:| [![GitHub Created At](https://img.shields.io/github/created-at/hftsoi/symbolfit?color=black&style=flat-square)](https://github.com/hftsoi/symbolfit)
[![GitHub Release](https://img.shields.io/github/v/release/hftsoi/symbolfit?color=black&style=flat-square)](https://github.com/hftsoi/symbolfit/releases)
[![GitHub Release Date](https://img.shields.io/github/release-date/hftsoi/symbolfit?color=black&style=flat-square)](https://github.com/hftsoi/symbolfit/releases) | [![PyPI - Version](https://img.shields.io/pypi/v/symbolfit?color=orange&style=flat-square)](https://pypi.org/project/symbolfit)
[![Pepy Total Downloads](https://img.shields.io/pepy/dt/symbolfit?color=orange&style=flat-square)](https://www.pepy.tech/projects/symbolfit) | [![Conda Version](https://img.shields.io/conda/vn/conda-forge/symbolfit.svg?color=green&style=flat-square)](https://anaconda.org/conda-forge/symbolfit)
[![Conda Downloads](https://img.shields.io/conda/dn/conda-forge/symbolfit.svg?color=green&style=flat-square)](https://anaconda.org/conda-forge/symbolfit) |

An API to automate parametric modeling with symbolic regression, originally developed for data analysis in the experimental high-energy physics community, but also applicable beyond.

SymbolFit takes binned data with measurement/systematic uncertainties (optional) as input, utilizes PySR to perform a machine-search for batches of functional forms that model the data, parameterizes these functions, and utilizes LMFIT to re-optimize the functions and provide uncertainty estimation, all in one go. It is designed to maximize automation with minimal human input. Each run produces a batch of functions with uncertainty estimation, which are evaluated, saved, and plotted automatically into readable output files, ready for downstream tasks.

Note: This API is actively being updated to accommodate more use cases, so any feedback and contributions are very much welcomed and appreciated! If you encounter any problems while using it, please don’t hesitate to: - Report bugs or suggest new features at Issues - Ask for specific help and recommendations for your dataset at Discussions

If you don't feel like sharing your data in public, please feel free to drop me a message or Email. We are happy to assist in getting it to work on your data!

Installation

Prerequisite (Julia)

Install Julia (backend for PySR): curl -fsSL https://install.julialang.org | sh Then check if installed properly: julia --version If julia is not found, most probably it is not yet included in PATH. To include, do: export PATH="$PATH:/path/to/<Julia directory>/bin" Check out here for platform-specific instructions.

Afterward, it is recommended to start from an empty virtual environment for installing and running SymbolFit.

Installation via PyPI

With python>=3.10 and pip: pip install symbolfit

Installation via conda (to be updated for >= v0.2.0, please use pip for now) ``` conda create --name symbolfit_env python=3.10 conda activate symbolfit_env conda install -c conda-forge symbolfit ```
Editable installation for developers ``` git clone https://github.com/hftsoi/symbolfit.git cd symbolfit pip install -e . ```

Getting Started

To run an example fit, get the example datasets by cloning this repo: git clone https://github.com/hftsoi/symbolfit.git cd symbolfit Then within a python session (or simply do python fit_example.py): ``` from symbolfit.symbolfit import *

dataset = importlib.importmodule('examples.datasets.toydataset1.dataset') pysrconfig = importlib.importmodule('examples.pysrconfigs.pysrconfiggauss').pysr_config

model = SymbolFit( x = dataset.x, y = dataset.y, yup = dataset.yup, ydown = dataset.ydown, pysrconfig = pysrconfig, maxcomplexity = 60, inputrescale = True, scaleyby = 'mean', maxstderr = 20, fityunc = True, randomseed = None, loss_weights = None )

model.fit() After the fit, save results to csv files: model.savetocsv(outputdir = 'outputdir/') and plot results to pdf files: model.plottopdf( outputdir = 'outputdir/', binwidths1d = dataset.binwidths1d, plotlogy = False, plotlogx = False, sampling95quantile = False, #binedges2d = dataset.binedges2d, #plotlogx0 = False, #plotlogx1 = False, #cbarmin = None, #cbarmax = None, #cmap = None, #contour = None, # ^ additional options for 2D plotting ) Candidate functions with full substitutions can be printed promptly: model.printcandidate(candidate_number = 20) ``` When preparing for your own data, a graphical illustration of the input data format can be found here.

Each fit will produce a batch of candidate functions and will automatically save all results to six output files: 1) candidates.csv: saves all candidate functions and evaluations in a csv table. 2) candidates_compact.csv: saves a reduced version for essential information without intermediate results. 3) candidates.pdf: plots all candidate functions (1D/2D only for now) with associated uncertainties one by one for fit quality evaluation. 4) candidates_sampling.pdf: plots all candidate functions (1D only for now) with total uncertainty coverage generated by sampling parameters. 5) candidates_gof.pdf: plots the goodness-of-fit scores. 6) candidates_correlation.pdf: plots the correlation matrices for the parameters of the candidate functions.

Output files from an example fit can be found and downloaded here for illustration.

Note: The function space is usually huge, even when constrained by the pysr config. This means that if you are not satisfied with the results from a fit, you can simply rerun it with the exact same config and obtain a completely different set of candidate functions—the only difference being the random seed that initiates the seeding functions. Therefore, you can rerun the fit as many times as you want until you are satisfied with the results. If you use model = SymbolFit(..., random_seed = None, ...), nothing needs to be changed—just rerun the fit. If you set a specific random_seed, change its value before rerunning. However, if you are still not satisfied with the results after many trials, it might indicate an issue with the config. Then you might want to try a different config, tune it, and start new runs.

For detailed instructions and more demonstrations, please check out the Colab notebook and the documentation.

Documentation

The documentation can be found here for more information and demonstrations.

Citation

If you find this useful in your research, please consider citing SymbolFit: @article{Tsoi:2024pbn, author = "Tsoi, Ho Fung and Rankin, Dylan and Caillol, Cecile and Cranmer, Miles and Dasu, Sridhara and Duarte, Javier and Harris, Philip and Lipeles, Elliot and Loncar, Vladimir", title = "{SymbolFit: Automatic Parametric Modeling with Symbolic Regression}", eprint = "2411.09851", archivePrefix = "arXiv", primaryClass = "hep-ex", doi = "10.1007/s41781-025-00140-9", journal = "Comput. Softw. Big Sci.", volume = "9", pages = "12", year = "2025" } and PySR: @misc{cranmerInterpretableMachineLearning2023, title = {Interpretable {Machine} {Learning} for {Science} with {PySR} and {SymbolicRegression}.jl}, url = {http://arxiv.org/abs/2305.01582}, doi = {10.48550/arXiv.2305.01582}, urldate = {2023-07-17}, publisher = {arXiv}, author = {Cranmer, Miles}, month = may, year = {2023}, note = {arXiv:2305.01582 [astro-ph, physics:physics]}, keywords = {Astrophysics - Instrumentation and Methods for Astrophysics, Computer Science - Machine Learning, Computer Science - Neural and Evolutionary Computing, Computer Science - Symbolic Computation, Physics - Data Analysis, Statistics and Probability}, }

Owner

  • Name: Ho-Fung Tsoi
  • Login: hftsoi
  • Kind: user
  • Location: Geneva, Switzerland
  • Company: CMS Collaboration at CERN

Citation (CITATION.bib)

@article{Tsoi:2024pbn,
    author = "Tsoi, Ho Fung and Rankin, Dylan and Caillol, Cecile and Cranmer, Miles and Dasu, Sridhara and Duarte, Javier and Harris, Philip and Lipeles, Elliot and Loncar, Vladimir",
    title = "{SymbolFit: Automatic Parametric Modeling with Symbolic Regression}",
    eprint = "2411.09851",
    archivePrefix = "arXiv",
    primaryClass = "hep-ex",
    doi = "10.1007/s41781-025-00140-9",
    journal = "Comput. Softw. Big Sci.",
    volume = "9",
    pages = "12",
    year = "2025"
}

@misc{cranmerInterpretableMachineLearning2023,
      title = {Interpretable {Machine} {Learning} for {Science} with {PySR} and {SymbolicRegression}.jl},
      url = {http://arxiv.org/abs/2305.01582},
      doi = {10.48550/arXiv.2305.01582},
      urldate = {2023-07-17},
      publisher = {arXiv},
      author = {Cranmer, Miles},
      month = may,
      year = {2023},
      note = {arXiv:2305.01582 [astro-ph, physics:physics]},
      keywords = {Astrophysics - Instrumentation and Methods for Astrophysics, Computer Science - Machine Learning, Computer Science - Neural and Evolutionary Computing, Computer Science - Symbolic Computation, Physics - Data Analysis, Statistics and Probability},
}

GitHub Events

Total
  • Create event: 8
  • Issues event: 41
  • Release event: 8
  • Watch event: 50
  • Issue comment event: 21
  • Push event: 262
  • Fork event: 3
Last Year
  • Create event: 8
  • Issues event: 41
  • Release event: 8
  • Watch event: 50
  • Issue comment event: 21
  • Push event: 262
  • Fork event: 3

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 75 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 9
  • Total maintainers: 1
pypi.org: symbolfit

Automatic parametric modeling with symbolic regression

  • Versions: 9
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 75 Last month
Rankings
Dependent packages count: 10.1%
Average: 33.5%
Dependent repos count: 57.0%
Maintainers (1)
Last synced: 6 months ago

Dependencies

requirements.txt pypi
  • lmfit ==1.2.2
  • matplotlib ==3.8.2
  • pandas ==2.2.3
  • pysr ==0.16.9
  • seaborn ==0.13.2
docs/requirements.txt pypi
  • sphinx ==7.1.2
  • sphinx-rtd-theme ==1.3.0rc1
pyproject.toml pypi
setup.py pypi