当我的矩阵是 PSD 时,为什么会出现此 DCPError?

计算科学 凸优化 简历
2021-12-16 19:15:04
import cvxpy as cp
import numpy as np

n = 3
PP = cp.Variable((n,n),"PP")
KK = [[2,1,3],[1,2,1],[3,1,2]]
s = np.array([[.1, .4, .5]]).T
t = np.array([[.4, .2, .4]]).T
e = np.ones((n,1))
x = PP.T@e - s
y = PP@e - t
for b in range(1,21):
    obj = (1/4/b) * (cp.quad_form(x,KK) + cp.quad_form(y,KK)) - cp.trace(KK@PP) 
    prob = cp.Problem(cp.Minimize(obj),[PP>=0,cp.sum(PP)==1])
    obj=prob.solve()
    print("status:",prob.status)
    print("obj:",obj)
    print(PP.value)

当我运行这个时,我得到

cvxpy.error.DCPError: Problem does not follow DCP rules. Specifically:
The objective is not DCP. Its following subexpressions are not:
QuadForm(PP.T * [[1.]
 [1.]
 [1.]] + -[[0.1]
 [0.4]
 [0.5]], [[2. 1. 3.]
 [1. 2. 1.]
 [3. 1. 2.]])

当我的矩阵 KK 明显是 PSD 时,我不明白为什么会出现此错误。为什么会这样?

==========

在此处复制https://stackoverflow.com/q/60745793/649090

1个回答

因为矩阵 KK 不是 PSD。它的最小特征值为-1。它是不确定的。

也许您误解了所有元素为正的对称矩阵是 PSD。如本例所示,情况并非如此。