Code Monkey home page Code Monkey logo

quadraticprogramsolver's Introduction

Visitors Donate using Liberapay

Quadratic Program Solver

View Quadratic Program Solver on File Exchange

Solves a Quadratic Programming problem using Alternating Direction Method of Multipliers (ADMM).
This is a MATLAB implementation of the paper - OSQP: An Operator Splitting Solver for Quadratic Programs.

Remark: Any Quadratic Program Solver can solve Constrained Least Squares problem as well (With linear and convex constraints).

Motivation

I needed for some Signal / Image Processing projects a solver of a problem of the form:

$$\begin{aligned} \arg \min_{\boldsymbol{x}} & \quad \frac{1}{2} {\left| A \boldsymbol{x} - \boldsymbol{b} \right|}_{2}^{2} \\ \text{subject to} & \quad B \boldsymbol{x} \leq \boldsymbol{c} \\ & \quad D \boldsymbol{x} = \boldsymbol{e} \end{aligned}$$

I could use MATLAB's quadprog() or lsqlin() yet both are part of the Optimization Toolbox which isn't widely accessible.
When I learned about ADMM, Projection and Optimization in general I played with some implementations for this problem but they were pretty slow and sensitive to parameters.
When OSQP became available it showed those problem can be solved.
It requires compiling and even defining GCC as the compiler on Windows which isn't easy to everyone.
Hence I thought it would be nice to replicate the paper (As the C code is way beyond me) in MATLAB.
Within few hours I had a first working code though without all the features (See To Do).

The goal is to have a viable alternative to MATLAB's quadprog().
While in most cases quadprog() will be faster choice, this implementation should be good enough and free solution.

Implementation in High Level Language might assist with faster integration of better optimization and flexibility (For instance, supporting non sparse matrices).

The Code

The solver is implemented in the function SolveQuadraticProgram().
It uses MATLAB's argument block and requires MATLAB R2020b (Ver 9.9) to the least.
Users of previous MATLAB versions might try remove this block (Be careful about the parameters).

The function solves the following form of Quadratic Program:

$$\begin{aligned} \arg \min_{\boldsymbol{x}} & \quad \frac{1}{2} \boldsymbol{x}^{T} P \boldsymbol{x} + \boldsymbol{x}^{T} \boldsymbol{q} \\ \text{subject to} & \quad \boldsymbol{l} \leq A \boldsymbol{x} \leq \boldsymbol{u} \end{aligned}$$

Where $ P \in \mathbb{S}_{+}^{n} $ (A symmetric positive semi definite matrix).

Documentation

In Progress...

Look inside the function SolveQuadProgram() and see the reference paper.

Unit Test

The unit tests implemented in SolveQuadraticProgramUnitTest.m.
The script requires CVX and Optimization Toolbox.
It basically generates a problem and verify the solution of SolveQuadraticProgram() vs. the other 2 references.

To Do

  1. Check if making paramRho a matrix has a real benefit.
  2. Implement the scaling procedure from the reference paper.
  3. Optimize the solution to the linear system (Is there anything better than pcg() for this structure? LSMR style?).
  4. Better reporting.
  5. Implement last step as Projected Gradient Descent in order to be strictly feasible.

Julia Code

The project implements the method in Julia Language as well (The .jl files).
The goal is to have a Julia package on its own. But it will happen only once performance will be in parity with the C code.
Julia has the potential to have even better performance than MATLAB's quadprog().

Reference

The code is an implementation of the paper Stellato, B. and Banjac, G. and Goulart, P. and Bemporad, A. and Boyd, S. - {OSQP}: An Operator Splitting Solver for Quadratic Programs.
This is a really great paper as the writers gave all the little details to create a truly competitive solver with ADMM.
Their work is really amazing.

quadraticprogramsolver's People

Contributors

royiavital avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.