Hi, I'm having some trouble getting a simple problem to converge. I have a working version using MATLAB as follows:
A = [1., 1., 1., 1., 1., 1., 1., 1.;
1., 1., 0., 0., 0., 0., 0., 0.;
0., 0., 1., 1., 0., 0., 0., 0.;
0., 0., 0., 0., 1., 1., 0., 0.;
0., 0., 0., 0., 0., 0., 1., 1.;
1., 0., 1., 0., 0., 0., 0., 0.;
0., 1., 0., 1., 0., 0., 0., 0.;
0., 0., 0., 0., 1., 0., 1., 0.;
0., 0., 0., 0., 0., 1., 0., 1.;
1., 0., 0., 0., 1., 0., 0., 0.;
0., 1., 0., 0., 0., 1., 0., 0.;
0., 0., 1., 0., 0., 0., 1., 0.;
0., 0., 0., 1., 0., 0., 0., 1.]
b = [1; 1/4; 1/4; 1/4; 1/4; 1/2; 0; 1/4; 1/4; 1/2; 0; 1/4; 1/4]
[m,n] = size(A)
cvx_begin
variable x(n) nonnegative
minimize (norm(A*x - b, inf))
cvx_end
from cvxopt import matrix
from cvxopt.solvers import cp, options
import scipy.linalg as linalg
From a linear system Ax = b, return Bx = c such that B has full rank.
Smat = linalg.diagsvd(S, A.shape[0], A.shape[1])
# See np.linalg.matrix_rank
tol = S.max() * max(A.shape) * np.finfo(S.dtype).eps
B = np.dot(Smat, Vh)[:rank]
c = np.dot(U.transpose(), b)[:rank]
[ 1., 1., 1., 1., 1., 1., 1., 1.],
[ 1., 1., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 1., 1., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 1., 1., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 1., 1.],
[ 1., 0., 1., 0., 0., 0., 0., 0.],
[ 0., 1., 0., 1., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 1., 0., 1., 0.],
[ 0., 0., 0., 0., 0., 1., 0., 1.],
[ 1., 0., 0., 0., 1., 0., 0., 0.],
[ 0., 1., 0., 0., 0., 1., 0., 0.],
[ 0., 0., 1., 0., 0., 0., 1., 0.],
[ 0., 0., 0., 1., 0., 0., 0., 1.]
b = np.array([ 1. , 0.25, 0.25, 0.25, 0.25, 0.5 , 0.,
0.25, 0.25, 0.5 , 0. , 0.25, 0.25])
# Dimension of optimization variable
# Number of nonlinear constraints
# Nonnegativity constraint
G = matrix( -1 * np.eye(n) ) # G should have shape: (K,n) = (n,n)
h = matrix( np.zeros((n,1)) ) # h should have shape: (K,1) = (n,1)
# Linear equality constraints (these are not independent constraints)
AA, bb, rank = full_rank(A, b)
b = matrix(bb) # now a column vector
return np.max(np.abs(A * x - b))
grad = numdifftools.Gradient(func)
hess = numdifftools.Hessian(func)
# z has shape: (m+1,1) and is the Hessian of f_0
if x is None and z is None:
if np.any(xarr > 1) or np.any(xarr < 0):
if not np.allclose(np.sum(xarr), 1):
Df = matrix(Df.reshape((1,n)))
result = cp(F=F, G=G, h=h, dims={'l':n, 'q':[], 's':[]}, A=A, b=b)
out = np.asarray(result['x'])
pcost dcost gap pres dres
0: 0.0000e+00 1.5752e-01 9e+00 1e+00 1e+00
1: 6.1745e-01 2.9734e-01 5e+00 6e-01 4e-01
2: 9.7355e-01 4.3862e-01 3e+00 3e-01 3e-01
3: 1.0115e+00 4.5308e-01 3e+00 3e-01 2e-01
4: 1.0677e+00 4.6902e-01 3e+00 2e-01 2e-01
5: 1.0957e+00 4.6693e-01 3e+00 2e-01 2e-01
6: 1.1030e+00 4.6411e-01 3e+00 2e-01 2e-01
7: 1.1049e+00 4.6324e-01 3e+00 2e-01 2e-01
8: 1.1054e+00 4.6301e-01 3e+00 2e-01 2e-01
9: 1.1054e+00 4.6300e-01 3e+00 2e-01 2e-01
10: 1.1054e+00 4.6299e-01 3e+00 2e-01 2e-01
11: 1.1054e+00 4.6299e-01 3e+00 2e-01 2e-01