CVXPY is a Python-embedded modeling language for convex optimization problems inspired by the MATLAB package CVX.
Questions tagged [cvxpy]
609 questions
3
votes
0 answers
CVXPY failing randomly on basic quadratic problem
I'm finding CVXPY is randomly failing with the following error:
ArpackError: ARPACK error 3: No shifts could be applied during a cycle of the Implicitly restarted
Arnoldi iteration. One possibility is to increase the size of NCV relative to NEV.…

Corvus
- 7,548
- 9
- 42
- 68
3
votes
0 answers
matrix exponential in cvxpy
I am trying to implement the following convex-optimization problem in cvxpy:
A = a given matrix of dimension dim x dim
B = a given matrix of dimension dim x dim
X = cp.variable((dim, dim))
distance = cp.norm(exp(X)-A, 'fro')
delta= some…

EmFed
- 31
- 2
3
votes
0 answers
How to define parameters which change value depending on variable in CXYPY
I'm trying to solve a convex optimisation problem using CVXPY. I've values x, y which are 150 and 60. These are the initial demand of 2 timeslots. The objective is to minimise the total cost.
Total cost = x * price1 + y * price2 + penalty
Penalty =…

Thusitha Thilina Dayaratne
- 5,666
- 4
- 42
- 69
3
votes
1 answer
cvxpy: best strategy for enforcing smoothness in second dimension for large problems
There might be an answer for that floating around somewhere but I wasn't able to find it.
I want to minimize with variable X >= 0 and 1st derivative matrix D, so that X is smooth in column-direction and with relatively large data.
In the past I…

zeawoas
- 446
- 7
- 18
3
votes
0 answers
pytorch nn.L1Loss vs. Sklearn’s l1 loss - very different optimization results?
I was implementing L1 regularization with pytorch for feature selection and found that I have different results compared to Sklearn or cvxpy. Perhaps I am implementing nn.L1Loss incorrectly or maybe there is a better way to optimize (I tried both…

hugh
- 31
- 2
3
votes
1 answer
Python: CVXPY SolverError
Purpose: I am trying to use cvxpy in python to maximize the dual_func, however I get the below SolverError, I believe it may be Variables having different dimensions, but cant seem to figure out the issue. I have tried using other solvers like ECOS,…

OGARCH
- 97
- 1
- 4
3
votes
0 answers
Optimize Sharpe via CVXPY
I am looking to find a way via cvxpy to optimize a portfolio for Sharpe ratio.
Currently I have the following:
import cvxpy as cvx
import numpy as np
def markowitz_portfolio(means, cov, risk_aversion):
weights = cvx.Variable(len(means))
…

Newskooler
- 3,973
- 7
- 46
- 84
3
votes
1 answer
How to fix the TypeError: G must be a 'd' matrix?
Objective: trying to run toy dataset through an optimization process.
I am encountering the following error:
---------------------------------------------------------------------------
TypeError Traceback (most recent…

Student
- 1,197
- 4
- 22
- 39
3
votes
1 answer
Outer product in CVXPY
I have an objective function that depends on a sum of outer products. If I could use Numpy functions, I would write this as:
A = np.ones(m, n)
U = Variable(m, n)
objective = np.trace(sum([np.outer(A[i,:], U[i,:]) for i in range(m)]))
Of course…

Geoffrey Negiar
- 809
- 7
- 28
3
votes
0 answers
CVXPY DCPError for Convex Function
I have a convex optimization problem I am trying to solve with cvxpy. Given a 1 x n row vector y and an m x n matrix C, I want to find a scalar b and a 1 x m row vector a such that the sum of squares of y - (aC + b(aC @ aC)) is as small as possible…

Jeff
- 110
- 7
3
votes
1 answer
Passing CPLEX Parameters to CVXPY
How do i pass tolerances and other parameters through CVXPY when using the CPLEX solver?
from cvxpy import Problem, Minimize
from cvxpy.settings import CPLEX
costs = ...
constraints = ...
prob = Problem(Minimize(costs),…

rhaskett
- 1,864
- 3
- 29
- 48
3
votes
3 answers
cvxpy/ecos pip installation error
This is a borderline SuperUser question. I've been using pip install to add packages to my 3.6.2 installation, from powershell on Windows 10. I'm struggling to install CVXPY. Specifically, I've already upgraded setuptools and installed visual…

3pitt
- 899
- 13
- 21
3
votes
1 answer
scipy.optimize.minimize fails to converge for matrix input with constraints
(First question, will edit if not good in some way. Did research prior to posting)
I want to predict x*C=y (x and y are datasets, C is a matrix), with a constraint that the rows of C sum to 1 and that its elements are between 0 and 1.
Because it's…

Itamar Mushkin
- 2,803
- 2
- 16
- 32
3
votes
1 answer
Force a variable to be an integer CVXPY
I'm trying to force a variable to be an integer (integer constraint) using cvxpy in Python, but result keeps being a float:
from cvxpy import *
Fi = Int()
Or = Int()
constr = [Fi <= 3000,
Or <= 3000,
Or >= 1000,
…

Aleharu
- 170
- 1
- 9
3
votes
1 answer
Minimising log function in cvxpy
I am trying to simulate an exact line search experiment using CVXPY.
objective = cvx.Minimize(func(x+s*grad(x)))
s = cvx.Variable()
constraints = [ s >= 0]
prob = cvx.Problem(objective, constraints)
obj = cvx.Minimize(prob)
(cvxbook byod…

Krishna Kalyan
- 1,672
- 2
- 20
- 43