CVXPY

CVXPY allows us to cast convex optimization tasks into OOP code.

\begin{align} \min \mid Ax - b \mid^{2}_{2} \end{align}

object to:

\(x \geq 0\)

import cvxpy as cp

A,b = ...

x = cp.Variable(n)
obj = cp.norm2(A@x - b)**2
constraints = [x >= 0]

prob = cp.Problem(cp.Minimize(obj), constraints)
prob.solve()

How it works

  1. starts with the optimization problem \(P_{1}\)
  2. applies a series of problem transformation \(P_{2} … P_{N}\)
  3. final problem \(P_{N}\) should be one of Linear Program, Quadratic Program, SOCP, SDP
  4. calls a specialized solver on \(P_{N}\)
  5. retrieves the solution of the original problem by reversing transformations