3
$\begingroup$

I'm trying to use the cvxopt quadratic solver to find a solution to a Kernel SVM but I'm having issues. I'm back to solving a very simple quadratic program:

\begin{gather*} \min_{x\in\mathbb{R}^n} \frac{1}{2}x^\intercal Px + q^\intercal P \end{gather*}

I get the error ValueError: Rank(A) < p or Rank([P; A; G]) < n. As I don't specify A or G I thought the problem might come from the fact that Rank(P) < n but it's not the case as P is full-ranked. The code below reproduces this error:

import numpy as np
import cvxopt

n = 5

P = np.random.rand(n,n)
P = P.T + P + np.eye(n)
q = 2 * np.random.randint(2, size=n) - 1

P = cvxopt.matrix(P.astype(np.double))
q = cvxopt.matrix(q.astype(np.double))

print(np.linalg.matrix_rank(P))

solution = cvxopt.solvers.qp(P, q)

Complete error:

Traceback (most recent call last):      
    solution = cvxopt.solvers.qp(P, q)
  File "python2.7/site-packages/cvxopt/coneprog.py", line 4470, in qp
    return coneqp(P, q, G, h, None, A,  b, initvals, kktsolver = kktsolver, options = options)
  File "python2.7/site-packages/cvxopt/coneprog.py", line 2013, in coneqp
    raise ValueError("Rank(A) < p or Rank([P; A; G]) < n")
ValueError: Rank(A) < p or Rank([P; A; G]) < n

Any idea?

  • 0
    I believe this question is off-topic for this group.2017-02-18

1 Answers 1

3

It appears that the qp() solver requires that the matrix $P$ is positive semi-definite.

You are initially generating $P$ as a matrix of random numbers: sometimes $P' + P + I$ will be positive semi-definite, but other times it will not.

The likelihood is you've run your code and been unlucky that $P$ does not meet this criterion. (It is possible to be lucky: if I set np.random.seed(123) first, then your code runs without error.)

As further evidence that this is the problem here, from the traceback I see that cvxopt attempts to do Cholesky factorisation using LAPACK's potrf routine, which fails and raises an ArithmeticError. The documents for this routine in cvxopt state that an ArithmeticError is indeed raised if the matrix is not positive definite.