Skip to main content
Help us improve Python packaging – donate today!

Symbolic Fitting; fitting as it should be.

Project Description

Project Goals

The goal of this project is simple: to make fitting in Python sexy and pythonic. What does pythonic fitting look like? Well, there’s a simple test. If I can give you pieces of example code and don’t have to use any additional words to explain what it does, it’s pythonic.

from symfit import parameters, variables, Fit, Model

xdata = [1.0, 2.0, 3.0, 4.0, 5.0]
ydata = [2.3, 3.3, 4.1, 5.5, 6.7]
yerr = [0.1, 0.1, 0.1, 0.1, 0.1]

a, b = parameters('a, b')
x, y = variables('x, y')
model = Model({y: a * x + b})

fit = Fit(model, x=xdata, y=ydata, sigma_y=yerr)
fit_result = fit.execute()

Cool right? So now that we have done a fit, how do we use the results?

import matplotlib.pyplot as plt

y = model(x=xdata, **fit_result.params)
plt.plot(xdata, y)
plt.show()
Linear Fit

Need I say more? How about I let another code example do the talking?

from symfit import parameters, Maximize, Equality, GreaterThan

x, y = parameters('x, y')
model = 2 * x * y + 2 * x - x**2 - 2 * y**2
constraints = [
    Equality(x**3, y),
    GreaterThan(y, 1),
]

fit = Maximize(model, constraints=constraints)
fit_result = fit.execute()

I know what you are thinking. “What if I need to fit to a system of Ordinary Differential Equations?”

from symfit import variables, Parameter, ODEModel, Fit, D

tdata = np.array([10, 26, 44, 70, 120])
adata = 10e-4 * np.array([44, 34, 27, 20, 14])

a, b, t = variables('a, b, t')
k = Parameter(0.1)

model_dict = {
    D(a, t): - k * a**2,
    D(b, t): k * a**2,
}

ode_model = ODEModel(model_dict, initial={t: 0.0, a: 54 * 10e-4, b: 0.0})

fit = Fit(ode_model, t=tdata, a=adata, b=None)
fit_result = fit.execute()

For more fitting delight, check the docs at http://symfit.readthedocs.org.

Release history Release notifications

This version
History Node

0.4.0

History Node

0.3.7

History Node

0.3.6

History Node

0.3.5

History Node

0.3.4

History Node

0.3.3

History Node

0.3.3.dev155

History Node

0.3.2

History Node

0.3.1

History Node

0.3.0

History Node

0.2.6

History Node

0.2.5

History Node

0.2.4

History Node

0.2.3

History Node

0.2.2

History Node

0.2.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
symfit-0.4.0-py2.py3-none-any.whl (50.9 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Dec 27, 2017
symfit-0.4.0.tar.gz (1.1 MB) Copy SHA256 hash SHA256 Source None Dec 27, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page