Questions tagged [cvxpy]

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

609 questions
1
vote
0 answers

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 entrywise-sum of v equal to 1. (See…
1
vote
1 answer

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 Collecting pandas==1.0.3 Using cached…
Ye Duan
  • 11
  • 5
1
vote
1 answer

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, I have a variable g, positive and I want to…
1
vote
2 answers

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 one line of code was(because I want to choose mosek…
Lancdorr
  • 335
  • 4
  • 14
1
vote
1 answer

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 = ['TSLA', 'MSFT', 'FB', 'AAPL',…
ASH
  • 20,759
  • 19
  • 87
  • 200
1
vote
1 answer

Constrain only some elements of the variable to be integer

I have a CVXPY optimization script, with a variable made of 14 elements. The first 2 need be integer, the other 12 don't. The CVXPY documentation says: integer (bool or list of tuple) – Is the variable integer? The semantics are the same as the…
younggotti
  • 762
  • 2
  • 15
1
vote
1 answer

Create matrix from vector cvxpy variable

For example, I declare a vector variable x = cvxpy.Variable(5). I want to enforce a constraint on such symmetric matrix, [ [x[0], 0, 0, x[1]], [0 , x[2], 0, 0], [0 , 0, x[3], 0], [ x[1], 0, 0, x[4] ] ] to be semi-positive definite. I know that in…
Zhong Guo
  • 11
  • 2
1
vote
1 answer

Solving linear regression minimizing quadratic cost

I want to solve linear regression in the following way When I try with minimizing the sum of cost it works fine, import cvxpy as cp import numpy as np n = 5 np.random.seed(1) x = np.linspace(0, 20, n) y = np.random.rand(x.shape[0]) theta =…
GPrathap
  • 7,336
  • 7
  • 65
  • 83
1
vote
0 answers

CVXPY why can't optimize expression which contains division by sum? (DCPError: objective is not DCP)

I am having a problem trying to get the optimal value of the f(x,w) matrix by optimizing the entropy of f(x, w)*w/sum(f(x, w)*w). import cvxpy as cp fxw = cp.Variable((len(x), len(w))) pmx = fxw@w/cp.sum(fxw@w*dx) objective =…
mate jozsa
  • 13
  • 3
1
vote
1 answer

Create constraints for list variable in CVXPY

In CVXPY I created a variable called "contracts", which includes 126 elements. contracts = cp.Variable(126, integer=True) I have two pandas series (1x126) with min and max values for each of the 126 elements (called "min_contracts" and…
younggotti
  • 762
  • 2
  • 15
1
vote
1 answer

How do I model this linear programming problem in Python?

I have been tasked to program a Dantzig Selector using Python, but I was given no guidelines and do not have much experience in linear programming or data science. I cannot find the information I need in LP module manuals, or in other questions on…
1
vote
1 answer

How do I prevent multiple starts/stops of my selection?

I have CVXPY problem defined with a volume array, and a cost array to match each of volumes. The problem has 192 variables and 3 constraints which I have defined. My goal is to minimize the cost in this problem to deliver a specific volume and avoid…
1
vote
1 answer

Using cvxpy to solve a lasso like problem

It's not entirely lasso because I add an extra constraint but I'm not sure how I'm supposed to solve a problem like the following using cvxpy import cvxpy as cp import numpy as np A = np.random.rand(5000,1000) v0 = np.random.rand(1000,1) v =…
financial_physician
  • 1,672
  • 1
  • 14
  • 34
1
vote
1 answer

Python CVXPY: Attribute Error - Parameter

I'm attempting to use CVXPY in python to solve a linear programming problem that has a handful of constraints. I created a single list with all of the constraints listed but when it came to running the problem.solve(), it returned the following…
ewolf
  • 39
  • 4
1
vote
1 answer

cvxpy + mosek: The lower bound specified is not a number (nan)

In below code snippet I am trying to do a very simple linear regression using cvxpy and mosek solver weight = df2['weight'].to_numpy() A = df2[ regressors ].to_numpy() x = cp.Variable(len(regressors )); R = df2['y'].to_numpy() cost = cp.sum_squares(…