Questions tagged [cvxpy]
CVXPY is a Python-embedded modeling language for convex optimization problems inspired by the MATLAB package CVX.
505
questions
-1
votes
0
answers
12
views
Resolve a SOCP problem thanks to cvxpy on python
Good afternoon everyone,
I post here because i have a problem:
I want to resolve a SOCP Problem with CVXPY but because of this condition, I can't solve it:
l>=(P2+Q2)/v where l,P,Q,v are variable ...
-1
votes
0
answers
17
views
SVM multiclass optimization using cvxpy
Trying to solve multiclass svm using below formulations.
size = 28*28
W_0 = Variable((size,1))
W_1 = Variable((size,1))
W_2 = Variable((size,1))
W = np.array([W_0,W_1,W_2])
Psi_0 = Variable(len(...
2
votes
1
answer
74
views
Integer Programming for NNC
I'm trying to implement Integer Programming for Nearest Neighbor Classifier in python using cvxpy.
Short intro
Given a dataset of n points with a color (red or blue) we would like to choose the ...
0
votes
1
answer
15
views
CVXPY constraint vector conditionals values inside
First of all I'm a newbie with the cvxpy module in python.
I have a doubt about the constraint in the CVXPY library in python.
I'm creating a vector weights that contains some specifications.
My ...
0
votes
0
answers
22
views
use "abs" with @ operator in CVXPY
I want to do the absolute operator with CVXPY: abs(A @ x).
From here cvxpy objective function error involving MulExpression I understand that I cannot use np.abs since it is overwritten from CVXPY, ...
-2
votes
0
answers
24
views
Mathematical optimization such as CVXPY, Gurobi, PuLP in Android Studio
How can I execute a Python-based CVXPY / Gurobi / PuLP optimization solver in Android Studio locally?
0
votes
1
answer
51
views
Displaying the solution at each iteration by using CVXPY
By using CVXPY, I want to solve this simple convex optimization problem:-
min ||z||^2 subject to z = Ax - b where A and b are given
The code is as follows:-
x = cp.Variable(n)
z = cp.Variable(n)
...
0
votes
1
answer
47
views
Imposing constraints on all (numbered) diagonals in CVXPY
I am looking to implement a constraint on an optimization on all diagonals of a matrix using CVXPY. The diag function in CVXPY only returns the main diagonal. Is there a simple way to implement the ...
0
votes
0
answers
13
views
CVXPY: rewrite optimization problem to fit DCP rules
I have some issues in the implementation of the following minimization problem:
min(sum_of_squares(norm2(ai-x) - di))
1
where x is the unknown variable of size (1,2), ai is a known variable of size (1,...
0
votes
0
answers
19
views
Python numpy with cvxpy incompatibility issue
I'm trying to run the following code in order to achieve from two vectors A = (N,1) and B = (M,1) a matrix with dimension (N, M). A matrix multiplication should allow to achieve this: AxB.
However, my ...
0
votes
0
answers
61
views
Python cvxpy code structure when using quad_form
I'm quite new to cvxpy and I wonder if I could get some help with the following.
I have a dataframe where each row represents a City and every column is a metric (they are ESG metrics but it doesn't ...
1
vote
0
answers
31
views
CVXPY takes compilation time for days for MNIST data
Trying to simulate SOCP optimization problem using multiple class SVM for MNIST data. Could see that with solver set to ECOS, cvxpy compilation takes days to complete it.
...
1
vote
1
answer
35
views
Can't assign necessary entries to a CVXPY (2,2) Variable
I'm trying to implement this research paper. The paper is combining multiple metrics into a single joint formulation. The authors manipulate it into an optimization problem, with the condition of a ...
0
votes
0
answers
29
views
Optimization problem: CVXPY Problem does not follow DCP rules
I'm trying to minimize the number of warehouses needed to serve a specific number of customers (whose locations are known) using CVXPY.
import numpy as np
import math
import networkx as nx
import ...
0
votes
1
answer
54
views
Doesn't respect limit conditions in scipy.optimize
Nonlinear Programming with Inequality Constraints
==============
Imagine that you work out in a factory that produces some kind of composite products.
Each product has its own composition of parts.
...
0
votes
0
answers
37
views
cvxpy: Possible sign flip for Lagrange Multiplier/dual variable
I have encountered a very strange problem when using cvxpy. Consider the following two problems:
x = cvx.Variable(1, "x")
obj = cvx.Minimize(x)
cons = [x==1]
prob = cvx.Problem(obj, cons)
...
0
votes
0
answers
24
views
cvxpy - How to obtain the variable value after each iteration?
I am using cvxpy to solve a second order cone program. I have used the boilerplate code as mentioned in the cvxpy website - cvxpy SOCP webpage. I do not know how to obtain the variable value after ...
0
votes
1
answer
69
views
cvxpy not allowing item assignment for MulExpression
I have a sparse matrix operation as part of the optimization constraint. I can implement the program in Matlab cvx, now I am trying to implement a cvxpy version. The problem is following constraint:
N ...
0
votes
0
answers
24
views
Need to get clarity on cvxpy problem solver
Recently started working on cvxpy problem solver (SVM SOCP) and everytime when I run, I am getting different answers. Do we need to define random_state here also or what is the best way to define this?...
0
votes
1
answer
85
views
The objective is not DCP
I try to solve the convex problem on page 20 presented in this paper
In my opinion, the objective is convex.
cvxpy version 1.1.18
prob is DCP: False
it reports
xception has occurred: DCPError ...
0
votes
1
answer
113
views
norm of differences of variables in cvxpy
How can I take the following norm in cvxpy
sum(norm(x[i] - x[j], p=2), i=1, j>i, i, j = n)
where x is (n, 2) variable matrix defined by x = cp.Variable((n, 2)). For the problem, I am taking n=16. ...
1
vote
1
answer
53
views
How to properly install qpsolvers for Python on Windows?
I am trying to install qpsolvers using pip.
The installation goes without errors, and the module imports properly afterwards.
However, qpsolvers has no available solvers for it to use :
import ...
0
votes
0
answers
12
views
How to frame the syntax of the following problem?
I have the following equation,
x*z -E -R = 0
Here, x and R are given; z and E are variables,
x's size = (128,1),
z's size = (1,2),
E's size = (128,2),
R's size = (128,2),
An important constraint ...
0
votes
0
answers
39
views
How to populate a variable/expression in CVXPY
I am trying to translate cvx code to cvxpy. The major problem I am having is finding something similar to expressions. I used expressions to set values for an entire list of len(n). From my ...
0
votes
1
answer
37
views
Always enabling numeric instability correction with Gurobi
We run large-scale optimization problems on regular-basis using Cvxpy+Gurobi.
Our optimization problem sometimes (~10% of the time) becomes numerically unstable.
Fortunately, the issue automatically ...
0
votes
0
answers
107
views
cvxpy.min or cvxpy.max in constraints
The following is my code:
import cvxpy as cp
alpha = 0.3
lamda_1 = 0.5
lamda_2 = 1.2
mu1 = cp.Variable(pos=True)
mu2 = cp.Variable(pos=True)
p_ev_max = 50
eps = 0.05
S1 = cp.Variable(pos=True)
S2 = ...
0
votes
1
answer
48
views
Accessing suboptimal solution in Mosek+Cvxpy
We are using Mosek solver via its Cvxpy interface.
We deal with large-scale optimization problem on a regular-basis and sometimes the runtime is very high. So, we specify a upper limit on runtime ...
0
votes
0
answers
18
views
Specify Pool in Cvxpy for Gurobi
We are using Gurobi solver via its Cvxpy interface.
We have multiple pools on our Gurobi Instant Cloud.
Rather than directing all optimization requests to the default pool, we want to direct some ...
0
votes
0
answers
53
views
I can't transform a non-DPP problem to a DPP problem
I am trying to solve a convex problem in parallel by using cvxpy and cvxpylayer. But I get "Problem must be DPP" error.
Here is a a part of my code.
lmbd = cp.Parameter(value= np.dot(z, s) / ...
0
votes
0
answers
65
views
How to modify "sqrt(sum_squares...)" to follow DCP rules CVXPY
I am a newbie to CVXPY and try to solve optimization problem, but an error occured:
DCPError: Problem does not follow DCP rules. Specifically:
The following constraints are not DCP:
500.0 <= 25.0 @ ...
0
votes
1
answer
59
views
Python: If / Else Function, Iterative Maximization Problem
I have the following code which will only return "None" when the if/else piecewise function exceeds the given threshold. When run by itself (i.e. not with a range of values), it works okay ...
1
vote
0
answers
54
views
CVXPY) Maximum diagonal entry of the inverse matrix
Currently what I am doing is: S(v) is a d-dimensional positive definite matrix determined by the d-dimensional vector v.
I want to optimize the maximum diagonal entry of the inverse of S(v) subject to
...
0
votes
0
answers
81
views
cvxpy - how to find the results each iteration
I am using cvxpy for to run an optimization comparison. For example, I'm interested in optimization the problem
tr(C.T @ X)^2 - log(det(X)) with constraint X >>0,
and compare the primal-dual ...
0
votes
0
answers
36
views
Result inconsistencies between solvers in CVXPY
I am running an LP optimization using CVXPY and testing a number of solvers. Previously, when running the same mathematical formulation of my problem I received consistent results, regardless of which ...
2
votes
1
answer
49
views
Optimization integer programming with covariance matrix
I am trying to do a optimization problem which requires the calculation of a new covariance matrix affected by the variable within the implementation.
I am able to do so with scipy optimization ...
0
votes
0
answers
58
views
Atomics Functions of CVXPY in Pyomo
I am trying to translate a problem modeled in CVXPY into Pyomo.
Currently I have the doubt of how the atoms functions can be carried out in pyomo, in particular the cp.pos function
I used it to ...
0
votes
1
answer
68
views
Convex Optimization - Currency exchange problem - cvxpy error
I am solving the currency exchange problem, where we have a set of currency holdings for 10 different kinds. Our objective is to have a specific minimum of each currency holdings, while minimizing the ...
0
votes
0
answers
67
views
Linearization of the absolute value breaks CVXPY DCP check
I would like to solve a standard quadratic problem that involves an absolute value term in the objective. In order to get rid of the absolute term I linearize it by splitting into two variables:
y = ...
0
votes
1
answer
68
views
does cvxpy need starting conditions provided is zeros are not satisfying contraints?
I am trying to modify the maxrect library to solve for maximum rectangles unconstrained by orientation.
looking at the code I see the constraints are:
""" :param coordinates:
...
0
votes
0
answers
47
views
Problem does not follow DCP rules (problem with cvxpy )
I was wondering if any of you folks could help me with this problem.
I would like to solve the next optimization problem numerical by using cvxpy library.
end here my code for solving this problem:
n=...
0
votes
0
answers
257
views
Convex Optimization: cvxpy solver issue
I'm solving a simple convex optimisation problem as follows:
import numpy as np
import cvxpy as cp
from cvxopt import solvers
#Problem: A diet problem where we minimize the cost of meal while keeping ...
1
vote
1
answer
353
views
When I try to run the code provided in a paper, it has following errors related to CVXPY
When I try to run the code provided in a paper, it has the following errors related to CVXPY:
(bayesrace) C:\Users\Lenovo\bayesrace>pip install -e .
Obtaining file:///C:/Users/Lenovo/bayesrace
...
1
vote
1
answer
156
views
Constraint on a boolean variable?
I am trying to implement a unit commitment problem with cvxpy with a rampup cost. However I am struggling to identify the ramp-ups. (when variable switch from 0 to any positive value)
In other terms, ...
0
votes
2
answers
474
views
How to install mosek for cvxpy?
Previously I used command conda install -c mosek mosek to install mosek(my IDE is VS Code and use anaconda environment). After I installed it, I ran a program for a convex optimization problem, and ...
0
votes
1
answer
53
views
cvxpy solvers produce solutions of different shapes?
I am trying to use maxrect's get_maximal_rectangle, which uses cvxpy under the hood.
With the shapely polygon: POLYGON ((0 0.95, 0 2, 2 2, 2 1.95, 0 0.95))
max_hull = shapely.wkt.loads('POLYGON ((0 0....
0
votes
1
answer
53
views
CVXPY, least-squares Optimization, wrong constraint formulation
First of all, I'm sorry if my questions doesn't make sens, I am new using CVXPY library and I don't understand everything :/
I am trying to solve a minimization problem that I thought would be easy ...
0
votes
0
answers
68
views
cvxpy - cannot solve a weighted SDP problem
I want to test a a weighted SDP problem in cvxpy, namely min_{X > 0} | P * X - B |^2, where * is the Hadamard product. I started with the simple case with P being the identity matrix. This is the ...
0
votes
1
answer
59
views
Import Error and Undefined symbol: dgesv_ Error on installing CVXPY with PIP
I crate a new virtual environment using "virtualenv -p python3 env-name" and then pip install cvxpy. All works fine. However, when I type the code "import cvxpy" I get the ...
2
votes
0
answers
60
views
Converting Gurobipy/CPLEX to CVXPY [closed]
Problem: I have to make a comparison between commercial solvers (Gurobipy, CPLEX) and open-source solvers (CVXPY, Pulp). I have successfully written a code in commercial solver but I am having trouble ...
1
vote
1
answer
95
views
Am having a matrix multiplication issue with CVXPY
Updated code ...
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from cvxpy import *
cvxpy.multiply
import yfinance as yf
from yahoofinancials import YahooFinancials
assets = ['...