[SciPy-user] scipy.optimize.anneal with multiple parameters

Tim Leslie tim.leslie at gmail.com
Sun Mar 5 21:52:53 CST 2006

Hi all,

Before I dive too deeply into the internals of this code I thought I'd check
here to see what people know.

I'm trying to use simulated annealing to fit a quadratic to some data (I'll
be using a more complex function later, the quadratic is just to get me
started). I'm doing the following:

func = lambda p: sum(abs(dat - array([p[0]*x*x + p[1]*x + p[2] for x in
range(150, 450)])))
print anneal(func,[0.001, 0.001, 0.001],full_output=1,upper=[3.0, 3.0, 3.0
],lower=[-3.0, -3.0, -3.0],feps=1e-6,maxiter=1000,schedule='fast')

timl at mercury:~/thesis/src% python fit.py
Traceback (most recent call last):
  File "fit.py", line 17, in ?
    print anneal(func,[0.001, 0.001, 0.001],full_output=1,upper=[3.0, 3.0,
3.0],lower=[-3.0, -3.0, -3.0],feps=1e-6,maxiter=1000,schedule='fast')
  File "/usr/lib/python2.4/site-packages/scipy/optimize/anneal.py", line
215, in anneal
    xnew = schedule.update_guess(x0)
  File "/usr/lib/python2.4/site-packages/scipy/optimize/anneal.py", line 92,
in update_guess
    xc = y*(self.upper - self.lower)
TypeError: unsupported operand type(s) for -: 'list' and 'list'

I stole the syntax from the __main__ section of anneal.py and modified it to
use a list of size 3, but I'm not sure if this is the correct way to do
multiple parameters, the docs leave plenty to the imagination

So, am I doing something wrong, in which case could someone show me the
light, or is anneal a bit broken, in which case I'm happy to dive in and
take a stab at fixing it.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.scipy.net/pipermail/scipy-user/attachments/20060306/f7ab593e/attachment-0001.htm

More information about the SciPy-user mailing list