• Stars
    star
    123
  • Rank 290,145 (Top 6 %)
  • Language
    Python
  • Created over 8 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A CVXPY extension for convex-concave programming

DCCP

DCCP package provides an organized heuristic for convex-concave programming. It tries to solve nonconvex problems where every function in the objective and the constraints has any known curvature according to the rules of disciplined convex programming (DCP). For instance, DCCP can be used to maximize a convex function. The full details of our approach are discussed in the associated paper. DCCP is built on top of CVXPY, a domain-specific language for convex optimization embedded in Python.

Installation

You should first install CVXPY 1.1.

To install the most updated DCCP, please download the repository and run python setup.py install inside.

To install DCCP from pip, please run pip install dccp.

DCCP rules

A problem satisfies the rules of disciplined convex-concave programming (DCCP) if it has the form

minimize/maximize o(x)
subject to  l_i(x) ~ r_i(x),  i=1,...,m,

where o (the objective), l_i (left-hand sides), and r_i (right-hand sides) are expressions (functions in the variable x) with curvature known from the DCP composition rules, and ∼ denotes one of the relational operators ==, <=, or >=.

In a disciplined convex program, the curvatures of o, l_i, and r_i are restricted to ensure that the problem is convex. For example, if the objective is maximize o(x), then o must be concave according to the DCP composition rules. In a disciplined convex-concave program, by contrast, the objective and right and left-hand sides of the constraints can have any curvature, so long as all expressions satisfy the DCP composition rules.

The variables, parameters, and constants in DCCP should be real numbers. Problems containing complex numbers may not be supported by DCCP.

Example

The following code uses DCCP to approximately solve a simple nonconvex problem.

import cvxpy as cvx
import dccp
x = cvx.Variable(2)
y = cvx.Variable(2)
myprob = cvx.Problem(cvx.Maximize(cvx.norm(x - y,2)), [0 <= x, x <= 1, 0 <= y, y <= 1])
print("problem is DCP:", myprob.is_dcp())   # false
print("problem is DCCP:", dccp.is_dccp(myprob))  # true
result = myprob.solve(method='dccp')
print("x =", x.value)
print("y =", y.value)
print("cost value =", result[0])

The output of the above code is as follows.

problem is DCP: False
problem is DCCP: True
x = [ 1. -0.]
y = [-0.  1.]
cost value = 1.4142135623730951

The solutions obtained by DCCP can depend on the initial point of the CCP algorithm. The algorithm starts from the values of any variables that are already specified; for any that are not specified, random values are used. You can specify an initial value manually by setting the value field of the variable. For example, the following code runs the CCP algorithm with the specified initial values for x and y:

x.value = numpy.array([1, 2])
y.value = numpy.array([-1, 1])
result = myprob.solve(method='dccp')

An option is to use random initialization for all variables by prob.solve(method=β€˜dccp’, random_start=TRUE), and by setting the parameter ccp_times you can specify the times that the CCP algorithm runs starting from random initial values for all variables each time.

Constructing and solving problems

The components of the variable, the objective, and the constraints are constructed using standard CVXPY syntax. Once a problem object has been constructed, the following solve method can be applied.

  • problem.solve(method='dccp') applies the CCP heuristic, and returns the value of the cost function, the maximum value of the slack variables, and the value of each variable. Additional arguments can be used to specify the parameters.

Solve method parameters:

  • The ccp_times parameter specifies how many random initial points to run the algorithm from. The default is 1.
  • The max_iter parameter sets the maximum number of iterations in the CCP algorithm. The default is 100.
  • The solver parameter specifies what solver to use to solve convex subproblems.
  • The tau parameter trades off satisfying the constraints and minimizing the objective. Larger tau favors satisfying the constraints. The default is 0.005.
  • The mu parameter sets the rate at which tau increases inside the CCP algorithm. The default is 1.2.
  • The tau_max parameter upper bounds how large tau can get. The default is 1e8.

If the convex solver for subproblems accepts any additional keyword arguments, such as warm_start=True, then you can set them in the problem.solve() function, and they will be passed to the convex solver.

Result status

After running the solve method, the result status is stored in problem.status. The status Converged means that the algorithm has converged, i.e., the slack variables converge to 0, and changes in the objective value are small enough. The obtained solution is at least a feasible point, but it is not guaranteed to be globally optimum. The status Not converged indicates that the algorithm has not converged, and specifically, if the slack variables (printed in the log) are not close to 0, then it usually indicates that some nonconvex constraint has not been satisfied.

