CVXPY is a Python-embedded modeling language for convex optimization problems inspired by the MATLAB package CVX.
Questions tagged [cvxpy]
609 questions
0
votes
1 answer
How to fix cvxpy output of arrays?
I am trying to write a portfolio optimization problem using cvxpy.
initial_weights = [0.045, 0.035, 0.024, 0.028...]
rets = (np.log(data/data.shift(1))
w = cvx.Variable(38)
ret = np.sum(rets.mean()*w)*252
prob = cvx.Problem(cvx.Maximize(ret),…

Ray234
- 173
- 5
- 15
0
votes
1 answer
How to write complex constraints in cvxpy?
I am trying to write a portfolio optimization problem using cvxpy.
initial_weights = [0.045, 0.035, 0.024, 0.028...]
rets = (np.log(data/data.shift(1))
w = cvx.Variable(38)
ret = np.sum(rets.mean()*w)*252
prob = cvx.Problem(cvx.Maximize(ret),…

Ray234
- 173
- 5
- 15
0
votes
0 answers
How to create a SOC constraints with different Variable vectors's element
I am working on an optimization problem with cvxpy. And I need to create a SOC(second order cone) constraint.
The way described in cvxpy documents is like following:
We use cp.SOC(t, x) to create the SOC constraint ||x||_2 <= t.
where t is the…

Black Bob
- 105
- 1
- 13
0
votes
1 answer
Define CVXPY variables for graph coloring problem
I’m trying to solve the minimum graph coloring problem. I’m trying to solve it as an mip using cvxpy. I’m following the outline of a solution described in this…

user3476463
- 3,967
- 22
- 57
- 117
0
votes
1 answer
Is there a way to implement convex optimization using N-dimensional arrays?
Given data with shape = (t,m,n), I need to find a vector variable of shape (n,) that minimizes a convex function of the data and vector. I've used cvxopt (and cvxpy) to perform convex optimizations using 2D input, but it seems like they don't…

John
- 15
- 1
- 3
0
votes
0 answers
CVXPY generates weird result
Here's a simple optimization problem:
import cvxpy as cp
import numpy as np
w = np.array([700, 700, 700, 700, 700, 700, 700, 700, 700, 700])
b = 7000
n = len(w)
# Define and solve the CVXPY problem.
x = cp.Variable(n, boolean=True)
prob =…

Rikard Olsson
- 841
- 1
- 7
- 28
0
votes
0 answers
Maximize the Minimum
I've got a vector (which will by dynamic in length depending on the problem), which is determined by the function Ax - b, where A and b are determined and x is a variable. I would like to maximize the minimum value of the resulting vector Ax - b.…

William
- 83
- 8
0
votes
1 answer
how to set a limit number of thread in cvxpy
I'm using CVXPY on a shared computer, and I have to set a limited number of thread.
prob = cvx.Problem(objective, constraints)
prob.solve(solver=cvx.CVXOPT)
is there any option to limit the number of threads for CVXPY solver?
thanks!

wanghf
- 1
- 3
0
votes
0 answers
cvxpy: map in objective function
I have a list beta_list, where each entry in the list is a vector. I want to minimize the following function
def two_norm(this_beta, beta):
cp.Pnorm(beta - this_beta, p = 2)**2
def obj_fn(beta_list, beta):
sum(map(two_norm, beta_list,…
0
votes
1 answer
cvxpy, no cplex attribute
I am not able to select the cplex solver for cvxpy. The cvxpy website states that if you're able to import cplex into python, you will also be able to use cplex for cvxpy. However, this is not the case.
CPLEX is not one of the arguments of cvxpy.…

Wiet
- 21
- 2
0
votes
0 answers
How to use non-atomic functions on cvxpy variable?
Consider the scenario where I define a CVXPY variable, a 4x4 semidefinite matrix, as below
x = cvxpy.Semidef(4)
If I want to write a constraint involving the trace of this, it seems I must use the atomic function
cvxpy.atoms.affine.trace.trace(x)
I…

user1936752
- 756
- 1
- 9
- 25
0
votes
0 answers
Translating an optimization problem from CVX to CVXPY?
I am attempting to translate a semidefinite programming problem from CVX to CVXPY as described here. My attempt follows:
import cvxpy as cvx
import numpy as np
c = [0, 1]
n = len(c)
# Create optimization variables.
f = cvx.Variable((n, n),…

Wulfsta
- 1
- 2
0
votes
2 answers
How to define variables, constrains to Pandas Dataframe when using CVXPY for optimization?
import pandas as pd
import numpy as np
import re
import cvxpy as cvx
data = pd.read_excel('Optimality_V3.xlsx', encoding='latin-1')
As u can see I just imported a csv file as a dataframe. Now I want to solve a maximixation function using the…

Nitish Gaddam
- 101
- 1
- 11
0
votes
1 answer
Convex Optimization problem labeled as non convex
I'm using cvxpy (1.0.11) to solve a convex optimization problem.
The convex problem I have is being labelled as non-convex I think because it does not know that the parameter alpha is bounded between [0, 1].
I know this from this line fails...
loss…

SARose
- 3,558
- 5
- 39
- 49
0
votes
1 answer
Contradicting output from the CVXPY solver
I am familiarizing myself with CVXPY, and encountered a strange problem. I have the following simple toy optimization problem:
import numpy as np
import cvxpy as cp
A=np.array([[1,0,0],[0,1,0], [0,0,1]])
y=np.array([1,1,1])
# Upper bound for the…

Longti
- 111
- 1