[SciPy-user] Using SciPy/NumPy optimization

Brandon Nuttall bnuttall at uky.edu
Tue Feb 27 17:16:23 EST 2007


Robert,

Thanks.

At 03:25 PM 2/27/2007, you wrote:
>Presumably, you mean
>
>   y = a*(1 + b*c*x) ** (-1.0/b)
>
>to correct a typo and use Python notation.

Yes, you are correct.

>   import numpy as np
>   from scipy.optimize import fmin_tnc
>
>   class LossFunction(object):
>     def __init__(self, x, y):
>       self.x = x
>       self.y = y
>
>     def __call__(self, abc):
>       """ A function suitable for passing to the fmin() minimizers.
>       """
>       a, b, c = abc
>       y = a*(1.0 + b*c*self.x) ** (-1.0/b)
>       dy = self.y - y
>       return dy*dy
>
>   x = np.array([...])
>   y = np.array([...])
>   lf = LossFunction(x, y)
>   abc0 = np.array([x.max(), 2.5, 0.0])  # or whatever
>   retcode, nfeval, abc_optimal = fmin_tnc(lf, abc0,
>     bounds=[(None, None), (0., 5.), (-1., 1.)])

OK. I'm on my way home to try it out.



Brandon C. Nuttall

BNUTTALL at UKY.EDU                         Kentucky Geological Survey
(859) 257-5500                                     University of Kentucky
(859) 257-1147 (fax)                              228 Mining & Mineral 
Resources Bldg
http://www.uky.edu/KGS/home.htm       Lexington, Kentucky 40506-0107  




More information about the SciPy-User mailing list