Other useful functions and attributes

  • is_dccp(problem) returns a boolean indicating if an optimization problem satisfies DCCP rules.
  • linearize(expression) returns the linearization of a DCP expression at the point specified by variable.value.
  • convexify_obj(objective) returns the convexified objective of a DCCP objective.
  • convexify_constr(constraint) returns the convexified constraint (without slack variables) of a DCCP constraint, and if any expression is linearized, its domain is also returned.

More Repositories

1

cvxpylayers

Differentiable convex optimization layers
Python
1,788
star
2

cvxportfolio

Portfolio optimization and back-testing.
Python
966
star
3

scs

Splitting Conic Solver
C
547
star
4

cvxbook_additional_exercises

Additional exercises and data for EE364a. No solutions; for public consumption.
Julia
544
star
5

pymde

Minimum-distortion embedding with PyTorch
Python
536
star
6

cvx_short_course

Materials for a short course on convex optimization.
Jupyter Notebook
327
star
7

CVXR

An R modeling language for convex optimization problems.
R
206
star
8

proximal

Sample implementations of proximal operators
MATLAB
186
star
9

cvxpygen

Code generation with CVXPY
Python
127
star
10

qcqp

A CVXPY extension for handling nonconvex QCQP via Suggest-and-Improve framework
Python
106
star
11

GGS

Greedy Gaussian Segmentation
Python
96
star
12

diffcp

Differentiation through cone programs
Python
91
star
13

cocp

Source code for the examples accompanying the paper "Learning convex optimization control policies."
Jupyter Notebook
80
star
14

ncvx

Python
73
star
15

cvxflow

Python
66
star
16

signal-decomposition

A simple and general framework for signal decomposition
Jupyter Notebook
60
star
17

auto_ks

Repository for "Fitting a Kalman Smoother to Data"
Python
55
star
18

cov_pred_finance

Jupyter Notebook
54
star
19

cvxpower

Power Network Optimization and Simulation.
Python
48
star
20

dmcp

A CVXPY extension for multi-convex programming
Python
45
star
21

qcml

A Python parser for generating Python/C/Matlab solver interfaces
Python
43
star
22

CVXcanon

C++
42
star
23

miqp_admm

ADMM for Mixed-Integer Quadratic Programming
C
41
star
24

vwap_opt_exec

Volume Weighted Average Price Optimal Execution
Jupyter Notebook
41
star
25

fastpathplanning

A fast algorithm for finding an optimal path in a collection of safe boxes
Python
37
star
26

simulator

Tool to support backtests
Jupyter Notebook
36
star
27

cptopt

Portfolio Optimization with Cumulative Prospect Theory Utility via Convex Optimization
Python
31
star
28

a2dr

Anderson accelerated Douglas-Rachford splitting
Python
29
star
29

kelly_code

Code and examples for the project on risk-constrained Kelly gambling
Jupyter Notebook
26
star
30

strat_models

A distributed method for fitting Laplacian regularized stratified models.
Python
25
star
31

dsp

A CVXPY extension for saddle problems
Python
24
star
32

cvxmarkowitz

Jupyter Notebook
23
star
33

nonexp_global_aa1

Globally Convergent Type-I Anderson Acceleration for Non-Smooth Fixed-Point Iterations
MATLAB
21
star
34

osc

C package performing operator splitting for control
C
21
star
35

markowitz-reference

This repository contains a reference implementation of the Markowitz portfolio optimization problem discussed in the paper Markowitz Portfolio Construction at Seventy.
Python
20
star
36

exp_util_gm_portfolio_opt

Minimal entropic value at risk (EVaR) portfolio construction under a Gaussian mixture model of returns.
Python
20
star
37

pdos

Primal-Dual Operator Splitting Method for Conic Optimization
C
20
star
38

cvxstatarb

Jupyter Notebook
19
star
39

aa

Anderson Acceleration
Jupyter Notebook
19
star
40

covpred

Covariance prediction via convex optimization
Python
18
star
41

rsw

rsw: optimal representative sample weighting.
Python
17
star
42

l1_ls

This is the repository for the l1_ls, a simple Matlab solver for l1-regularized least squares problems.
MATLAB
17
star
43

cvx_opt_risk_neutral

Convex optimization over risk-neutral probabilities.
Jupyter Notebook
14
star
44

cvxpyrepair

Code for "Automatic repair of convex optimization problems".
Python
14
star
45

osmm

oracle-structured minimization method
Python
13
star
46

lrsm_portfolio

Portfolio Construction using Stratified Models
Jupyter Notebook
12
star
47

robust_bond_portfolio

Robust Bond Portfolio Construction via Convex-Concave Saddle Point Optimization
Python
10
star
48

mkvchain

Fitting Feature-Dependent Markov Chains
Jupyter Notebook
10
star
49

icqm

MATLAB script for approximating the solution to the integer convex quadratic minimization problem
MATLAB
10
star
50

