3
$\begingroup$

I have tried to solve an optimization problem using CVXPY library. This problem aims to minimize the distance between a vector of $n$ variables ($\beta$), which can be positive or negative real numbers and another n-dimensional vector ($s$) containing only positive real number, as follows

beta = cp.Variable(n)
problem = cp.Problem(cp.Minimize(cp.abs(cp.norm1(beta) - cp.norm1(s))))

I tried cp.norm1(beta) - cp.norm1(s) and it worked fine, but I want to make sure that the result of the difference between both vectors must be positive. However, when I add abs, I got the error saying that "this problem does not follow DCP rules". I am not sure how to resolve this error.

$\endgroup$

1 Answer 1

7
$\begingroup$

I think you want cp.norm1(beta - s), with no need for abs. This is DCP-compliant.

Taking separate norms of beta and s doesn't make sense for what you describe.

Edit: Note that by using norm1, you are minimizing L1 distance. That's fine if that's what you really want. However, distance, when not otherwise qualified, more commonly means L2 (Euclidean) distance, for which you would use norm (with default p) or norm2.

$\endgroup$
0

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.