Questions tagged [cvxpy]

For mathematical questions about CVXPY; questions purely about the language, syntax, or runtime errors would likely be better received on Stack Overflow. CVXPY is a Python-embedded modeling language for convex optimization problems.

CVXPY is a Python-embedded modeling language for convex optimization problems. It allows problems to be expressed in a natural syntax which follows the math, rather in the restrictive standard form in other solvers.

For example, the following code shows an intuitive syntax for a sample problem.

from cvxpy import *

# Create two scalar optimization variables.
x = Variable()
y = Variable()

# Create two constraints.
constraints = [3*x + 2*y == 1,
               x - y <= 1]

# Form objective.
obj = Minimize(square(x + y))

# Form and solve problem.
pblm = Problem(obj, constraints)
pblm.solve()

# The optimal value for x is stored in x.value.
print x.value
# The optimal dual variable (Lagrange multiplier) for
# a constraint is stored in constraint.dual_value.
print constraints[1].dual_value

CVXPY is licensed under Apache 2.0, so you are free to use it for any purpose as long as the license text is retained.

Some useful resources for users:

31 questions
4
votes
1 answer

How to solve quadratic optimization problem with two variables

I would like to solve the support vector regression problem. The formula for the optimization is the following: $$a_1^*, a_2^* = \max\sum_{i=1}^{n} (a_{1i}-a_{2i})y_{i} - eta\sum_{i=1}^{n}(a_{1i}+a_{2i}) -…
4
votes
1 answer

How to prove an expression of log-sum-exp type is convex in DCP?

In Disciplined Convex Programming (DCP) the user should give a certificate to the program that the function (sometimes multivariate) is convex. The user should use predefined set of functions like $x^2/y$ $(x_1 \ldots x_k)^{1/k}$ $\log (e^{x_1} +…
3
votes
0 answers

Boyd & Vandenberghe, section 8.4.2 — Maximum volume ellipsoid in an intersection of ellipsoids

I originally asked this on Stack Overflow, it was suggested that I ask here. I need to find the maximum volume inscribed ellipsoid subject to linear inequality constraints and a constraining ellipsoid. I've been stuck on this for quite some time…
3
votes
1 answer

Minimal $\ell_\infty$ solution of underdetermined system of linear equations

[ Update: question solved, answer is at the end of the post] I need to solve this problem $$ \min \| x \|_{\infty} \; \text{s.t.} \; Ax = b $$ where $Ax = b$ is an underdetermined system, e.g., $A \in \mathbb{R}^{n \times m}$, with $n < m$.…
2
votes
1 answer

Rephrase convex constraint to satisfy DCP rules

Crossposted on Stack Overflow I have a convex objective function and a convex constraint of the form $$\frac{y^2}{x} + z \leq 1$$ on the domain $x \geq 0$. However, I'm not sure how to encode this constraint in a way that CVXPY will accept it. It…
JEK
  • 87
2
votes
1 answer

In CVXPY, how to use an asymmetric cost function without breaking convexity?

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…
Enzoupi
  • 151
2
votes
1 answer

Problem formulation in CVX toolbox in Python

I have an optimization problem to solve, which is a constrained least squares. I am trying to solve it using CVX toolbox in Python. Here is the optimization problem: $$\hat{H} = \arg \min_H \vert \vert A \: \text{vec}(H) - b\vert…
2
votes
1 answer

Solving the multi-dimensional scaling problem in CVXPY

I want to use the CVXPY Python toolbox to solve the simple classical multi-dimensional scaling problem. Problem: Given $n$ points in $d$-dimensional space, i.e. $\mathbf{x}_i \in \mathbb{R}^d$. The position coordinates of the points are stacked in…
2
votes
1 answer

Expressing positive semidefiniteness of block matrices in CVXPY

I am trying to solve a robust optimization problem using CVXPY. I am new to this package and also a beginner of Python. I don't know how to implement the constraint that makes a block decision variable matrix to be positive semidefinite. Can…
2
votes
1 answer

Write $\log(\cdot) \le -\exp(\cdot)$ in the DCP form

I am interested in writing $$ \log \left(\exp(-\sqrt x)+ \left(1 + \frac{y}{z} \right)^{y} \right) \leq -\exp(-z), \qquad x\geq0,y\geq0,z>0 $$ in the Disciplined Convex Programming (DCP) form. I don't know how to convert this expression to a DCP…
1
vote
0 answers

cvxpy with a tanh objective

I need to solve an optimisation problem of the form: \begin{align} \textrm{maximize} \quad &\sum_{i=1}^{n} a_i \tanh(c_i x_i/2) \\ \textrm{wrt} \quad &x_i, \quad i \in 1,\dots,n \\ \textrm{subject to} &\sum_{i=1}^{n} x_i = X \\ &x_i \ge 0, \quad i…
1
vote
1 answer

Solving a convex problem with quasiconvexity with CVXPY?

I have a question regarding quasiconvexity and its usage in CVXPY. I have the following optimization problem. \begin{equation*} \begin{aligned} \min_{x} \quad & \sqrt x\\ \textrm{subject to:} \quad & 1 \leq x \leq…
1
vote
1 answer

Efficiency of constrained LQR formulation in CVXPY via batch-approach

I am interested in formulating a discrete finite time constrained LQR in CVXPY. \begin{align} \text{minimize } & J = \sum_{k=0}^N x'(k)Qx(k) + u'(k)Ru(k) \\ \text{subject to } & x(k+1) = Ax(k) + Bu(k) \\ & Cx(k) + Du(k) \leq e \end{align} I came…
1
vote
0 answers

Maximize sum of gamma cumulative distributions as disciplined quasiconvex problem (DQCP) in CVXPY

Is is possible to formulate the maximization of the sum of gamma cumulative distributions as a disciplined quasiconvex problem (DQCP) in CVXPY? I'm trying to solve the following problem: Given $F(x) = \int_0^x t^{\alpha-1}exp(-t) dt$ (proportional…
gnarls
  • 35
1
vote
0 answers

Optimization problem that is convex and bounded is said to be unbounded in implementation

I have an optimization problem that is convex and bounded: \begin{align*} \text{Minimize}_{\text{wrt}…
1
2 3