A package to fit functions on data
Project description
Status
Compatibilities
Contact
AdAdjust
Package allowing to fit any mathematical function to (for now 1-D only) data.
Installation
pip install adadjust
Usage
from adadjust import Function
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams.update({"text.usetex": True}) # Needs texlive installed
nsamples = 1000
a = 0.3
b = -10
xstart = 0
xend = 1
noise = 0.01
x = np.linspace(xstart, xend, nsamples)
y = a * x ** 2 + b + np.random.normal(0, noise, nsamples)
def linfunc(xx, p):
return xx * p[0] + p[1]
def square(xx, p):
return xx ** 2 * p[0] + p[1]
func = Function(linfunc, "$a \\times p[0] + p[1]$")
func2 = Function(square, "$a^2 \\times p[0] + p[1]$")
params = func.fit(x, y, np.array([0, 0]))[0]
rr = func.compute_rsquared(x, y, params)
params2 = func2.fit(x, y, np.array([0, 0]))[0]
rr2 = func2.compute_rsquared(x, y, params2)
table = Function.make_table(
[func, func2], [params, params2], [rr, rr2], caption="Linear and Square fit", path_output="table.pdf"
)
table.compile()
Function.plot(x, [func, func2], [params, params2], y=y, rsquared=[rr, rr2])
plt.gcf().savefig("plot.pdf")
NOTE : to have pretty gaphs, put the line plt.rcParams.update({"text.usetex": True})
just after you imported adadjust.
This requiers that you have TexLive full installed on your computer.
The result will be :
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
adadjust-0.1.39.tar.gz
(295.6 kB
view details)
File details
Details for the file adadjust-0.1.39.tar.gz
.
File metadata
- Download URL: adadjust-0.1.39.tar.gz
- Upload date:
- Size: 295.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 441e655e1ea9cc18ecb3437e3fe827f6d7c12eeccb6848f952320233bf8f5b7c |
|
MD5 | a06d5d2be1f26cec105f872024c55732 |
|
BLAKE2b-256 | 68d092351609883c09b1039cd89b0bbae2e8600685129bffaf42b4482b589104 |