Questions tagged [cvxpy]

CVXPY is a Python-embedded modeling language for convex optimization problems inspired by the MATLAB package CVX.

609 questions
2
votes
1 answer

CVXPY: DCPError: Problem does not follow DCP rules

I am trying to code a problem solves B(2,1) under LMI constraints. R(2,1)=R0(2,1)+H(2,2)*B(2,1) Vc is a scalar variable It keeps getting > "DCPError: Problem does not follow DCP rules." import numpy as np import cvxpy as cp H =…
2
votes
1 answer

cvxpy: Converting a nonlinear constraint to an equivalent linear constraint

Context: I'm the developer of PyPortfolioOpt, a python portfolio optimisation library, and I'm trying to allow users to add constraints to a maximum Sharpe ratio problem. Currently, users can pass their constraints as a lambda function, e.g to make…
lagrange103
  • 169
  • 3
  • 9
2
votes
1 answer

Broadcasting error when summing cvxpy affine expression with np.array

In the following code snippet I intend to do the following: (1) Multiply each element of the identity by the d optimization variable. (2) Sum a vector of ones to a CVXPY affine expression, which is also a vector of 24 elements. (3) Create a…
cab20
  • 35
  • 1
  • 5
2
votes
0 answers

The objective is not DCP. Its following subexpressions are not

Here I use the cvxpy solver to solve a problem. But the Problem does not follow DCP rules. The objective is import cvxpy as cp import numpy as np def bit_rate(alpha, beta, p, w): return alpha * w * cp.log(1 + beta * p / w) # Create scalar…
Leo Li
  • 81
  • 1
  • 7
2
votes
1 answer

Non-strict inequalities as contstraints in Python's library cvxpy

I am playing with the cvxpy library in order to solve some particular optimisation problem import cvxpy as cp import numpy as np (...) prob = cp.Problem( cp.Minimize(max(M*theta-b)) <= 45, [-48 <= theta, theta <= 48]) (Here M and b are…
Tomasz Kania
  • 231
  • 2
  • 10
2
votes
2 answers

Unable to install cvxpy into virtualenv for AWS lambda

I am trying to run the cvxpy package in an AWS lambda function. This package isn't in the SDK, so I've read that I'll have to compile the dependencies into a zip, and then upload the zip into the lambda function. I've done some research and tried…
user10756193
  • 183
  • 1
  • 1
  • 8
2
votes
1 answer

Why am I getting this DCPError?

I'm trying to optimize a binary portfolio vector to be greater than a benchmark using CVXPY. import cvxpy as cp import numpy as np # Generate a random non-trivial quadratic program. n = 10 # number of options np.random.seed(1) mu =…
George
  • 680
  • 4
  • 16
2
votes
0 answers

CVXPY doesn't terminate (with CVXOPT as solver)

We are using CVXPY with CVXOPT as solver (and cvx.ROBUST_KKTSOLVER as KKT solver) as part of a change-point detection approach. In some cases, the call to Problem.solve() doesn't terminate. We cannot deterministically reproduce the problem as…
Konstantin
  • 2,451
  • 1
  • 24
  • 26
2
votes
1 answer

Can I use cvxpy to split integer-2D-array to two arrays?

I have a problem that I wonder if I can solve using cvxpy: The problem: I have a two dimensional integers array and I want to split it to two array in a way that each row of the source array is either in the 1st or 2nd array. The requirement from…
2
votes
1 answer

Use Pyomo or cvxpy to predict the power of a building (Model Predictive Control)

I have the data of the outside temperatures [8,2,10,13 ..] and I have the thermal inertia (8h) of my building. One of the constraints would be to keep an inside temperature of my building within 20 degrees. We start at equilibrium and we say that…
Dodo3
  • 43
  • 7
2
votes
0 answers

Why is scikitlearn implementation for dictionary learning faster than cvxpy?

I am implementing a sparse matrix factorization routine to generate a sparse score matrix and a dense feature matrix in python. There is a direct implementation in scikit-learn scikitlearn.decomposition.DictionaryLearning which works well for a…
Naren
  • 23
  • 6
2
votes
1 answer

Broadcasting in CVXPY

I'm trying to train a linear model with bias using CVXPY. Suppose input and target are given. Suppose loss is a cvxpy function, convex in its 1st argument. I have the following code: import cvxpy as cvx n_data = 100 d_in = 10 d_out = 10 beta =…
Geoffrey Negiar
  • 809
  • 7
  • 28
2
votes
2 answers

Is my problem suited for convex optimization, and if so, how to express it with cvxpy?

I have an array of scalars of m rows and n columns. I have a Variable(m) and a Variable(n) that I would like to find solutions for. The two variables represent values that need to be broadcast over the columns and rows respectively. I was naively…
2
votes
0 answers

CVXPY integer programming returning non-integer solution

I am trying to solve an integer programming with CVXPY. But the solution returning by CVXPY seems to be non-integer. What's wrong with my code? import cvxpy as cp # Create two optimization variables of type integer. x = cp.Variable(integer=True) y…
Saikat
  • 1,209
  • 3
  • 16
  • 30
2
votes
1 answer

cvxpy+ecos: problem INFEASIBLE, how to scale correctly

I have the following code: import numpy as np import cvxpy as cp import math import sys def solve05( p, a ): m,n,ids,inv,k = 0,len(p),{},{},0 for i in range(n): for j in range(n): ids[(i,j)] = k inv[k] =…
Ilonpilaaja
  • 1,169
  • 2
  • 15
  • 26