# Why is a elementwise max not DCP?

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 \}$$

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)

• Post the error message you're getting and a MWE? Importantly, are you minimizing or maximizing your objective? Jan 24, 2022 at 15:13
• Added a MWE and error message, I am minimizing the obj func Jan 24, 2022 at 15:24
• 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). Jan 24, 2022 at 15:30
• 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. Jan 24, 2022 at 15:40
• 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. Jan 24, 2022 at 16:01