error using2 norm insid quad_form in objective function

117 views
Skip to first unread message

Sandeep hegde

unread,
Apr 27, 2021, 3:24:56 AM4/27/21
to cvxpy
Hello members,

I want to add this term to my objective function
Wij( || X- Y ||_2 - D)^2

where Wij, D are scalars. ||X-Y||_2 is 2-norm, X&Y are vectors of size 3. If I make the below formulation in cvxpy, I get an error:

import cvxpy as cp
import numpy as np

= cp.Variable(3)
Y = np.array([1,2,3])

term = cp.norm(x- Y,2)-D
cost = 10*cp.quad_form(term,1)
# constraints not shown, but correctly in place

problem = cp.Problem(cp.Minimize(cost),constraints)
problem.solve(verbose = True,solver='OSQP')

raise ValueError("Invalid dimensions for arguments.")
ValueError: Invalid dimensions for arguments.

Is this formulation correct, allowed? If not, how can I change this? In the second argument of quad_form instead of 1, I tried np.eye(1) but it doesn't help. Can someone kindly guide me?

Thank you
Sandeep

Michal Adamaszek

unread,
Apr 28, 2021, 2:49:05 AM4/28/21
to cvxpy

You can only have affine expressions in quad_form. Also, the term you are trying to create is not convex.

Michal

Sandeep hegde

unread,
Apr 28, 2021, 9:25:42 AM4/28/21
to cvxpy
Hi Mr. Adamaszek,

Thanks for your reply. I have a question again: I have a constraint || X- Y ||_2 >= D which can be also written equivalently as (|| X- Y ||_2 - D)^2 according to this research paper (please see the attachment). I have to include this term in my objective function which also contains some other quadratic terms already. Is there any way to do this in cvxpy? If I consider norm function in cvxpy, then it cannot be reduced to QP anymore.
Screenshot from 2021-04-28 15-22-22.png

Thank you in advance
Sandeep

Michal Adamaszek

unread,
Apr 28, 2021, 3:24:12 PM4/28/21
to cvxpy
Sorry but I don't see how to make any mathematical sense of the highlighted statement. 

Sunghee Yun

unread,
Apr 29, 2021, 4:04:37 AM4/29/21
to cvxpy
Hi Sandeep,

In addition to Michal's comment above, the constraints, $\|X_i - X_j^P\|_2 \geq D" is not convex constraints, hence cvxpy wouldn't accept it.

Best,
Sunghee
Reply all
Reply to author
Forward
0 new messages