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): -
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)
-
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_anneal(func, x0, args, **opts)
File "/usr/lib64/python2.7/site-packages/scipy/optimize/anneal.py", line 374, in _minimize_anneal
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.
0 1429 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Paxcal |
last post by:
Hi...
Does anyone know how can I get the fitting error (R**2) when using the
scipy.optimize.leastsq.
Tks everyone...
Paxcal
|
by: Tom Anderson |
last post by:
Hi,
I'd like to fit a curve (a rectangular hyperbola, in fact) to some data
points as part of a program i'm writing. Can anyone suggest a package
which would help me do this?
A bit of...
|
by: tkpmep |
last post by:
I'm trying to optimize a function using SciPy's optimize.fmin, but am
clearly getting the syntax wrong, and would be grateful for some
guiidance. First, here's the function
def func(Y,x):
"""Y...
|
by: robert |
last post by:
Is there a ready made function in numpy/scipy to compute the correlation y=mx+o of an X and Y fast:
m, m-err, o, o-err, r-coef,r-coef-err ?
Or a formula to to compute the 3 error ranges?
...
|
by: HYRY |
last post by:
Why the exec time of test(readdata()) and test(randomdata()) of
following program is different?
my test file 150Hz10dB.wav has 2586024 samples, so I set randomdata
function
to return a list with...
|
by: fdu.xiaojf |
last post by:
Hi all,
I have two questions about scipy.
1) When I was trying to solve a single variable equations using scipy, I
found two methods: scipy.optimize.fsolve, which is designated to find the...
|
by: Evelien |
last post by:
Dear python-users,
I am trying to do a non-linear least squares fitting. Maybe trying is
not the best word, as I already succeeded in that. At the moment I am
using leastSquaresFit from...
|
by: fordie1000 |
last post by:
Hi,
I have performed a fit to data using scipy's 'leastsq' function. However,
I wanted to be able to weight the fit by individual errors on the data points.
Here is an example of what I'm...
|
by: schwen |
last post by:
Hey there!
I am trying to phase a spectrum. In order to do that, I need to minimize following function of phi:
import numpy as np
from scipy.optimize import minimize
intgr = np.array()...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |