2

I am facing a problem with a CVX(PY). I want to solve an optimization problem over a variable $x$ of dimension $n$ with the cost function

$$c=\sum^n (x-1)^2$$

and subject to some constraints. This is perfectly convex and hence I am able to solve it using CVX(PY) as long as my constraints are convex.

Now I would like to be able to introduce asymmetry in the cost function. For example, I would like to penalize $x > 1$ more than $x \le 1$. A corresponding cost function could be :

$$c=\begin{cases} \displaystyle\sum (a(x-1))^2 & \text{if } x \le 1\\\\ \displaystyle\sum (b(x-1))^2 & \text{if } x > 1 \end{cases}$$

This cost function remain convex for any $(a,b)$ and continuous. So, up to my understanding, I could use in principle CVX(PY) to solve my problem.

However, CVX(PY) detects non-convex problems whenever I introduce $\min(\cdot)$, $\max(\cdot)$, $\mbox{sign}(\cdot)$ functions which are in general not convex.

Has anyone used a non symmetric cost function with CVX(PY) ? Or has any idea on how to cope with my problem ?

Thank you in advance for any help or hints :)

Enzoupi
  • 151

1 Answers1

2

I might have been on the wrong site indeed. However, I have found how to solve my issue.

Reading more about DCP rules and how to deal with them in CVXPY, I understood that it was indeed not a math-related problem. I read that I should use pos and neg as CVXPY knows that they are convex when it is not true with min and max .

My cost function ended up being as written below where a and b are my penalization coefficients.

cost = cp.sum(cp.power(a*cp.pos(x - 1), 2)) + cp.sum(cp.power(b*cp.neg(x -   1), 2))
Enzoupi
  • 151