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 zeroguess
import numpy as np
from scipy import optimize
# Define function to fit
def gaussian(x, amplitude, center, width):
return amplitude * np.exp(-(x - center)**2 / (2 * width**2))
# Define sampling points for training
x_sampling = np.linspace(-10, 10, 100)
# Create and train parameter estimator
estimator = zeroguess.create_estimator(
function=gaussian,
param_ranges={
'amplitude': (0, 10),
'center': (-5, 5),
'width': (0.1, 2)
},
independent_vars_sampling={
'x': x_sampling
}
)
estimator.train()
# Get parameter estimates for new data
x_data = np.linspace(-10, 10, 100)
y_data = ... # Your experimental data
initial_params = estimator.predict(x_data, y_data)
# Use in standard curve fitting
optimal_params, _ = optimize.curve_fit(
gaussian, x_data, y_data,
p0=initial_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(
gaussian, x_data, y_data,
param_ranges={
'amplitude': (0, 10),
'center': (-5, 5),
'width': (0.1, 2)
},
independent_vars_sampling={
'x': np.linspace(-10, 10, 100)
}
)
lmfit Integration
from zeroguess.integration import lmfit_integration
import lmfit
import numpy as np
# Enhanced lmfit Model with parameter estimation
model = lmfit_integration.Model(
gaussian,
param_ranges={
'amplitude': (0, 10),
'center': (-5, 5),
'width': (0.1, 2)
},
independent_vars_sampling={
'x': np.linspace(-10, 10, 100)
}
)
# Standard lmfit workflow
result = model.fit(y_data, x=x_data)
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
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.7.2.tar.gz.
File metadata
- Download URL: zeroguess-0.7.2.tar.gz
- Upload date:
- Size: 30.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1011da92ceac046a67f03282e2c02087e173c5340ea3215316d009f12cc664e2
|
|
| MD5 |
7db1fff5706b72bb69f1b6bece358c37
|
|
| BLAKE2b-256 |
ca05e50ccdfbf4e5c4a585f7b69a6c5878f0286f47f1316cfceef8d3266c00cb
|
File details
Details for the file zeroguess-0.7.2-py3-none-any.whl.
File metadata
- Download URL: zeroguess-0.7.2-py3-none-any.whl
- Upload date:
- Size: 37.0 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 |
ca15e63753428ee86b4aa3871087eb2c09158f13f5b45b3979e9f92facd327c9
|
|
| MD5 |
727786a418df946a199e327c9479bc8b
|
|
| BLAKE2b-256 |
37acc56c0aa9ac73664c35ddc8bab6607beecbd379acfd85cac7fdc8a5c98ec8
|