我发现 CVXPY 随机失败并出现以下错误:
ArpackError: ARPACK error 3: No shifts could be applied during a cycle of the Implicitly restarted
Arnoldi iteration. One possibility is to increase the size of NCV relative to NEV.
下面的代码是一个最小示例,它只是尝试在没有约束、单位相关矩阵和正态分布均值向量的情况下进行均值方差优化。大约每千次运行失败一次。我要求它使用哪个求解器似乎并不重要,这让我认为它无法设置问题?
import cvxpy as cp
import numpy as np
n = 199
np.random.seed(100)
mu = np.random.normal(size = n)
C = np.eye(n)
for repeat in range(1000):
x = cp.Variable(n)
mean = x.T @ mu
variance = cp.quad_form(x, C)
objective = cp.Maximize(mean - variance)
constraints = []
prob = cp.Problem(objective, constraints)
result = prob.solve()
print(repeat, end = " ")