Hi,
I am trying to fit experimetal data with scipy.optimize. anneal, but I think I didn't get the syntax right from reading the documentation, and I can't figure out what's wrong from the error I get.
ydata are the y-values, t are the x-values (experimental data), and I am trying to optimize p0 (Baseline, A1, fwhm, t0, decay1):
I get following error:
File "./jjfit_g", line 54, in <module>
res = anneal(diffa, *p0)#, args=ydata)
File "/usr/lib64/python2.7/site-packages/scipy/optimize/anneal.py", line 314, in anneal
res = _minimize_annea l(func, x0, args, **opts)
File "/usr/lib64/python2.7/site-packages/scipy/optimize/anneal.py", line 374, in _minimize_annea l
schedule = eval(schedule+' _sa()')
TypeError: unsupported operand type(s) for +: 'numpy.float64' and 'str'
The error happens on the line:
res = anneal(diffa, *p0)#, args=ydata)
How do I fix this?
Thanks.
I am trying to fit experimetal data with scipy.optimize. anneal, but I think I didn't get the syntax right from reading the documentation, and I can't figure out what's wrong from the error I get.
ydata are the y-values, t are the x-values (experimental data), and I am trying to optimize p0 (Baseline, A1, fwhm, t0, decay1):
Code:
import numpy as np
import matplotlib.pyplot as plt
import math, sys, os
from scipy.optimize import curve_fit, minimize, anneal
from scipy.special import erf
p0=np.array([0.25, 1., 7., 15., 11.])
t=np.array([5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0])
ydata=np.array([0.53227518, 0.79152417, 0.96672679, 1., 0.76314581, 0.59492542, 0.48326752, 0.35906952, 0.32363437, 0.27881503])
def func(t, Baseline, A1, fwhm, t0, decay1):
return Baseline + A1/2.*np.exp(((fwhm/(2.*math.sqrt(np.log(2.))))**2.-(4.*(t-t0)*decay1))/(4.*decay1**2.))*(1.+erf(((t-t0)/(fwhm/(2.*math.sqrt(2.*np.log(2.)))))-((fwhm/(2.*math.sqrt(np.log(2.))))/(2.*decay1))))
def diffa(p0, *data):
ydata,t=data
return abs(ydata - func(t, Baseline, A1, fwhm, t0, decay1))
res = anneal(diffa, *p0)#, args=ydata)
File "./jjfit_g", line 54, in <module>
res = anneal(diffa, *p0)#, args=ydata)
File "/usr/lib64/python2.7/site-packages/scipy/optimize/anneal.py", line 314, in anneal
res = _minimize_annea l(func, x0, args, **opts)
File "/usr/lib64/python2.7/site-packages/scipy/optimize/anneal.py", line 374, in _minimize_annea l
schedule = eval(schedule+' _sa()')
TypeError: unsupported operand type(s) for +: 'numpy.float64' and 'str'
The error happens on the line:
res = anneal(diffa, *p0)#, args=ydata)
How do I fix this?
Thanks.