简体   繁体   English

CVXPY 二次规划; ArpackNoConvergence 错误

[英]CVXPY Quadratic Programming; ArpackNoConvergence error

I'm trying to use the Python package CVXPY to solve a convex quadratic programming problem of the first form here: https://www.cvxpy.org/examples/basic/quadratic_program.html , using the following code I'm trying to use the Python package CVXPY to solve a convex quadratic programming problem of the first form here: https://www.cvxpy.org/examples/basic/quadratic_program.html , using the following code

x = np.variable(2 * N)
prob = cp.Problem(cp.Minimize((1/2) * cp.quad_form(x, P) + q @ x), [G @ x <= h, A @ x == b])
prob.solve(solver=cp.OSQP, verbose=True)

However, for certain data, it gives me the error但是,对于某些数据,它给了我错误

ArpackNoConvergence: ARPACK error -1: No convergence (1001 iterations, 0/1 eigenvectors converged)

From searching the internet, it seems like this can be addressed either by increasing the number of iterations in ARPACK, or by increasing the tolerance.通过搜索互联网,似乎可以通过增加 ARPACK 中的迭代次数或增加容差来解决此问题。 CVXPY has options for both max_iters and for absolute accuracy, but these don't seem to affect the number of iterations in ARPACK, and I assume they apply to some higher level part of the solver. CVXPY 有 max_iters 和绝对精度的选项,但这些似乎不会影响 ARPACK 中的迭代次数,我假设它们适用于求解器的更高级别部分。

I can't find any references online to this specific problem, or indeed to ARPACK in conjunction with CVXPY.我在网上找不到任何关于这个特定问题的参考资料,或者确实找不到与 CVXPY 一起使用的 ARPACK。 I'm pretty stumped by this, and would really appreciate any help.我对此感到很困惑,非常感谢任何帮助。

Without running this (code is obviously incomplete), there are two candidates:不运行这个(代码显然不完整),有两个候选:

  • A : OSQP:OSQP
  • B : Internal PSD-checks within cvxpy (before submitting data to solvers!) B :cvxpy 中的内部 PSD 检查(在将数据提交给求解器之前!)

I'm guessing it's B (and you might switch to some other solver to reason about it).我猜它是B (你可能会切换到其他求解器来推理它)。

The iteration-parameter you are setting is related to the solvers and if i'm guessing correctly, you are not even reaching this point (error in canonicalization-phase).您设置的迭代参数与求解器有关,如果我猜对了,您甚至还没有达到这一点(规范化阶段错误)。

It seems, your matrix induces trouble in regards to iterative eigenvalue-computations (ARPACK).看来,您的矩阵在迭代特征值计算(ARPACK)方面引起了麻烦。 Maybe this can be seen by it's condition-number.也许这可以通过它的条件数看出。

Not sure, if there is an easy transformation / perturbation for your use-case to improve the conditioning here.不确定,如果您的用例有一个简单的转换/扰动来改善这里的条件。

Lots of internals are not easily accessable without rebuilding cvxpy from sources, but in this case you might get away by changing cvxpy.settings.settings.EIGVAL_TOL :如果不从源代码重建 cvxpy,很多内部组件都不容易访问,但在这种情况下,您可以通过更改cvxpy.settings.settings.EIGVAL_TOL来摆脱困境:

import cvxpy as cp
print(cp.settings.EIGVAL_TOL)
# 1e-10
cp.settings.EIGVAL_TOL = 1e-08

... do your work

(If your data is not totally broken due to some mistake AND not confidential, i would assume cvxpy-people would be happy to obtain your data as example too re-evaluate some internal tolerances -> github issue with reproducible code incl. data ) (如果您的数据由于某些错误而不是机密而没有完全损坏,我会假设 cvxpy-people 很乐意获取您的数据作为示例,也重新评估一些内部公差 - > github 问题与可重现的代码,包括数据

It is because that ARPACK can fail to converge on PSD matrices due to numerical issues, and failures occur randomly.这是因为 ARPACK 可能由于数值问题而无法在 PSD 矩阵上收敛,并且失败是随机发生的。 See discussions in见讨论

If you know that P is a PSD and the PSD check failed, then you can replace P by如果您知道 P 是 PSD 并且 PSD 检查失败,那么您可以将 P 替换为

P = cvxpy.atoms.affine.wraps.psd_wrap(P).

to skip the PSD check.跳过 PSD 检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM