Skip to main content

Python package for univariate curve fitting using TensorFlow.

Project description

TensorFit

TensorFit is an open source package for curve fitting. This package was designed with the intention of allowing students and researchers to quickly assess parametric functions for explaining experimental data and trends. The package currently only supports univariate functions, i.e. functions with a single independent variable.

Install

pip install tensorfit

Usage

Import packages as needed.

>>> import numpy as np
>>> from tensorfit import TensorFunction

Generate from fake experimental data for the purpose of demonstration.

>>> x = np.linspace(-1, 1, 100)
>>> y = 9.8 * x ** 2 + 6.1 * x + 0.87 * np.random.randn(*x.shape)

Create and initialize TensorFunction instance using a parametric model for your fitting function and a set of starting parameters.

>>> tfunc = TensorFunction()
>>> my_func = "self.a * self.X ** 2 + self.b * self.X + self.c"
>>> init_params = {"a": 0.1, "b": 0.1, "c": 0.1}
>>> tfunc.initialize(func=my_func, params=init_params)

After initialization, you can make a call to .fit() to fit your TensorFunction() to the experimental data.

>>> tfunc.fit(x, y, num_rounds=10000, early_stopping_rounds=10, verbose_eval=0)
Early stopping, best iteration is:
[Episode - 6046] mse: 0.81566346

Fitted parameters and a summary of your fit can then be looked at.

>>> tfunc.Params
{'a': 9.560993, 'b': 6.0437393, 'c': 0.11265278}
>>> tfunc.Summary
{'mse': 0.81566346, 'r2': 0.9623992666602135}

License

MIT License

This library uses:

  • numpy, which is distributed under the BSD 3-Clause license.
  • tensorflow, which is distributed under the Apache 2.0 license.

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

tensorfit-0.0.6.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tensorfit-0.0.6-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file tensorfit-0.0.6.tar.gz.

File metadata

  • Download URL: tensorfit-0.0.6.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.7.9

File hashes

Hashes for tensorfit-0.0.6.tar.gz
Algorithm Hash digest
SHA256 7a5779cf287b3c0e5ffc65d14ecbde7c7684e3d0d3abf3e713929370f533e08f
MD5 42025d8cfc150c3bfdab1f9b33666514
BLAKE2b-256 0d3c5bcabd5cb2a1ed0ccc590a430315af6b9b88235f4f7611938b5553e82ba2

See more details on using hashes here.

File details

Details for the file tensorfit-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: tensorfit-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.7.9

File hashes

Hashes for tensorfit-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a82c725e46a3f862a7f290a60c7d69147780e67745b59a0999fbe6a91a82d01a
MD5 a6180e2d5b388af6203315a53da08614
BLAKE2b-256 75066cc1dab7d0d7076a256fa724f4f03fdc19539909c413a98dade242179633

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page