我在 Python 中使用 CVXOPT 来尝试解决一个相当简单的二次规划问题。我发现它对我的参数的某些值非常有效,但对其他参数值却失败了。
下面显示的是一个非常简单的失败示例cvxopt.solvers.qp()
,其中三个示例之一失败。
您可以看到所有示例在性质上都非常相似。谁能告诉我为什么 CVXOPT 无法解决这三个问题的中间问题?
非常感谢
import numpy as np
from cvxopt.solvers import qp
from cvxopt import matrix
print '-'*70
print 'Case 1:'
P = np.array([[ 0.0084, 0.003 ],
[ 0.003, 0.0017]])
q = np.array([[-0.36],
[-0.02]])
G = np.array([[ 1., 0.],
[ 0., 1.]])
h = np.array([[ 500.],
[ 500.]])
results = qp(
matrix(P),
matrix(q),
matrix(G),
matrix(h),
)
print results # Works fine, {'status': 'optimal'}
print results['x']
print 'Works fine'
print '-'*70
print 'Case 2:'
P = np.array([[ 0.0042 , 0.0015 ],
[ 0.0015 , 0.00085]])
q = np.array([[-0.48],
[-0.06]])
G = np.array([[ 1., 0.],
[ 0., 1.]])
h = np.array([[ 500.],
[ 500.]])
results = qp(
matrix(P),
matrix(q),
matrix(G),
matrix(h),
)
print results # Fails, reaches max_iter, {'status': 'unknown'}
print '***Fails***'
print '-'*70
print 'Case 3:'
P = np.array([[ 0.0021 , 0.00075 ],
[ 0.00075 , 0.000425]])
q = np.array([[-0.54],
[-0.08]])
G = np.array([[ 1., 0.],
[ 0., 1.]])
h = np.array([[ 500.],
[ 500.]])
results = qp(
matrix(P),
matrix(q),
matrix(G),
matrix(h),
)
print results # Works fine, {'status': 'optimal'}
print results['x']
print 'Works fine'