CVXPY is a Python-embedded modeling language for convex optimization problems inspired by the MATLAB package CVX.
Questions tagged [cvxpy]
609 questions
38
votes
4 answers
Python constrained non-linear optimization
What's the recommended package for constrained non-linear optimization in python ?
The specific problem I'm trying to solve is this:
I have an unknown X (Nx1), I have M (Nx1) u vectors and M (NxN) s matrices.
max [5th percentile of (ui_T*X), i in 1…

akhil
- 839
- 3
- 8
- 15
12
votes
1 answer
From CVX to CVXPY or CVXOPT
I've been trying to pass some code from Matlab to Python. I have the same convex optimization problem working on Matlab but I'm having problems passing it to either CVXPY or CVXOPT.
n = 1000;
i = 20;
y = rand(n,1);
A = rand(n,i);
cvx_begin
variable…

silgon
- 6,890
- 7
- 46
- 67
8
votes
2 answers
Initial Guess/Warm start in CVXPY: give a hint of the solution
In this bit of code:
import cvxpy as cvx
# Examples: linear programming
# Create two scalar optimization variables.
x = cvx.Variable()
y = cvx.Variable()
# Create 4 constraints.
constraints = [x >= 0,
y >= 0,
x + y >=…

Riley
- 933
- 10
- 26
8
votes
3 answers
Install Python Packages in Azure ML?
Similar question as here but now on Python packages. Currently, the CVXPY is missing in Azure ML. I am also trying to get other solvers such as GLPK, CLP and COINMP working in Azure ML.
How can I install Python packages in Azure ML?
Update about…

hhh
- 50,788
- 62
- 179
- 282
7
votes
1 answer
What are the specific reasons for CVXPY to throw `SolverError` exception?
I am using CVXPY (version 1.0) to solve a quadratic program (QP) and I often get this exception:
SolverError: Solver 'xxx' failed. Try another solver.
which makes my program really fragile. I have tried different solvers, including CVXOPT, OSQP,…

Tony
- 445
- 6
- 13
6
votes
2 answers
Constructing fused lasso penalty with cvxpy package in python
Fused Lasso (Tibshirani et al, 2005) encourages sparsity of the coefficients and also sparsity of their differences.
This is the formula for the loss function and regularization:
The first term is the L2 (mse) loss, the second is an L1 penalty on…

Mine
- 831
- 1
- 8
- 27
6
votes
1 answer
Integer Linear Programming with CVXPY in python3
I'm trying to solve an integer linear programming problem using the CVXPY but am struggling with some syntax and can not figure out a way of how to enforce my variable that I'm interested to solve for the constraint to take values of either 0 or 1.…

user3289556
- 155
- 2
- 11
6
votes
3 answers
Trying to solve Sudoku with cvxpy
I'm trying to solve a Sudoku with cvxpy optimization package.
I'm really new to both optimization and cvxpy.
The constraints are:
all the values are between 1 to 9
sum of all rows = 45
sum of all columns = 45
sum of all squares = 45
the given…

Binyamin Even
- 3,318
- 1
- 18
- 45
6
votes
3 answers
cvxpy stlibc++ Installation error on MacOS Mojave
While trying to install cvxpy package using pip install on Mac, I get the following error message:
warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead…

dheena
- 61
- 1
- 4
6
votes
1 answer
Block LMI in CVXPY
I want to translate a LMI-constrained optimization problem from Matlab to Python. While reading the CVXPY documentation, I found that I can define an LMI-constrained problem by creating a matrix variable and adding the corresponding constraint.…

czr
- 658
- 3
- 13
6
votes
0 answers
python least squares regression modification to objective function
Least squares regression is defined as the minimization of the sum of squared residuals e.g.
Minimize(sum_squares(X * beta - y))
However, I'd like to propose a slight modification such that we are still minimizing the…

Michael
- 7,087
- 21
- 52
- 81
6
votes
1 answer
Constraints do not follow DCP rules in CVXPY
I want to solve this problem using CVXPY but I don't know why I get the following error message:
DCPError: Problem does not follow DCP rules.
I guess my constraints are not DCP. Is there any way to model this in DCP?
n_k = [10000,…

mahdieh ahmadi
- 101
- 1
- 1
- 5
6
votes
1 answer
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…

goldenbear137
- 81
- 1
- 1
- 4
5
votes
1 answer
Using python-mip library with cvxpy syntax
I need to use CBC solver for mixed integer optimization problem, however in the target environment I cannot use CBC solver installed as an outsource software, it has to be a part of the python library. To overcome this problem I found mip library…

Joanna
- 51
- 1
5
votes
1 answer
How to invert a matrix of variables in cvxpy?
How do I invert a matrix of variables in cvxpy?
I have a matrix of problem variables defined as follows:
import cvxpy as cp
A = cp.Variable(2,2)
and I want to solve a program with an objective function involving the inverse of this matrix. I have…

DLim
- 93
- 5