0
$\begingroup$

I am trying to formulate a convex optimization problem using CVXPY. Everything works, except a constraint that does not seem to follow DCP rules.

Let $D \in \Bbb R^n$ be a decision variable and let $Q$ be another decision variable that is derived from $D$ using the following constraint,

Q = cvxpy.pos(D)

I am not sure why this is the case. Here it states that pos is a convex atom.

$$ \mbox{pos} (x) := \max \{ x, 0 \} $$

Can someone please help me?

Edit:

Error message:

cvxpy.error.DCPError: Problem does not follow DCP rules. Specifically: The following constraints are not DCP: var1 == maximum(var0, 0.0) , because the following subexpressions are not: |-- var1 == maximum(var0, 0.0)

Minimum working example (if the 2nd constraint is switched off the program works),

import cvxpy as cp
import numpy as np

D = cp.Variable(2)
A = np.array([[1, 2], [2, 1]])
b = np.ones((2, )) * 2
Q = cp.Variable(2)

constraints = [sum(D) == 1, Q == cp.pos(D)]

prob = cp.Problem(cp.Minimize(cp.sum_squares(A @ D - b)), constraints)

prob.solve(verbose=True)
$\endgroup$
7
  • 1
    $\begingroup$ Post the error message you're getting and a MWE? Importantly, are you minimizing or maximizing your objective? $\endgroup$
    – Richard
    Jan 24, 2022 at 15:13
  • $\begingroup$ Added a MWE and error message, I am minimizing the obj func $\endgroup$ Jan 24, 2022 at 15:24
  • $\begingroup$ CVXPY is objecting to the nonlinear equality constraint, which is (non-convex) and not DCP-compliant. I'm not sure how Q is used in your problem, but do you actually want the constraint D >= 0? if so, use that. (Note: I am a CVX user, not CVXPY). $\endgroup$ Jan 24, 2022 at 15:30
  • 1
    $\begingroup$ Did you mean "regularization needs to be applied only to the NONnegative entries"? Don't use a constraint. Apply the pos or max(D,0) directly in the objective function expression. In CVX, that would be ... + M'*pos(D) I'll let you figure out the syntax in CVXPY. $\endgroup$ Jan 24, 2022 at 15:40
  • 1
    $\begingroup$ Nonlinear equality constraints are not allowed by DCP, and other than trivial cases, they are non-convex. masx(D,) <= something is allowed; max(D,0) >= something is not allowed. The term -max(Q,0) is non-convex, so not usable in a minimization objective function in CVXPY. If you really want a non-convex objective, you will need to use a non-convex (modeling system and) solver. $\endgroup$ Jan 24, 2022 at 16:01

1 Answer 1

1
$\begingroup$

The answer is based on @Mark L. Stones' comments

Nonlinear equality constraints are not allowed by DCP, and other than trivial cases, they are non-convex. Apply the pos or max(D,0) directly in the objective function expression. In CVX, that would be ... + M'*pos(D)

$\endgroup$
1
  • $\begingroup$ As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. $\endgroup$
    – Community Bot
    Jan 24, 2022 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.