Machine Learning for Curve Fitting Parameter Estimation
Project description
ZeroGuess: Machine Learning for Curve Fitting Parameter Estimation
ZeroGuess is a Python library that simplifies the estimation of starting parameters for curve fitting by leveraging machine learning. It supports SciPy and lmfit, two widely used curve fitting libraries in the scientific Python ecosystem.
Problem Statement
While curve fitting is a well-understood problem, the process of estimating starting parameters is not. It is a very tedious and error-prone process that often requires domain expertise, trial and error, or both. Poor initial parameter estimates can cause fitting algorithms to:
- Converge to suboptimal local minima
- Require more iterations to converge
- Fail to converge entirely
ZeroGuess uses machine learning to learn from the fitting function itself, providing optimal starting parameters without manual tuning.
Installation
pip install zeroguess
Quick Start
Setup experimental data
import numpy as np
from zeroguess.functions import WaveletFunction, add_gaussian_noise
# Create a double peakGaussian function
wavelet = WaveletFunction()
# Create some experimental data
true_params = wavelet.get_random_params()
x_data = np.linspace(-10, 10, 100)
y_data = add_gaussian_noise(wavelet(x_data, **true_params), sigma=0.1)
lmfit Integration
from zeroguess.integration import ZeroGuessModel
# Enhanced lmfit Model with parameter estimation
# Enhanced lmfit Model with parameter estimation
model = ZeroGuessModel(
wavelet,
independent_vars_sampling={"x": x_data},
estimator_settings={
"make_canonical": wavelet.get_canonical_params,
# Configure training parameters
# "n_samples": 1000,
# "n_epochs": 200,
# "validation_split": 0.2,
# "add_noise": True,
# "noise_level": 0.1,
# 'verbose': True
"snapshot_path": "model_dg.pth", # saves and loads model automatically
},
)
model.set_param_hint("frequency", min=0.05, max=1.0)
model.set_param_hint("phase", min=0.0, max=2.0 * np.pi)
model.set_param_hint("position", min=5.0, max=15.0)
model.set_param_hint("width", min=0.1, max=3.0)
# Standard lmfit workflow
params = model.guess(y_data, x=x_data)
result = model.fit(y_data, x=x_data, params=params)
Scipy usage
import zeroguess
from scipy import optimize
# Create and train parameter estimator
estimator = zeroguess.create_estimator(
function=wavelet,
param_ranges={
"frequency": (0.05, 1.0),
"phase": (0.0, 2.0 * np.pi),
"position": (5.0, 15.0),
"width": (0.1, 3.0),
},
independent_vars_sampling={
'x': x_data
},
snapshot_path="model_dg_plain.pth", # saves and loads model automatically
)
if not estimator.is_trained:
estimator.train()
# Get parameter estimates for experimental data
initial_params = estimator.predict(x_data, y_data)
# Use in standard curve fitting
optimal_params, _ = optimize.curve_fit(
wavelet, x_data, y_data,
p0=list(initial_params.values())
)
Features
- Automatic estimation of starting parameters for curve fitting
- Support for both SciPy and lmfit curve fitting libraries
- Neural network-based parameter estimation
- Model persistence for reuse without retraining
- Detailed diagnostics and visualization tools
Requirements
- Python 3.10+
- Dependencies: numpy, scipy, torch, lmfit (optional)
License
MIT
Performance Benchmarks
ZeroGuess is benchmarked regularly to ensure optimal performance. View the latest benchmark results.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zeroguess-0.8.1.tar.gz.
File metadata
- Download URL: zeroguess-0.8.1.tar.gz
- Upload date:
- Size: 32.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ece6c8767c18cd75f8ecd095af2523f42a2b2d4410d466aa0e8da31108838e8
|
|
| MD5 |
14350400dedcfdfcebefea0e184b7c28
|
|
| BLAKE2b-256 |
c0398e16e25de0531c0947e525a21fcdb6d1771a8c0dc4ec7b0d990361539748
|
File details
Details for the file zeroguess-0.8.1-py3-none-any.whl.
File metadata
- Download URL: zeroguess-0.8.1-py3-none-any.whl
- Upload date:
- Size: 41.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83070c253a0632688096f1666868682d91f7e417190497082555905df06a0a1d
|
|
| MD5 |
4015d7653d642246ae765c3a49d43eca
|
|
| BLAKE2b-256 |
064e6e41908709f0e63dfac067d2750c8f9c66ea3eb9a4685f8e4e2f6c4d6e1e
|