https://github.com/cvxgrp/dsp

A CVXPY extension for saddle problems

https://github.com/cvxgrp/dsp

Science Score: 36.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.8%) to scientific vocabulary

Keywords

cvxpy modeling-language optimization python saddle-point

Keywords from Contributors

archival projection investing interactive generic sequences profiles serial mathematical-optimization numerical-optimization
Last synced: 6 months ago · JSON representation

Repository

A CVXPY extension for saddle problems

Basic Info
  • Host: GitHub
  • Owner: cvxgrp
  • License: apache-2.0
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 1.44 MB
Statistics
  • Stars: 26
  • Watchers: 6
  • Forks: 4
  • Open Issues: 2
  • Releases: 3
Topics
cvxpy modeling-language optimization python saddle-point
Created over 3 years ago · Last pushed 7 months ago
Metadata Files
Readme License

README.md

DSP - Disciplined Saddle Programming

build Coverage

A CVXPY extension for Disciplined Saddle Programming. DSP allows solving convex-concave saddle point problems, and more generally convex optimization problems we refer to as saddle problems, which include the partial supremum or infimum of convex-concave saddle functions. Saddle functions are functions that are (jointly) convex in a subset of their arguments, and (jointly) concave in the remaining arguments. A detailed description of the underlying method is given in our accompanying paper.

Installation

The DSP package can be installed using pip as follows bash pip install dsp-cvxpy The DSP package requires CVXPY 1.3 or later.

Minimal example

The following example creates and solves a simple saddle point problem known as a matrix game. A saddle point problem is created by specifying an objective and a list of constraints. Here, the objective is $f(x, y) = x^TCy$, which is simultaneously minimized over $x$ and maximized over $y$. The resulting saddle point is an optimal mixed strategy for both players in the matrix game. Each component is explained below in more detail.

```python import dsp import cvxpy as cp import numpy as np

x = cp.Variable(2) y = cp.Variable(2) C = np.array([[1, 2], [3, 1]])

f = dsp.inner(x, C @ y) obj = dsp.MinimizeMaximize(f)

constraints = [x >= 0, cp.sum(x) == 1, y >= 0, cp.sum(y) == 1] prob = dsp.SaddlePointProblem(obj, constraints) prob.solve() # solves the problem

prob.value # 1.6666666666666667 x.value # array([0.66666667, 0.33333333]) y.value # array([0.33333333, 0.66666667]) ```

New atoms

In DSP, saddle functions are created from atoms. Each atom represents a saddle function, with the convention being that the first argument is the convex argument and the second argument is the concave argument.

  • inner(x, y)
    The inner product $x^Ty$, with both arguments affine.
  • saddle_inner(Fx, Gy)
    The inner product $F(x)^TG(y)$, with $F$ convex and nonnegative, and $G$ concave. If $G$ is not nonnegative, a constraint $G \geq 0$ is added.
  • weighted_norm2(x, y)
    The weighted $\ell2$ norm $\left(\sumi yi xi^2\right)^{1/2}$. Here too, a constraint $y \geq 0$ is added if $y$ is not nonnegative.
  • weighted_log_sum_exp(x, y) The weighted log-sum-exp function $\log\left(\sumi yi \exp(x_i)\right)$. Again a constraint $y \geq 0$ is added if $y$ is not nonnegative.
  • quasidef_quad_form(x, y, P, Q, S)
    For a positive semidefinite matrix $P$ and a negative semidefinite matrix $S$, this atom represents the function

$$ f(x,y) = \left[\begin{array}{c} x \\ y \end{array}\right]^T \left[\begin{array}{cc} P & S \\ S^T & Q \end{array}\right] \left[\begin{array}{c} x \\ y \end{array}\right]. $$ - saddle_quad_form(x, Y)
The quadratic form $x^TYx$, where $Y$ a positive semindefinite matrix.

Calculus rules

Saddle functions can be scaled and composed by addition. DCP convex expressions are treated as saddle functions with no concave arguments, and DCP concave expressions are treated as saddle functions with no convex arguments. When adding two saddle functions, a variable may not appear as a convex variable in one expression and as a concave variable in the other expression.

Note that negating a saddle function switches the roles of the convex and concave arguments.
For example, -inner(x, y) is equivalent to inner(y, -x), not inner(-x, y). This might seem counterintuitive, especially for bi-affine functions, where both are DSP-compliant, but it is consistent with the fact that

$$ -\minx\maxy x^T y = \maxx\miny -x^T y \neq \minx\maxy - x^T y. $$

Saddle point problems

To create a saddle point problem, a MinimizeMaximize object is created first, which represents the objective function, using python obj = dsp.MinimizeMaximize(f) where f is a DSP-compliant expression.

The syntax for specifying saddle point problems is python problem = dsp.SaddlePointProblem(obj, constraints, cvx_vars, ccv_vars) where obj is the MinimizeMaximize object, constraints is a list of constraints, and cvx_vars and ccv_vars are lists of variables to be minimized and maximized over, respectively.

Each constraint must be DCP, and can only involve variables that are either convex or concave. When the role of a variable can be inferred, it can be omitted from the list of convex or concave variables. The role can be inferred either from a saddle atom, a DCP atom that is convex or concave, but not affine, or from a constraint, when a variable appears in a constraint that involves variables with known roles.

Nevertheless, specifying the role of each variable can add clarity to the problem formulation, and is especially useful for debugging.

