I'm learning scipy.optimize.minimize
. I thought of a simple function to see how it works:
$$f(x) = x$$
With the goal to minimise $f(x)$, subject to the constraint that: $$x \ge 0.1$$
Without the constraint, there is no solution (except in the limit $\lim_{x\to -\infty} f(x) = \infty$). But with the constraint $x \ge 0.1$, my logic says that the solution must be also $x=0.1$ since it's the smallest permissible number according to the constraint.
Here is my code:
import numpy
import scipy
def f(x, *args):
return x[0]
def fc1(x):
# x[0] >= 0.1
# x[0] - 0.1 >= 0
return x[0] - 0.1
x0 = numpy.array([1])
c1 = {'type':'ineq', 'fun':fc1}
scipy.optimize.minimize(f, x0, [c1])
But it results in a failure:
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:241: RuntimeWarning: overflow encountered in square
return np.sum(np.abs(x)**ord, axis=0)**(1.0 / ord)
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:1417: RuntimeWarning: invalid value encountered in scalar multiply
if (alpha_k*vecnorm(pk) <= xrtol*(xrtol + vecnorm(xk))):
/usr/lib/python3.10/site-packages/scipy/optimize/_optimize.py:1439: RuntimeWarning: overflow encountered in multiply
Hk = np.dot(A1, np.dot(Hk, A2)) + (rhok * sk[:, np.newaxis] *
/usr/lib/python3.10/site-packages/scipy/optimize/_linesearch.py:276: RuntimeWarning: invalid value encountered in multiply
return f(xk + alpha * pk, *args)
Out[4]:
message: Desired error not necessarily achieved due to precision loss.
success: False
status: 2
fun: -3.3921181109909714e+155
x: [-3.392e+155]
nit: 47
jac: [ 1.000e+00]
hess_inv: [[ inf]]
nfev: 7037
njev: 3518
Question: What am I misunderstanding about the concept? I think I have a fundamental understanding mistake about how this works.