[SciPy-User] Inequality constrains definition and violation in slsqp
josef.pktd@gmai...
josef.pktd@gmai...
Fri Dec 11 10:49:13 CST 2009
On Fri, Dec 11, 2009 at 11:37 AM, jagan prabhu <jagan_cbe2003@yahoo.co.in>wrote:
> My function is a simple least square, it look like,
>
> func = sum((observeddata[ ] - calculated[ ] )**2) or sum(abs(observed[ ] -
> calculated[ ] ))
>
> The slsqp optimization code is coupled to a third part software, beginning
> from the initial values for each function evaluation my optimization code
> passes 8 parameters to the software. Based on these 8 parameters software
> calculates the data and its is stored in calculated[ ] array and
> observeddata[ ] is a constant data through out the process, aim is to
> minimize the error between the observedata[ ] and calculated[ ] by choosing
> the proper parameter. Basically i want to do a inverse process
> identification.
>
> observeddata[ ] and calculated[ ] will be an array of 200 to 400 entries.
>
> My software is very sensitive to the constraints, if it violates is stops
> execution and the entire process stops.
>
> End of the process i don't know whether it is violated or not, because once
> in between the process constrains are violated the coupling software stops
> execution and my optimization process stops.
>
> So i am forced to search of a better way to define my constraints so that
> it will not violated during function evaluation.
>
In this case you also have to rewrite (or drop) your numerical
differentiation, because you violate the constraint yourself.
One simple way to make sure that your external program doesn't get invalid
parameters, is to check the constraints in your wrapper func and return
e.g. inf or a very large number directly (without calling the external
program)
There might be some problems with the derivative calculations at the
boundary, and I don't know how slsqp handles it if you drop your own
numerical derivatives. Otherwise, I guess, you would need to to check that
your own derivative calculations only use points that satisfy the
constraints.
Josef
>
> --- On *Fri, 11/12/09, josef.pktd@gmail.com <josef.pktd@gmail.com>* wrote:
>
>
> From: josef.pktd@gmail.com <josef.pktd@gmail.com>
> Subject: Re: [SciPy-User] Inequality constrains definition and violation in
> slsqp
> To: "SciPy Users List" <scipy-user@scipy.org>
> Date: Friday, 11 December, 2009, 8:41 PM
>
>
>
>
> On Fri, Dec 11, 2009 at 9:39 AM, jagan prabhu <jagan_cbe2003@yahoo.co.in<http://mc/compose?to=jagan_cbe2003@yahoo.co.in>
> > wrote:
>
>> my objective function is a simple least square function, i have 8
>> parameters and 3 inequality constraints, i used fmin_slsqp optimization
>> algorithm for my problem, but often my constraints are violated while
>> execution. My
>> code looks like,
>>
>> ######### begin ##############################
>> #######
>> Init = [8.0, 14.0, 16.0, 7.0, 13.0, 50.0, 9.0, 4.0] #
>> [a,b,c,d,e,f,g,h]
>> # constraints (c > d, g > h & e>=a)
>>
>> bounds = [(3.0, 4000.0), (1.0, 6000.0), (2.0, 10000.0), (1.0,
>> 4000.0), (4.0, 6000.0), (1.0, 5000.0), (2.0, 10000.0), (1.0, 4000.0)]
>> # constraints
>> con1 = lambda x: x[2]-x[3]
>> con2 = lambda x: x[6]-x[7]
>> con3 = lambda x: x[4]-x[0]
>> cons = [con1, con2, con3]
>> ###
>> # gradient function for my problem
>> def grad(s,*args):
>> f = func
>> step = 1.e-3
>> fini = f(*((s,)+args))
>> grad = numpy.zeros((len(s),), float)
>> st = numpy.zeros((len(s),), float)
>> for i in range(len(s)):
>> st[i] = step*s[i]
>> grad[i] = (f(*((s+st,)+args)) - fini)/st[i]
>> st[i] = 0.0
>> return grad
>>
>> opt = fmin_slsqp(func, Init, ieqcons=cons, bounds= bounds, fprime =
>> grad, iter=50000,iprint=2, acc=0.01)
>>
>> ############## end of the code #############################
>>
>> Here the major problem i face is the constraints (c > d, g > h & e>=a) are
>> violated frequently during execution, is there any error with my constrain
>> definition method or any better way to avoid constrain violations?
>>
>>
> What's your func?
>
> I don't see anything obviously wrong.
> With "violated frequently during execution", do you mean during
> optimization but not at the final result?
>
> If yes, your numerical gradient calculation doesn't check whether the
> parameters for the functions f(*((s+st,)+args))
> are satisfying the constraints, and your stepsizes are pretty big. I don't
> know if slsqp itself only evaluates at points that statisfy the constraints.
>
> If that's not the point, then I would need more information to understand
> what's going on.
>
> Josef
>
>
> ------------------------------
>> The INTERNET now has a personality. YOURS! See your Yahoo! Homepage<http://in.rd.yahoo.com/tagline_yyi_1/*http://in.yahoo.com/>
>> .
>>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User@scipy.org <http://mc/compose?to=SciPy-User@scipy.org>
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
>>
>
> -----Inline Attachment Follows-----
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org <http://mc/compose?to=SciPy-User@scipy.org>
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
> ------------------------------
> The INTERNET now has a personality. YOURS! See your Yahoo! Homepage<http://in.rd.yahoo.com/tagline_yyi_1/*http://in.yahoo.com/>
> .
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20091211/24b5215e/attachment.html
More information about the SciPy-User
mailing list