subgradpy

Subgradient calculator for Python
Python
9
star
51

cone_prog_refine

Cone program refinement
Python
9
star
52

PrincipalTimeSeries

MATLAB
9
star
53

torch_linops

A library to define abstract linear operators, and associated algebra and matrix-free algorithms, that works with pyTorch Tensors.
Python
9
star
54

cvxrisk

Compile risk with cvxpy
Jupyter Notebook
9
star
55

vgi

Value-gradient iteration for convex stochastic control
Python
8
star
56

SURE-CR

Tractable evaluation of Stein's Unbiased Risk Estimator on convexly regularized estimators
Python
8
star
57

OSBDO

Oracle-Structured Bundle Distributed Optimization (OSBDO)
Python
7
star
58

sigopt

Solvers for sigmoidal programming problems
Python
7
star
59

cvxcla

critical line algorithm for efficient frontier
Jupyter Notebook
7
star
60

qss

QSS: Quadratic-Separable Solver
Jupyter Notebook
7
star
61

spcqe

Smooth periodic consistent quantile estimation
Jupyter Notebook
7
star
62

low_rank_forecasting_code

Code for "Low Rank Forecasting" paper.
Jupyter Notebook
6
star
63

graph_isom

Python
6
star
64

mlr_fitting

Factor Fitting, Rank Allocation, and Partitioning in Multilevel Low Rank Matrices
Jupyter Notebook
6
star
65

WaveOperators.jl

Building matrices in physics is hard; that's why this package exists.
Julia
6
star
66

l1_tf

This is the repository for the l1_tf, software for l1 trend filtering.
C
6
star
67

cvx-docker

Docker image containing CVXPY and other cvxgrp libraries
6
star
68

cvx-finance-examples

Makefile
6
star
69

lfd_lqr

Code for "Fitting a Linear Control Policy to Demonstrations with a Kalman Constraint"
Jupyter Notebook
5
star
70

lass

Linear algebra for structured sparse matrices
Python
5
star
71

sccf

Repository for "Minimizing a sum of clipped convex functions" paper
Python
5
star
72

mm_dist_lapl

Python
5
star
73

ls-spa

A package for efficient Shapley performance attribution for least-squares problems
Python
5
star
74

conda-recipes

Anaconda recipes for cvxgrp python packages
Shell
4
star
75

joint-lrsm

Joint graph learning and model fitting in Laplacian Regularized Stratified Models
Python
4
star
76

multi_period_liability_clearing

Code for the paper "Multi-period liability clearing via convex optimal control"
Python
4
star
77

l1_logreg

This is the repository for the l1_logreg, l1-regularized logistic regression problem solver.
C
3
star
78

resalloc

Efficient allocation of fungible resources
Jupyter Notebook
3
star
79

multilevel_factor_model

Fitting multilevel factor model
Jupyter Notebook
3
star
80

n-queens

Python
2
star
81

PhysicalBounds.jl

Julia
2
star
82

incre_prox_mf_mpc

code for the paper Incremental Proximal Multi-Forecast Model Predictive Control
Jupyter Notebook
2
star
83

home-energy-management

Home energy management with dynamic tariffs and tiered peak power charges.
Jupyter Notebook
2
star
84

cvxcli

Example cli using fire, poetry and pipx
Python
2
star
85

boolprob

A Python tool to analyze joint distributions of boolean random variables
Python
2
star
86

cvxbson

dealing with json and bson files
Python
2
star
87

opt_cap_res

Solves the problem of reserving link capacity in a network in such a way that any of a given set of flow scenarios can be supported.
Python
2
star
88

smooth_multiperiodic_forecasting_experiments

Notebook accompanying numerical results section of the paper "Interpretable Net Load Forecasting Using Smooth Multiperiodic Features".
Jupyter Notebook
2
star
89

ewmm_code

Code for the EWMM paper
Jupyter Notebook
2
star
90

pv_bundt_cake

Code reproducing results of the paper "Time Dilated Bundt Cake Analysis of PV Output"
Jupyter Notebook
2
star
91

rerm_code

Public code for Robust Empirical Risk Minimization Paper
Python
1
star
92

ls-spa-benchmark

Python
1
star
93

extquadcontrol

Python
1
star
94

convexjl

A julia package for disciplined convex programming.
1
star
95

cvx_stat_arb

Jupyter Notebook
1
star
96

cvxbacktest

Python
1
star
97

coneos

C package that solves convex cone problems via operator splitting (DEPRECATED, new project https://github.com/cvxgrp/scs)
C
1
star
98

pd-heuristics-and-bounds

Julia
1
star
99

boilerplate

We use this repo to automate and avoid boilerplate issue
Python
1
star
100

randalo

Python
1
star