Skip to content Skip to sidebar Skip to footer

Specifying Constraints For Fmin_cobyla In Scipy

I use Python 2.5. I am passing bounds to the cobyla optimisation: import numpy from numpy import asarray Initial = numpy.asarray [2, 4, 5, 3] # Initial values to start with

Solution 1:

fmin_cobyla() is not an interior point method. That is, it will pass points that are outside of the bounds ("infeasible points") to the function during the course of the optmization run.

On thing that you will need to fix is that b9 and b10 are not in the form that fmin_cobyla() expects. The bound functions need to return a positive number if they are within the bound, 0.0 if they are exactly on the bound, and a negative number if they are out of bounds. Ideally, these functions should be smooth. fmin_cobyla() will try to take numerical derivatives of these functions in order to let it know how to get back to the feasible region.

b9 = lambda x: x[2] - x[3]

I'm not sure how to implement b10 in a way that fmin_cobyla() will be able to use, though.

Solution 2:

for b10, a possible option could be:

b10 = lambda x: min(abs(i-j)-d for i,j in itertools.combinations(x,2))

where d is a delta greater than the minimum difference you want between your variables (e.g 0.001)

Post a Comment for "Specifying Constraints For Fmin_cobyla In Scipy"