Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Element-wise multiplication in CVXPY

I am trying to do element-wise multiplication in CVXPY in the objective function. Is this allowed as part of a convex problem?

X is a n x 1 variable. V is a n x n constant.

I want to do the equivalent of np.multiply(X, V*X), which returns an n x 1 vector.

like image 747
goldenbear137 Avatar asked Apr 11 '17 00:04

goldenbear137


People also ask

What is the difference between Cvxpy and Cvxopt?

In cvxopt you have to write your problem in a more standard way for the type of solver you want to use, whereas cvxpy is supposed to adapt your problem based on the structure you use for your problem (they are supposed to select the type of cvxopt solver depending on your problem and pass the variables in an standard ...

Is DCP a Cvxpy?

Disciplined convex programming (DCP) is a system for constructing mathematical expressions with known curvature from a given library of base functions. CVXPY uses DCP to ensure that the specified optimization problems are convex. This section of the tutorial explains the rules of DCP and how they are applied by CVXPY.

What is the default solver for Cvxpy?

CVXPY comes with ECOS_BB – an open source mixed-integer nonlinear solver – by default.

How does Cvxpy define constraints?

The preferred way of creating a NonPos constraint is through operator overloading. To constrain an expression x to be non-positive, simply write x <= 0 ; to constrain x to be non-negative, write x >= 0 . The former creates a NonPos constraint with x as its argument, while the latter creates one with -x as its argument.


1 Answers

I think the function you're looking for is cvx.multiply

For example:

In [1]: import cvxpy as cvx

In [2]: n = 10

In [3]: X = cvx.Variable((n, 1))

In [4]: V = cvx.Variable((n, n))

In [5]: cvx.multiply(X, V*X)
Out[5]: Expression(UNKNOWN, UNKNOWN, (10, 1))

In the 1.0 update notes, they mention that this function used to be called mul_elemwise (<1.0), which may have been the source of your confusion.

like image 133
captaincapsaicin Avatar answered Oct 02 '22 07:10

captaincapsaicin