cvxpy | embedded modeling language for convex optimization problems | Math library

 by   cvxpy C++ Version: 1.4.2 License: Apache-2.0

kandi X-RAY | cvxpy Summary

kandi X-RAY | cvxpy Summary

cvxpy is a C++ library typically used in Utilities, Math applications. cvxpy has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

A Python-embedded modeling language for convex optimization problems.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              cvxpy has a medium active ecosystem.
              It has 4541 star(s) with 998 fork(s). There are 118 watchers for this library.
              There were 4 major release(s) in the last 6 months.
              There are 167 open issues and 1140 have been closed. On average issues are closed in 143 days. There are 10 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of cvxpy is 1.4.2

            kandi-Quality Quality

              cvxpy has 0 bugs and 0 code smells.

            kandi-Security Security

              cvxpy has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              cvxpy code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              cvxpy is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              cvxpy releases are available to install and integrate.
              Installation instructions are not available. Examples and code snippets are available.
              It has 32942 lines of code, 3407 functions and 420 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of cvxpy
            Get all kandi verified functions for this library.

            cvxpy Key Features

            No Key Features are available at this moment for cvxpy.

            cvxpy Examples and Code Snippets

            norm of differences of variables in cvxpy
            Pythondot img1Lines of Code : 60dot img1License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import numpy as np
            import cvxpy as cp
            pts = np.array([(-2, 3), (-3, 5), (-1, 4), (-3, 7), (0, 3),
                            (-2, -2), (-3, 8), (3, 1), (1, -2), (2, 6),
                            (-2, 6), (-2, 5), (-4, 3), (-4, 6), (-3, 10),
                            (2,
            GLPK (python swiglpk) "Problem has no primal feasible solution" but ok with CVXPY
            Pythondot img2Lines of Code : 3dot img2License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
             x <= -1
             x,y in {0,1}^2
            
            GLPK (python swiglpk) "Problem has no primal feasible solution" but ok with CVXPY
            Pythondot img3Lines of Code : 20dot img3License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            swiglpk.glp_write_lp(lp,None,"xxx.lp")
            
            \* Problem: Unknown *\
            
            Maximize
             obj: + z_1 + z_2
            
            Subject To
             r_1: 0 z_1 <= -1
            
            Bounds
             0 <= z_1 <= 1
             0 <= z_2 <= 1
            
            Generals
             z_1
             z_2
            
            End
            
            cvxpy solvers produce solutions of different shapes?
            Pythondot img4Lines of Code : 13dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
                prob = cvxpy.Problem(obj, constraints)
                #prob.solve(solver=cvxpy.CVXOPT, verbose=False, max_iters=1000, reltol=1e-9)
                prob.solve()
            
                bottom_left = np.array(bl.value).T * scale
                top_right = np.array(tr.value).T * scale
                
            
            Solving linear regression minimizing quadratic cost
            Pythondot img5Lines of Code : 6dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
              objective_function = (y - X*theta).T*(y-X*theta)
            
              objective = cp.Minimize(cp.norm(y - X*theta)**2)
            
              objective = cp.Minimize(cp.norm(y - X*theta))
            
            MISDP/MISOCP in cvxpy
            Pythondot img6Lines of Code : 8dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            det(A) = xy-z^2
            
            xy - z^2 >= u^2
            
            xy >= z^2 + u^2
            
            x >= quad_over_lin([z,u], y)
            
            How do I model this linear programming problem in Python?
            Pythondot img7Lines of Code : 97dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            minimize:   sum(u)
            subject to: -u_i <= beta_i for all i in len(u)
                        u_i >= beta_i for all i in len(u)
                        [X^T (y - X beta)]_j <= delta_j for all j in len(y)
                        [X^T (y - X beta)]_j >= -delta_j for al
            Find linear combination of vectors that is the best fit for a target vector
            Pythondot img8Lines of Code : 42dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            # Import packages.
            import cvxpy as cp
            import numpy as np
            
            # Generate data.
            m = 20
            n = 15
            np.random.seed(1)
            A = np.random.randn(m, n)
            b = np.random.randn(m)
            
            # Define and solve the CVXPY problem.
            x = cp.Variable(n)
            cost = cp.sum_squares(A @
            Connect series of bridges at midpoint by raising legs
            Pythondot img9Lines of Code : 64dot img9License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            from ortools.linear_solver import pywraplp
            
            x = [0, 200, 300, 500, 600, 800]
            y = [6, 1, 6, 9, 9, 120]
            initial_bounds = [(0, 10), (0, 9), (0, 9.5), (0, 8), (0, 7), (0, 9)]
            
            # Returns the y value at x2 of the line between (x0,y0) and (x1,y1)
            Using cvxpy to solve a lasso like problem
            Pythondot img10Lines of Code : 2dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            objective = cp.Minimize(cp.norm2(A @ (v - v0)) ** 2 + lam * cp.abs(v).T @ iota)
            

            Community Discussions

            QUESTION

            norm of differences of variables in cvxpy
            Asked 2022-Mar-29 at 19:14

            How can I take the following norm in cvxpy

            ...

            ANSWER

            Answered 2022-Mar-29 at 19:14

            Your problem is solved exactly because you don't have any constraint. I skipped the function to make you a shorter script.

            Source https://stackoverflow.com/questions/71632766

            QUESTION

            The objective is not DCP
            Asked 2022-Mar-28 at 08:48

            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 Problem does not follow DCP rules. Specifically: The objective is not DCP. Its following subexpressions are not: 0.004 / (power(var1[0], 0.5) + power(var1[0], 0.5)) 0.004 / (power(var11, 0.5) + power(var11, 0.5))

            my code is

            ...

            ANSWER

            Answered 2022-Mar-28 at 08:48

            Use cp.inv_pos(u) instead of 1/u.

            Source https://stackoverflow.com/questions/71641509

            QUESTION

            Accessing suboptimal solution in Mosek+Cvxpy
            Asked 2022-Feb-24 at 07:24

            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 using Mosek's mosek.dparam.optimizer_max_time parameter.

            In those cases, the pain-point is that we get no solution.

            Is it possible to get the suboptimal/best found solution so far?

            ...

            ANSWER

            Answered 2022-Feb-24 at 07:24

            If Mosek did not find any feasible integer solution within the time limit then there is nothing to return, so you get nothing.

            If Mosek found some feasible integer solution then CVXPY should return it with solution status s.OPTIMAL_INACCURATE, judging from a quick look at the code.

            So the question is what does it say in the log output and what happens at the end of the optimization when CVXPY is processing the answer from the solver.

            Source https://stackoverflow.com/questions/71240192

            QUESTION

            Convex Optimization - Currency exchange problem - cvxpy error
            Asked 2022-Jan-24 at 10:04

            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 loss due to the bid-ask spread which occurs when we exchange some units of a currency for some units of another currency.

            In case it helps here is the full question: https://drive.google.com/file/d/1DG8xfM3ayQ0Oj9VQGYSNbHF_rbKHMTLq/view

            The code:

            ...

            ANSWER

            Answered 2022-Jan-23 at 20:58

            Wherever you are operating on cvxpy objects you should be using cp. functions, not np. ones. So cp.dot etc.

            Source https://stackoverflow.com/questions/70824473

            QUESTION

            How to install mosek for cvxpy?
            Asked 2022-Jan-11 at 09:09

            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 as solver):

            ...

            ANSWER

            Answered 2022-Jan-10 at 08:49

            Have you tested that your conda installed Mosek can be used outside Cvxpy i.e. directly from Python.

            Source https://stackoverflow.com/questions/70648123

            QUESTION

            cvxpy solvers produce solutions of different shapes?
            Asked 2022-Jan-06 at 16:16

            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))

            ...

            ANSWER

            Answered 2022-Jan-06 at 16:16

            I found success in customizing this library for modern use.

            Source https://stackoverflow.com/questions/70586297

            QUESTION

            CVXPY, least-squares Optimization, wrong constraint formulation
            Asked 2022-Jan-03 at 14:35

            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 handle. I got a matrix S dimensions (9,7) with known coefficients, B dimensions (1,7) with known coefficients, Alpha dimensions (1,7) what I need to find, with various constraints :

            • Alpha must be positive
            • The sum of all the coefficients of Alpha must be equal to 1

            I need to optimize Alpha such as : A @ Alpha-B=0. I discovered CVXPY and thought least square optimization was perfect for this issue.

            This is the code I wrote :

            ...

            ANSWER

            Answered 2022-Jan-03 at 14:35

            Use just sum(Alpha) == 1. You are not supposed to use numpy functions in CVXPY expressions, you must use CVXPY functions listed in https://www.cvxpy.org/tutorial/functions/index.html

            Source https://stackoverflow.com/questions/70566975

            QUESTION

            Solving linear regression minimizing quadratic cost
            Asked 2021-Nov-25 at 16:15

            I want to solve linear regression in the following way

            When I try with minimizing the sum of cost it works fine,

            ...

            ANSWER

            Answered 2021-Nov-25 at 16:15

            I think CVXPY does not understand that both y - X*theta are the same in

            Source https://stackoverflow.com/questions/70108101

            QUESTION

            MISDP/MISOCP in cvxpy
            Asked 2021-Nov-24 at 09:08

            I'm trying to solve the following problem in CVXPY.

            The problem is a mixed-integer SDP due to the PSD matrix we're solving. However, according to this list it looks as though none of the solvers can handle such a problem.

            Can we use the fact that A is a 2x2 matrix to somehow convert this to a mixed-integer SOCP problem?

            ...

            ANSWER

            Answered 2021-Nov-24 at 09:08

            Let's say A=[[x,z], [z,y]], then you can maximize sqrt(det(A)) (which is equivalent to your objective). Note that

            Source https://stackoverflow.com/questions/70091659

            QUESTION

            Multipoint(df['geometry']) key error from dataframe but key exist. KeyError: 13 geopandas
            Asked 2021-Oct-11 at 14:51

            data source: https://catalog.data.gov/dataset/nyc-transit-subway-entrance-and-exit-data

            I tried looking for a similar problem but I can't find an answer and the error does not help much. I'm kinda frustrated at this point. Thanks for the help. I'm calculating the closest distance from a point.

            ...

            ANSWER

            Answered 2021-Oct-11 at 14:21

            geopandas 0.10.1

            • have noted that your data is on kaggle, so start by sourcing it
            • there really is only one issue shapely.geometry.MultiPoint() constructor does not work with a filtered series. Pass it a numpy array instead and it works.
            • full code below, have randomly selected a point to serve as gpdPoint

            Source https://stackoverflow.com/questions/69521034

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install cvxpy

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • PyPI

            pip install cvxpy

          • CLONE
          • HTTPS

            https://github.com/cvxpy/cvxpy.git

          • CLI

            gh repo clone cvxpy/cvxpy

          • sshUrl

            git@github.com:cvxpy/cvxpy.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link