Easy and Flexible Curve Fitting
Project description
Fitting Toolkit
This toolkit aims at providing flexible and powerful tools for data analysis and modelling, but remain easy to use.
Here, I aim to strike a balance between the two extremes in this field. On one side are toolkits such as Kafe2, which prioritize ease of use and convenience but limit user control over the output, often resulting in highly specialized graphics that frequently do not meet standards required for publication without considerable effort. On the other side are data analysis systems like CERN's ROOT, which offer exceptional speed and capability but come with a steep learning curve and often exceed the requirements of most experiments.
This toolkit is aimed primarily at my peers, students of physics at the university of bonn, and to a degree at professionals within my field. I am optimizing this toolkit to be used on the scale typical of lab courses and homework assignments but if possible it should be powerful enough to run decently sized datasets on an average laptop.
This toolkit wraps numpy for fast data management and manipulation, scipy for curve_fit() and matplotlib for display options.
Check out the docs folder for documentation and tutorials.
Quick Introduction
Requirements
This project requires the following modules along with their dependencies:
- numpy
- matplotlib
- scipy
It is highly recommended that the user familiarizes themselves with the functionality of these modules first. A rudimentary understanding of numpy and matplotlib.pyplot is required.
To install the dependencies, first a virtual environment should be created. requirements.txt lists all necessary packages. Run:
pip install -r requirements.txt
Getting Started
To get started find the fitting_toolkit.py in the src folder and copy it into your project.
You can now import the relevant functions into your code:
from fitting_toolkit import curve_fit, plot_fit
import numpy as np
The curve_fit requires numpy-arrays. Therefore numpy has to be imported as well.
We can now start by simply defining our data.
x = np.array((1, 2, 3, 4, 5))
y = np.array((1, 2, 1.75, 2.25, 3))
dy = 0.1*y+0.05
dx = 0.1
We chose a simple linear model:
def f(x, a, b):
return a * x + b
We can now fit the model to the data:
params, cov, lower_conf, upper_conf = curve_fit(f, x, y, yerror=dy)
This functions returns 4 arrays. First the parameters of the model, the covariance matrix of those parameters and then the lower and upper limits of the confidence interval around the fit. Note that the confidence interval is absolute. To get the error in relation to the fitted function you would need to find the difference at each point.
The resulting fit can now be plotted. This toolkit provides a premade function to generate plots:
from matplotlib import pyplot as plt
fig, ax = plot_fit(x, y, f, params, lower_conf, upper_conf, xerror=dx, yerror=dy)
plt.show()
Note that the fitted function is not automatically displayed. Instead the figure and axis-objects are returned.
For a deeper explanation and tutorials please reference the documentation.
Literature:
[1] Vugrin, K. W., L. P. Swiler, R. M. Roberts, N. J. Stucky-Mack, and S. P. Sullivan (2007), Confidence region estimation techniques for nonlinear regression in groundwater flow: Three case studies, Water Resour. Res., 43, W03423, https://doi.org/10.1029/2005WR004804.
[2] Dennis D. Boos. "Introduction to the Bootstrap World." Statist. Sci. 18 (2) 168 - 174, May 2003. https://doi.org/10.1214/ss/1063994971
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 fitting_toolkit-1.0.1.tar.gz.
File metadata
- Download URL: fitting_toolkit-1.0.1.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0bbfdb525b7d5145575f86811b56eea1ad3353c56a2177d025295d095e42167
|
|
| MD5 |
c2bfcc3ea1af9a6765a4d16d1abea4c4
|
|
| BLAKE2b-256 |
69af287261f65660364a5df9e24133bd7d3f5d16ea01438fdef6f6a33a6f90be
|
File details
Details for the file fitting_toolkit-1.0.1-py3-none-any.whl.
File metadata
- Download URL: fitting_toolkit-1.0.1-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7294ceadfa633a07c5e7926eaa8fff3e106d243e142dabe07e5ef66e29be8a63
|
|
| MD5 |
eeb43c53f97f4c2adbaf3a6dc8f6cdd8
|
|
| BLAKE2b-256 |
9bc244b01d497c36191592b36a1653f2b6b3b116401d321b277fa3c8db141a97
|