cvxopt / cvxopt

CVXOPT -- Python Software for Convex Optimization
https://cvxopt.org
Other
990 stars 208 forks source link

Problem causes numerical issues #23

Open SteveDiamond opened 10 years ago

SteveDiamond commented 10 years ago

The solution to both of these problems is -K/2. In both cases CVXOPT runs into numerical issues for large K. The get_problem_data lines give the arguments passed to CVXOPT by CVXPY. CVXPY uses the LDL KKT solver with iterative refinement.

import cvxpy

# Numerical problems with quad_form.
K=250
u = cvxpy.Variable()
cost_optimizer=K*u+cvxpy.quad_form(u, 1)
objective = cvxpy.Minimize(cost_optimizer)
problem=cvxpy.Problem(objective)
problem.solve(verbose=True, solver=cvxpy.CVXOPT)
# Should be near 0.
print u.value + K/2

c, G, h, dims, A, b = problem.get_problem_data(solver=cvxpy.CVXOPT)

# Numerical problems with square.
K=250
u = cvxpy.Variable()
cost_optimizer=K*u+cvxpy.square(u)
objective = cvxpy.Minimize(cost_optimizer)
problem=cvxpy.Problem(objective)
problem.solve(verbose=True, solver=cvxpy.CVXOPT)
# Should be near 0.
print u.value + K/2

c, G, h, dims, A, b = problem.get_problem_data(solver=cvxpy.CVXOPT)
martinandersen commented 10 years ago

Thanks for the examples. I think this may be a scaling issue since the problem goes away when K is somewhat smaller or if you increase feastol and/or reltol a bit. We'll look into this.

On a different note, I noticed that the first row of G, h corresponds to the linear inequality constraint 0 <= 1 (equivalently, 0 + s[0] == 1) which means that it can be removed.