具有涉及矩阵逆的约束的凸优化

计算科学 Python 凸优化
2021-12-12 07:43:41

我有以下凸优化问题。我想问一下有没有什么有效的方法可以在 Python 中解决它?我可以使用 CVXOPT 包吗?如果有,有详细的说明吗?非常感谢。

minT[0,]10i=110Tiai
服从 这里,10 和 5 只是通用常量。如果逆不存在,我们可以用伪逆代替。
xj(i=110Tixixi)1xjbj,for all j[10].
{a1,,a10}R{x1,,x10}R5

1个回答

是的,这可以做到,请参见下面的代码块。我正在使用 CVXPY 库,该库由斯坦福的 Boyd 小组维护,并包装了 CVXOPT 求解器(除其他外)。

假设我们已经构建了该Problem data部分的输入数据,在我刚刚运行的一个简单基准测试中,Construct the problem和部分大约需要 550 毫秒。Report solution如果我们将问题大小增加 2 倍,解决方案大约需要 3.6 秒,如果我们增加 3 倍,则需要 11.5 秒。

import cvxpy as cp
import numpy as np

# Problem data.
# m is matrix dimension, n is number of terms
m, n = 5, 10
X = np.random.randn(m, n)
b = np.abs(np.random.randn(n)) # constraint upper bounds
a = np.abs(np.random.randn(n)) # objective coefficients

# Construct the problem.
T = cp.Variable(n)
A = cp.Variable((m,m))
objective = cp.Minimize(a @ T)
constraints = [A == X @ cp.diag(T) @ X.T] + \
              [T >= 0] + \
              [cp.matrix_frac(x, A) <= bi for x, bi in zip(X.T, b)]
problem = cp.Problem(objective, constraints)

# Report solution.
result = problem.solve()
print(result)