# [SciPy-user] Using SciPy/NumPy optimization

lechtlr lechtlr@yahoo....
Wed Mar 14 12:52:08 CDT 2007

```Robert:

Thanks for the fmin_tnc example and it's working now. However, I have trouble getting optimal parameters for the model.  I have tied varies options from 'fmin_tnc', and nothing seems to work so far.  I would  appreciate, if you can give some clues to get optimal values.  I have attached my python script.

Thanks,
Lex

from numpy import *
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 dot(dy,dy)

#Generating y for given set of x
a_true = 100.0
b_true = 1.0
c_true = 10.0

T = range(1000, 2500, 10)

data = zeros([len(T), 2], 'd')

for m in range(len(T)):
error = rand(1)/T[m]
r = a_true*(1.0 + b_true*c_true*T[m])**(-1.0/b_true) + error
data[m][0] = T[m]
data[m][1] = r

x = data[:,0]
y = data[:,1]

print 'numer of data points:', len(T)

lf = LossFunction(x, y)
abc0 = [10.0, 1.0, 5.0]
retcode, nfeval, abc_optimal = fmin_tnc(lf, abc0, bounds=None, approx_grad=True)

print 'retcode:', retcode
print 'nfeval:', nfeval
print 'Optimal Parameters:', abc_optimal

---------------------------------
Expecting? Get great news right away with email Auto-Check.
Try the Yahoo! Mail Beta.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20070314/2a45d35e/attachment.html
```