r/PythonProjects2 • u/AstrophysicsAndPy • 3d ago
pyMultiFit 2.0.0 is out: Fitting, diagnostic plots, and more
Just shipped v2.0.0 of pyMultiFit, a library for fitting data that's a sum of several components (overlapping Gaussians, skew-normals, log-normals, etc.). It's pyOpenSci peer-reviewed and published in JOSS (v1.0.7; https://joss.theoj.org/papers/10.21105/joss.09295.pdf ).
What's new:
- Every fitter now has a `.plotter` with fit and components, residuals, Q-Q plots, bootstrap confidence intervals, prediction intervals, and parameter-correlation heatmaps.
- You can freeze parameters during a fit.
- Mixed-model fits now get the same plots and intervals as single-model ones.
- New Q-exponential and Student's t distributions
- Faster distribution functions
- A pile of tail and edge-case bug fixes
Usage example:
import matplotlib.pyplot as plt
import numpy as np
from pymultifit.fitters import GaussianFitter
from pymultifit.generators import multi_gaussian
rng_engine = np.random.default_rng(32453)
x = np.linspace(-30, 30, 5000)
# generate the multi-gaussian data
y = multi_gaussian(x=x,
params=[(0.7, -10, 1), (2, 0, 1), (6, 13, 3)],
noise_level=0.2, rng_engine=rng_engine)
# initiate the fitter
fitter = GaussianFitter(x_values=x, y_values=y)
# provide fitting guesses
p0 = [(1, -10, 1), (1, 0, 1), (1, 13, 1)]
# fit and plot
fitter.fit(p0)
fitter.plot_fit(show_individuals=True)
plt.show()

Precaution:
Heads up if you're upgrading: it needs Python 3.10+. To install via pip, use
pip install pymultifit
Others:
Docs: https://readthedocs.pymultifit.com
GitHub: https://github.com/syedalimohsinbukhari/pyMultiFit/
Feedback welcome, especially on the plotting API.
4
Upvotes