2
$\begingroup$

I was trying out the minimize function from scipy

import numpy as np import scipy.optimize fn = lambda x: x[0] + x[1] ineq = lambda x: 4 - x[0] ** 2 - x[1] ** 2 # ineq = lambda x: x[0] ** 2 + x[1] ** 2 - 2 cons = [ {"type": "ineq", "fun": ineq } ] x0 = np.array([0.0, 0.0]) output = scipy.optimize.minimize(fun=fn, x0=x0, method='SLSQP', constraints=cons) 

this gives me the correct answer $(-\sqrt{2}, -\sqrt{2})$ for the constraint $g(x)=4-x_0^2-x_1^2\ge 0$. But it gives me the solution $(0, 0)$ with minimum $0$ for the constraint $g(x)=x_0^2+x_1^2-2\ge 0$. However, for the function $g(x)=x_0^2+x_1^2-2\ge 0$ I would have expected the solution to be $-\infty$. I think I did a mistake somewhere but I am not sure where

Also, I was wondering if the SLSQP method can go outside the constraint, i.e. if during the optimization procedure it can evaluate the function to optimize $f$ in a value $x$ for which the constrain is not verified (i.e. $g(x) < 0$)

$\endgroup$

1 Answer 1

3
$\begingroup$

I ran your code and changed the inequalities. This is the full output I get:

 message: Positive directional derivative for linesearch success: False status: 8 fun: 0.0 x: [ 0.000e+00 0.000e+00] nit: 5 jac: [ 1.000e+00 1.000e+00] nfev: 3 njev: 1 

Note the success: False line there. Scipy didn't so much give you an answer of $x = (0, 0)$, but rather that the last value the optimizer had for $x$ when it failed was $(0, 0)$. I suspect that this routine in scipy doesn't work from an infeasible start point, which $(0, 0)$ is for that inequality constraint. If I run it again with $x_0 = (1.0, 1.1)$, I get this:

 message: Singular matrix E in LSQ subproblem success: False status: 5 fun: -1.560785378940805e+31 x: [-3.151e+31 1.590e+31] nit: 47 jac: [ 1.000e+00 1.000e+00] nfev: 141 njev: 47 

which is just what you expected. (As an aside, the optimizer does succeed when you start from any guess of the form $x_0 = (t, t)$ for $t \ge \sqrt 2$. I'll let you figure out why.)

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.