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
Basic Usage
import numpy as np
from zeroguess.functions import WaveletFunction, add_gaussian_noise
from zeroguess.integration import ZeroGuessModel
# 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)
import zeroguess
from scipy import optimize
# Create and train parameter estimator
estimator = zeroguess.create_estimator(
function=wavelet,
param_ranges={
'frequency': (0, 10),
'phase': (-5, 5),
'position': (0.1, 2),
'width': (0, 10),
},
independent_vars_sampling={
'x': x_data
}
)
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=initial_params
)
lmfit Integration
# 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, max=10)
model.set_param_hint("phase", min=-5, max=5)
model.set_param_hint("position", min=0.1, max=2)
model.set_param_hint("width", min=0, max=10)
# Standard lmfit workflow
params = model.guess(y_data, x=x_data)
result = model.fit(y_data, x=x_data, params=params)
SciPy Integration
from zeroguess.integration import scipy_integration
import numpy as np
# Enhanced curve_fit with automatic parameter estimation
optimal_params, pcov = scipy_integration.curve_fit(
wavelet, x_data, y_data,
param_ranges={
'frequency': (0, 10),
'phase': (-5, 5),
'position': (0.1, 2),
'width': (0, 10),
},
independent_vars_sampling={
'x': np.linspace(-10, 10, 100)
}
)
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.0.tar.gz.
File metadata
- Download URL: zeroguess-0.8.0.tar.gz
- Upload date:
- Size: 24.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
681e97d04948755df4cb4175eab2dbc1d620f5f8c00c4aab36a9cb94263d64a9
|
|
| MD5 |
8e9e1a87e10bf502599e6bade5820147
|
|
| BLAKE2b-256 |
db94c7de8ab4c07246d660a8168ace34cef1b86b86d3ad0051e96a91ad460bf8
|
File details
Details for the file zeroguess-0.8.0-py3-none-any.whl.
File metadata
- Download URL: zeroguess-0.8.0-py3-none-any.whl
- Upload date:
- Size: 29.5 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 |
487aac3526d97898524e79a29046fd0ed1482ec41729f8602e89317b78a2a31d
|
|
| MD5 |
4f2ac3c19298532cb6d9a171f878b6ff
|
|
| BLAKE2b-256 |
62dcd1de098a5e481a156c6ab8b38bdc2f1237210b0651b0c5916e4de5478036
|