[SciPy-User] fmin_slsqp- Bounds are not obeyed
jagan prabhu
jagan_cbe2003@yahoo.co...
Tue Nov 3 13:58:32 CST 2009
Dear users,
Problem is " Bounded with inequality constrains", in slssqp often Bounds are not obeyed, its deviates the bounds. So if deviates i made it to come back with in the region(bounds). But i face a problem in execution. i get error like,
File "/usr/lib/python2.5/site-packages/scipy/optimize/slsqp.py", line 277, in fmin_slsqp
c_ieq = array([ ieqcons[i](x) for i in range(len(ieqcons)) ])
File "/usr/lib/python2.5/site-packages/scipy/optimize/optimize.py", line 97, in function_wrapper
return function(x, *args)
TypeError: <lambda>() takes exactly 1 argument (2 given)
program will look like,
#import os
#import scipy.optimize
from scipy import *
import numpy
from scipy import optimize
from numpy import asarray
from math import *
def cst(aParams,bounds):
aParams = numpy.asarray(aParams)
for par in range(len(aParams)):
if ((bounds[par][0]<= aParams[par]<= bounds[par][1])):
pass
else:
if (aParams[par]< bounds[par][0]): aParams[par] = bounds[par][0]
if (aParams[par]> bounds[par][1]): aParams[par] = bounds[par][1]
x = aParams[0]
y = aParams[1]
z = aParams[2]
# objective function
eqn = -cos(x)*cos(y)*cos(z)*log(-((x-pi)**2-(y-pi)**2-(z-pi)**2))
return eqn
#Initial guess
Init = numpy.array([5.0,15.0,17.0]) # parameters x,y,z
bounds = [(2.0, 20000.0),(4.0, 50000.0),(5.0, 60000.0)]
# inequality constraints x must be least,y larger than x smaller than z,and z the largest of all
con1 = lambda x:numpy.asarray(x[1]-x[0], x[2]-x[1])
opt = fmin_slsqp(cst,Init,ieqcons= [con1] , bounds=bounds, fprime = None, args=(bounds,), full_output=True, iter=20000, iprint=2, acc=0.001)
print '****************************************'
print opt[0]
print opt[1]
print opt[2]
print opt[4]
Problems are,
1, bounds i could not able to pass to the function as args( ).
2, Whether implementation of the ineq. constraints are correct? any better way?
3, How to avoid bounds deviation?
Please help me.
Regards,
Prabhu
Now, send attachments up to 25MB with Yahoo! India Mail. Learn how. http://in.overview.mail.yahoo.com/photos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20091104/26b728a6/attachment.html
More information about the SciPy-User
mailing list