473,549 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

fitting data with scipy.optimize. anneal

2 New Member
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):

Expand|Select|Wrap|Line Numbers
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import math, sys, os
  4. from scipy.optimize import curve_fit, minimize, anneal
  5. from scipy.special import erf
  6.  
  7. p0=np.array([0.25, 1., 7., 15., 11.])
  8. t=np.array([5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0])
  9. ydata=np.array([0.53227518, 0.79152417, 0.96672679, 1., 0.76314581, 0.59492542, 0.48326752, 0.35906952,  0.32363437, 0.27881503])
  10. def func(t, Baseline, A1, fwhm, t0, decay1):
  11.     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))))
  12.  
  13. def diffa(p0, *data):
  14.     ydata,t=data
  15.     return abs(ydata - func(t, Baseline, A1, fwhm, t0, decay1))
  16. res = anneal(diffa, *p0)#, args=ydata)
  17.  
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.
Mar 30 '14 #1
0 1438

Sign in to post your reply or Sign up for a free account.

Similar topics

0
3027
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
2
3676
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 googling suggests that SciPy might be what i want. Does that sound likely? Thanks,
1
5255
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 holds samples of a function sampled at t=-3,-2,-1,0,1,2,3. Y=0 always. func returns the absolute value of the maximum NEGATIVE error from a...
18
22373
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? -robert PS: numpy.corrcoef computes only the bare coeff:
4
2810
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 2586024 samples. the exec result is: 2586024 <type 'list'> 10.8603842736 2586024
0
1502
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 roots of a polynomial, and scipy.optimize.newton, which is used for Scalar function root finding according to the help(). I have tried both, and it...
4
5223
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 Scientific Python. I know of other least squares routines, such as the one in scipy.optimize and I believe there is also one in numpy. Now here is my...
5
24421
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 doing at the moment : # fitting functions for the data fitfunc = lambda p,x: p + p*x
0
2101
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() intgi = np.array()
0
7451
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7720
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7959
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7810
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5369
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1944
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.