8.1 Problems with Nonlinear Objectives

cp(F[, G, h[, dims[, A, b[, kktsolver]]]])

Solves a convex optimization problem

minimize   f0(x )
subject to fk(x) ≤ 0, k = 1,...,m
          Gx ≼ h
          Ax = b,
(8.1)

The argument F is a function that evaluates the objective and nonlinear constraint functions. It must handle the following calling sequences.

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:

C = C  × C × ⋅⋅⋅× C  × C     × ⋅⋅⋅× C
      0   1        M     M+1        M+N

with

          l                                            rk-1                                          {            tk}
C0 = {u ∈ R | uk ≥ 0, k = 1,...,l}, Ck+1 = {(u0,u1) ∈ R×R    | u0 ≥ ∥u1∥2}, k = 0,...,M - 1, Ck+M+1  =  vec(u) | u ∈ S+ , k = 0,...,N - 1.

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

       M∑-1    N∑- 12
K = l+     rk +    tk.
        k=0     k=0

The columns of G and h are vectors in

Rl × Rr0 × ⋅⋅⋅× RrM -1 × Rt20 × ⋅⋅⋅× Rt2N-1,

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.

dims[’l’]:
l, the dimension of the nonnegative orthant (a nonnegative integer).
dims[’q’]:
[r0,,rM-1], a list with the dimensions of the second-order cones (positive integers).
dims[’s’]:
[t0,,tN-1], a list with the dimensions of the positive semidefinite cones (nonnegative integers).

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 8.4.

cp() returns a dictionary that contains the result and information about the accuracy of the solution. The most important fields have keys ’status’, ’x’, ’snl’, ’sl’, ’y’, ’znl’, ’zl’. The possible values of the ’status’ key are:

’optimal’
In this case the ’x’ entry of the dictionary is the primal optimal solution, the ’snl’ and ’sl’ entries are the corresponding slacks in the nonlinear and linear inequality constraints, and the ’znl’, ’zl’ and ’y’ entries are the optimal values of the dual variables associated with the nonlinear inequalities, the linear inequalities, and the linear equality constraints. These vectors approximately satisfy the Karush-Kuhn-Tucker (KKT) conditions
∇f0(x)+D ˜f(x)T znl+GT zl+AT y = 0,   ˜f(x)+snl = 0, k = 1,...,m,    Gx+sl = h,   Ax = b,

where f˜= (f1,,fm),

                                         T      T
snl ≽ 0,   sl ≽ 0,  znl ≽ 0,   zl ≽ 0,  snlznl + sl zl = 0.

’unknown’
This indicates that the algorithm terminated before a solution was found, due to numerical difficulties or because the maximum number of iterations was reached. The ’x’, ’snl’, ’sl’, ’y’, ’znl’ and ’zl’ contain the iterates when the algorithm terminated.

cp() solves the problem by applying cpl() to the epigraph form problem

minimize   t
subject to f0(x ) ≤ t
          fk(x) ≤ 0, k = 1,...,m
          Gx ≼ h
          Ax = b.

The other entries in the output dictionary of cp() describe the accuracy of the solution and are copied from the output of cpl() applied to this epigraph form problem.

cp() requires that the problem is strictly primal and dual feasible and that

                  ([ ∑m       2       T                       T ])
rank(A) = p,   rank     k=0zk∇  fk(x)  A   ∇f1 (x) ⋅⋅⋅∇fm (x ) G     = n,

for all x and all positive z.

Example: equality constrained analytic centering

The equality constrained analytic centering problem is defined as

            ∑
minimize   -   mi=1 logxi
subject to Ax = b.

The function acent() defined below solves the problem, assumping it is solvable.

from cvxopt import solvers, 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’]

Example: robust least-squares

The function robls() defined below solves the unconstrained problem

          ∑m                               m×n          ∘ ----2-
minimize    k=1ϕ((Ax - b)k),   where  A ∈ R    , ϕ (u) =   ρ+ u .

from cvxopt import solvers, 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’]

Example: analytic centering with cone constraints
minimize   - log(1- x21)- log(1 - x22) - log(1- x23)
subject to ∥x∥ ≤ 1
             ⌊2             ⌋     ⌊              ⌋     ⌊               ⌋   ⌊            ⌋
               - 21 - 11  0          0   10   16          - 5   2  - 17      20  10  40
           x1⌈ - 11   10  8 ⌉+ x2 ⌈ 10  - 10 - 10 ⌉ + x3⌈   2  - 6   8 ⌉ ≼ ⌈ 10  80  10 ⌉.
                  0    8  5         16  - 10   3         - 17  - 7   6       40  10  15

from cvxopt import matrix, log, div, spdiag, 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]