1

Crossposted on Mathematics SE


I have a convex objective function and a convex constraint of the form $y^2/x + z \leq 1$ on the domain $x \geq 0$. But I'm not sure how to encode this constraint in a way that cvxpy will accept it. It seems to be rejecting it because it can't convince itself that the constraint is convex.

Here is a simple example code

import numpy as np
import cvxpy as cp

n = 5
x = cp.Variable(n)

xtarget = np.random.normal(0, 1, n)
A = np.random.normal(0, 1, [n, n])
B = np.random.normal(0, 1, [n, n])
y = A @ x
z = B @ x
obj = cp.sum_squares(xtarget - x)
constraints = [x>= 0, y ** 2 / x + z <= 1]
prob = cp.Problem(cp.Minimize(obj), constraints)
prob.solve()

This gives the error:

DCPError: Problem does not follow DCP rules. Specifically:
The following constraints are not DCP

I have tried to replace y ** 2 / x + z <= 1 with cp.multiply(y ** 2, cp.pos_inv(x)) + z <= 1 so that it know that $x$ variable is non-negative. It still gives me the DCP error.

Is there a way to reformulate the problem such that it satisfies the DCP rules?

Rodrigo de Azevedo
  • 1,097
  • 9
  • 17
JEK
  • 11
  • 3
  • @RodrigodeAzevedo $y^2/x$ is parsed element wise operation here. Yes to second comment. $z \leq 1$ should be implied right? I don’t think I need to add that. – JEK Mar 05 '23 at 15:45
  • 1
    Thanks @RodrigodeAzevedo I made a post in math stack exchange. https://math.stackexchange.com/q/4652619/632365 – JEK Mar 05 '23 at 17:06

1 Answers1

0

You should use the cvxpy function quad_over_lin(y,x) to express y^2/x.