示例#1
0
文件: fit.py 项目: Jhsmit/AtomicPlot
def get_model(
    model, xdata, ydata
):  # todo classfactory, and xdata y data optional (is already classfactory)
    if model == 'exp_decay':
        a = Parameter(name='a', value=ydata[0], min=0)
        b = Parameter(name='b', value=ydata[-1], min=0)

        tau_pos = np.abs(ydata - (ydata[0] / np.e + ydata[-1])).argmin()
        tau = Parameter(name='tau', value=xdata[tau_pos], min=0)

        x = Variable(name='x')
        m = a * exp(-x / tau) + b
        return m

    elif model == 'double_exp_decay':
        a1 = Parameter(name='a1', value=ydata[0] / 2.1, min=0)
        a2 = Parameter(name='a2', value=ydata[0] / 1.9, min=0)
        b = Parameter(name='b', value=ydata[-1], min=0)

        tau_pos = np.abs(ydata - (ydata[0] / np.e + ydata[-1])).argmin()
        tau1 = Parameter(name='tau1', value=0.5 * xdata[tau_pos], min=0)
        tau2 = Parameter(name='tau2', value=2 * xdata[tau_pos], min=0)

        x = Variable(name='x')

        m = a1 * exp(-x / tau1) + a2 * exp(-x / tau2) + b
        return m
示例#2
0
文件: tests.py 项目: Eljee/symfit
    def test_likelihood_fitting(self):
        """
        Fit using the likelihood method.
        """
        b = Parameter(4, min=3.0)
        x = Variable()
        pdf = (1/b) * exp(- x / b)

        # Draw 100 points from an exponential distribution.
        # np.random.seed(100)
        xdata = np.random.exponential(5, 100000)

        fit = Likelihood(pdf, xdata)
        fit_result = fit.execute()

        self.assertAlmostEqual(fit_result.params.b, 5., 1)
示例#3
0
文件: gaussian.py 项目: Eljee/symfit
from __future__ import print_function
from symfit.api import Parameter, Variable, Fit, exp
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

palette = sns.color_palette()


x = Variable()
A = Parameter()
sig = Parameter(name='sig', value=1.4, min=1.0, max=2.0)
x0 = Parameter(name='x0', value=15.0, min=0.0)
# Gaussian distrubution
model = A*exp(-((x - x0)**2/(2 * sig**2)))

# Sample 10000 points from a N(15.0, 1.5) distrubution
sample = np.random.normal(loc=15.0, scale=1.5, size=(10000,))
ydata, bin_edges = np.histogram(sample, 100)
xdata = (bin_edges[1:] + bin_edges[:-1])/2

fit = Fit(model, xdata, ydata)
fit_result = fit.execute()
print(fit_result)
print(model)

y = model(x=xdata, **fit_result.params)
sns.regplot(xdata, ydata, fit_reg=False)
plt.plot(xdata, y, color=palette[2])
plt.ylim(0, 400)
plt.show()
示例#4
0
def boltzmann(T, V, *args, **kwargs):
    kbT = kb * T
    return exp(-V(*args, **kwargs) / kbT)