Skip to main content

Adaptive Curvefitting Tool

PyPI version PyPI - Downloads Downloads DOI

Adaptive curvefitting is a tool to find potentially optimal models for your research data. It's based on scipy, numpy, and matplotlib.

Table of contents

Why is this tool

The very difference of adaptive-curvefitting with numpy.polyfit, scipy.optimize.curve_fit or scipy.optimize.least_squares is the hypothesis you don’t know which model to fit. If you already have the expected model, the methods in scipy and numpy are fantastic tools and better than this one. When you explore something unknown, this will be a maybe.

Installation, update and uninstallation

To install

Quick installation with pip:

pip install adaptive-curvefitting

Or from github:

pip install git+https://github.com/longavailable/adaptive-curvefitting

To update

pip install --upgrade adaptive-curvefitting

To uninstall

pip uninstall adaptive-curvefitting

Usage

Import the required module

In general,

import longscurvefitting

or import the specified function:

from longscurvefitting import oneClickCurveFitting
from longscurvefitting import generateFunction
from longscurvefitting import generateModels

Do the curvefitting

oneClickCurveFitting(xdata, ydata)

There are some optional arguments of oneClickCurveFitting.

  • functions: specified or all (default) basic models(name of models) to fit.
    • Type: list of string
    • Default: basicModels_nameList
  • piecewise: if consider custom a piecewise function. It is mandatory not to 'piecewise' when the data size is less than 20.
    • Type: bool
    • Default: False
  • operator: operatation between basic models.
    • Type: string
    • Default: '+'
  • maxCombination: max number of combination of basic models.
    • Type: integer
    • Default: 2
  • plot_opt: the number of plot for optimal models.
    • Type: integer
    • Default: 10
  • xscale: one of {"linear", "log", "symlog", "logit", ...}
    • Type: string
    • Default: None
  • yscale: one of {"linear", "log", "symlog", "logit", ...}
    • Type: string
    • Default: None
  • filename_startwith: a custom string mark as part of output filename
    • Type: string
    • Default: 'curvefit'
  • silent: minimal output to monitor
    • Type: boolean
    • Default: False
  • feedback: if True, return the optimal model(function object), parameters
    • Type: boolean
    • Default: False
  • kwargs: keyword arguments passed to curve_fit_m. Note that bounds and p0 will take no effect when multi-models.
    • Type: dict

See the complete example "/tests/curvefitting.py".

Generate a expected model

Create a model composited by gaussian and erf function:

funcs = ['gaussian','erf']
myfunc = generateFunction(funcs, functionName='myfunc', operator='+')['model']

See the complete example "/tests/custom_a_model.py".

Re-use the fitted curve

See the complete example "/tests/reuse_the_fitted_model.py".

Shortages

How to cite

If this tool is useful to your research, star and cite it as below:

Xiaolong Liu, & Meixiu Yu. (2020, June 14). longavailable/adaptive-curvefitting. Zenodo. 
http://doi.org/10.5281/zenodo.3893596

Easily, you can import it to Mendeley.

Changelog

v0.1.3

  • First release.

v0.1.4

  • Add queryModel() to simplify the reuse of a fitted model.
  • Replace from scipy._lib._util import getargspec_no_self as _getargspec with from ._helpers import funcArgsNr

v0.1.5

  • Updated the outdated module of scipy.

v0.1.7

  • This bug occurs because Python 3.13 no longer exposes exec-defined local functions to locals() or eval() due to PEP 667. We resolve it by explicitly passing a namespace dictionary to exec() and retrieving the generated function from that dictionary instead.

Metadata

Release files for adaptive-curvefitting 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for adaptive-curvefitting 0.1.7
File Size Uploaded
adaptive_curvefitting-0.1.7.tar.gz 12.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for adaptive-curvefitting 0.1.7
File Interpreter ABI Platform
adaptive_curvefitting-0.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 27.1 kB

Release files / adaptive_curvefitting-0.1.7.tar.gz

Download URL adaptive_curvefitting-0.1.7.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
075b73db161c78a264441f93f965a60c237f49e63cb191cfff613f4ba3187561
BLAKE2b-256 checksum
How to use checksums
b2f1c11bd3143692d6a50d21f4f875d5d6cfd0ba6249eb36e36e8edcc8be415e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release files / adaptive_curvefitting-0.1.7-py3-none-any.whl

Download URL adaptive_curvefitting-0.1.7-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c484b25dde7aca986edd7f2e0c74102c0d30e355b56ba2e971c6809e0722fdcb
BLAKE2b-256 checksum
How to use checksums
7ce780b859f27a30d8bdfcab05afca8ecd52a1c5aa6d4f29c518ffbc2da09215
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release history Release notifications | RSS feed

This release

0.1.7 This release

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page