cp(F[, G, h[, dims[, A, b[, kktsolver]]]])
Solves a convex optimization problem
![]() | (9.1) |
The argument F is a function that evaluates the objective and nonlinear constraint functions. It must handle the following calling sequences.
If F is called with two arguments, it can be assumed that x is in the domain of f.
The linear inequalities are with respect to a cone C defined as a Cartesian product of a nonnegative orthant, a number of second-order cones, and a number of positive semidefinite cones:
with
Here vec(u) denotes a symmetric matrix u stored as a vector in column major order.
The arguments h and b are real single-column dense matrices. G and A are real dense or sparse matrices. The default values for A and b are sparse matrices with zero rows, meaning that there are no equality constraints. The number of rows of G and h is equal to
The columns of G and h are vectors in
where the last N components represent symmetric matrices stored in column major order. The strictly upper triangular entries of these matrices are not accessed (i.e., the symmetric matrices are stored in the ’L’-type column major order used in the blas and lapack modules).
The argument dims is a dictionary with the dimensions of the cones. It has three fields.
The default value of dims is {’l’: h.size[0], ’q’: [], ’s’: []}, i.e., the default assumption is that the linear inequalities are componentwise inequalities.
The role of the optional argument kktsolver is explained in section 9.4.
cp() returns a dictionary with keys ’status’, ’x’, ’snl’, ’sl’, ’y’, ’znl’, ’zl’. The possible values of the ’status’ key are:
where = (f1,…,fm),
cp() requires that the problem is solvable and that
for all x and all positive z.
The equality constrained analytic centering problem is defined as
The function acent() defined below solves the problem, assumping it is solvable.
from cvxopt import solvers
from cvxopt.base import matrix, spdiag, log def acent(A, b): m, n = A.size def F(x=None, z=None): if x is None: return 0, matrix(1.0, (n,1)) if min(x) <= 0.0: return None f = -sum(log(x)) Df = -(x**-1).T if z is None: return f, Df H = spdiag(z[0] * x**-2) return f, Df, H return solvers.cp(F, A=A, b=b)[’x’] |
The function robls() defined below solves the unconstrained problem
from cvxopt import solvers
from cvxopt.base import matrix, spdiag, sqrt, div def robls(A, b, rho): m, n = A.size def F(x=None, z=None): if x is None: return 0, matrix(0.0, (n,1)) y = A*x-b w = sqrt(rho + y**2) f = sum(w) Df = div(y, w).T * A if z is None: return f, Df H = A.T * spdiag(z[0]*rho*(w**-3)) * A return f, Df, H return solvers.cp(F)[’x’] |
from cvxopt.base import matrix, log, div, spdiag
from cvxopt import solvers def F(x = None, z = None): if x is None: return 0, matrix(0.0, (3,1)) if max(abs(x)) >= 1.0: return None u = 1 - x**2 val = -sum(log(u)) Df = div(2*x, u).T if z is None: return val, Df H = spdiag(2 * z[0] * div(1 + u**2, u**2)) return val, Df, H G = matrix([ [0., -1., 0., 0., -21., -11., 0., -11., 10., 8., 0., 8., 5.], [0., 0., -1., 0., 0., 10., 16., 10., -10., -10., 16., -10., 3.], [0., 0., 0., -1., -5., 2., -17., 2., -6., 8., -17., -7., 6.] ]) h = matrix([1.0, 0.0, 0.0, 0.0, 20., 10., 40., 10., 80., 10., 40., 10., 15.]) dims = {’l’: 0, ’q’: [4], ’s’: [3]} sol = solvers.cp(F, G, h, dims) print sol[’x’] [ 4.11e-01] [ 5.59e-01] [-7.20e-01] |