To solve the problem, call problem.solve(). This returns the optimal saddle value, which is also stored in the problem's value attribute. Further all value attribute of the variables are populated with their optimal values.

Saddle extremum functions

A saddle extremum function has one of the forms

$$ G(x) = \sup{y \in \mathcal{Y}} f(x,y) \quad \text{or} \quad H(y) = \inf{x \in \mathcal{X}} f(x,y), $$

where $f$ is a saddle function, and $\mathcal{X}$ and $\mathcal{Y}$ are convex. Since the functions only depend on $x$ or $y$, respectively, the other variables have to be declared as LocalVariables. Any LocalVariable can only be used in one saddle extremum function. The syntax for creating a saddle extremum function is python dsp.saddle_max(f, constraints) dsp.saddle_min(f, constraints) where f is a DSP-compliant scalar saddle function, and constraints is a list of constraints, which can only involve LocalVariables. DSP-compliant saddle extremum functions are DCP-convex or DCP-concave, respectively, and as such can be used in DCP optimization problems.

An example of a saddle extremum function is ```python

Creating variables

x = cp.Variable(2)

Creating local variables

y_loc = dsp.LocalVariable(2)

Convex in x, concave in y_loc

f = dsp.saddleinner(C @ x, yloc)

maximizes over y_loc

G = dsp.saddlemax(f, [yloc >= 0, cp.sum(y_loc) == 1]) ```

Saddle problems

A saddle problem is a convex optimization problem that involves saddle extremum functions. Any DCP convex optimization can include saddle extremum functions when they are DSP-compliant. Using the saddle extremum function G from above, we can solve the following problem: ```python prob = cp.Problem(cp.Minimize(G), [x >= 0, cp.sum(x) == 1]) prob.solve() # solving the problem

prob.value # 1.6666666666666667 x.value # array([0.66666667, 0.33333333]) ```

Citation

If you want to reference DSP in your research, please consider citing us by using the following BibTeX:

BibTeX @article{schiele2024dsp, title = {Disciplined Saddle Programming}, author = {Schiele, Philipp and Luxenberg, Eric and Boyd, Stephen}, journal = {Transactions on Machine Learning Research}, year = {2024}, pages = {1--25}, url = {https://openreview.net/forum?id=KhMLfEIoUm}, }

Owner

  • Name: Stanford University Convex Optimization Group
  • Login: cvxgrp
  • Kind: organization
  • Location: Stanford, CA

GitHub Events

Total
  • Create event: 4
  • Release event: 1
  • Issues event: 2
  • Watch event: 4
  • Delete event: 4
  • Issue comment event: 4
  • Push event: 23
  • Pull request review comment event: 7
  • Pull request review event: 9
  • Pull request event: 7
Last Year
  • Create event: 4
  • Release event: 1
  • Issues event: 2
  • Watch event: 4
  • Delete event: 4
  • Issue comment event: 4
  • Push event: 23
  • Pull request review comment event: 7
  • Pull request review event: 9
  • Pull request event: 7

Committers

Last synced: about 2 years ago

All Time
  • Total Commits: 254
  • Total Committers: 5
  • Avg Commits per committer: 50.8
  • Development Distribution Score (DDS): 0.476
Past Year
  • Commits: 236
  • Committers: 5
  • Avg Commits per committer: 47.2
  • Development Distribution Score (DDS): 0.483
Top Committers
Name Email Commits
phschiele p****e@g****m 133
ericlux 4****x 103
Philipp Schiele 4****e 10
dependabot[bot] 4****] 5
Kurt McKee c****e@k****g 3
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 12
  • Total pull requests: 26
  • Average time to close issues: 14 days
  • Average time to close pull requests: 3 months
  • Total issue authors: 7
  • Total pull request authors: 5
  • Average comments per issue: 1.75
  • Average comments per pull request: 0.54
  • Merged pull requests: 13
  • Bot issues: 0
  • Bot pull requests: 18
Past Year
  • Issues: 2
  • Pull requests: 9
  • Average time to close issues: 15 days
  • Average time to close pull requests: 2 months
  • Issue authors: 2
  • Pull request authors: 4
  • Average comments per issue: 0.5
  • Average comments per pull request: 0.33
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 5
Top Authors
Issue Authors
  • tschm (3)
  • rjboczar (2)
  • keithbriggs (2)
  • SteveDiamond (2)
  • dilipmadan46 (1)
  • dogged1021 (1)
  • debackerl (1)
Pull Request Authors
  • dependabot[bot] (18)
  • tschm (3)
  • kurtmckee (2)
  • phschiele (2)
  • smachen42 (1)
Top Labels
Issue Labels
Pull Request Labels
dependencies (18) github_actions (3)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 96 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 6
  • Total maintainers: 2
pypi.org: dsp-cvxpy

Disciplined Saddle Programming

  • Versions: 6
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 96 Last month
Rankings
Dependent packages count: 6.6%
Stargazers count: 20.5%
Average: 22.1%
Forks count: 30.5%
Dependent repos count: 30.6%
Maintainers (2)
Last synced: 6 months ago

Dependencies

.github/workflows/test.yml actions
  • SonarSource/sonarcloud-github-action master composite
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
.github/workflows/docs.yml actions
  • JamesIves/github-pages-deploy-action v4.4.1 composite
  • actions/checkout v3 composite
  • actions/setup-python v4 composite