I am trying to formulate an optimization problem using scipy minimize
function. However, I am having the following problem that I can't work around:
I want X = [x1, x2, x3, x4, x5]
that minimizes a cost function F(X). This X vector, however, are percentage values that must add to 1, i.e., np.sum(X) = 1
.
The problem is: if I use, for instance, the "SLSQP" method with some initial values (such as X0 = [0.2, 0.2, 0.2, 0.2, 0.2]
), it will try to increment each value to find some convergence direction. For example, the algorithm will make X0 -> [0.21, 0.2, 0.2, 0.2, 0.2]
. But that cannot happen, because np.sum(X) = 1
is a requirement for me to compute the objective function.
Using constraints does not help either! I could make a constraint with np.sum(X) = 1
. However, the minimize algorithm will only check the constraint after computing the objective function.
Anyone have an idea on how to deal with such a problem?
Thanks a lot!