我想用有界约束和线性不等式约束(即总和 wi*xi ≤ b)来解决约束最小化。然而,目标函数的 Hessian 矩阵可能是奇异的。
我已经用方法尝试了minimize
inscipy.optimize
模块SLSQP
,但没有运气。一个简化的问题如下:
In [1]: import scipy as sp
In [2]: from scipy.optimize import minimize
In [3]: H = sp.array([[ 3.06235015e+04, 3.41413089e-01, 1.46545768e-01, 3.11691235e-01, 3.63587681e-01, 8.42621390e-01],
...: [ 3.41413089e-01, 6.97707374e-06, 3.43111013e-06, 6.83141186e-06, 6.88528951e-06, 1.00469425e-05],
...: [ 1.46545768e-01, 3.43111013e-06, 1.89088856e-06, 3.57752861e-06, 3.49362491e-06, 4.60245212e-06],
...: [ 3.11691235e-01, 6.83141186e-06, 3.57752861e-06, 7.39833538e-06, 6.97480991e-06, 9.41369621e-06],
...: [ 3.63587681e-01, 6.88528951e-06, 3.49362491e-06, 6.97480991e-06, 7.25710942e-06, 1.06384396e-05],
...: [ 8.42621390e-01, 1.00469425e-05, 4.60245212e-06, 9.41369621e-06, 1.06384396e-05, 3.46765772e-05]])
In [4]: fun = lambda x: sp.dot(sp.dot(x, H), x)
In [5]: jac = lambda x: 2 * sp.dot(H, x)
In [6]: x0 = sp.array([-1, 0, 0, 0, 0, 0])
In [7]: bounds = [(-100, -1), (0, 100000), (0, 100000), (0, 100000), (0, 100000), (0, 100000)]
In [8]: res = minimize(fun, x0, method='SLSQP', jac=jac, bounds=bounds)
In [9]: res.x
Out[9]: array([-1., 0., 0., 0., 0., 0.])
In [10]: fun(res.x)
Out[10]: 30623.501499999998
In [11]: fun([-1, 1000, 0, 0, 0, 0])
Out[11]: 29947.652395739999
In [12]: sp.__version__
Out[12]: '0.14.0'
我们可以看到优化器给出了错误的结果。是否有任何 python 模块可以满足要求?谢谢。