Quick Tutorial

Consider a constrained least squares problem

\[\begin{aligned} \begin{array}{ll} \mbox{minimize} & \|Ax - b\|_2^2 \\ \mbox{subject to} & x \geq 0 \end{array} \end{aligned}\]

with variable $x\in \mathbf{R}^{n}$, and problem data $A \in \mathbf{R}^{m \times n}$, $b \in \mathbf{R}^{m}$.

This problem can be solved in Convex.jl as follows: :

julia> # Make the Convex.jl module available
       using Convex, SCS

julia> # Generate random problem data
       m = 4;  n = 5
5

julia> A = randn(m, n); b = randn(m, 1)
4×1 Array{Float64,2}:
 -0.5982561974146283
  1.8285635154246862
  0.7473287766124718
  1.9114497945229456

julia> # Create a (column vector) variable of size n x 1.
       x = Variable(n)
Variable
size: (5, 1)
sign: real
vexity: affine
id: 104…137

julia> # The problem is to minimize ||Ax - b||^2 subject to x >= 0
       # This can be done by: minimize(objective, constraints)
       problem = minimize(sumsquares(A * x - b), [x >= 0])
minimize
└─ qol_elem (convex; positive)
   ├─ norm2 (convex; positive)
   │  └─ + (affine; real)
   │     ├─ …
   │     └─ …
   └─ [1.0]
subject to
└─ >= constraint (affine)
   ├─ 5-element real variable (id: 104…137)
   └─ 0

current status: not yet solved

julia> # Solve the problem by calling solve!
       solve!(problem, SCSSolver())
   1  0  0 |  0  0

OPTIMAL (within feastol=1.6e-10, reltol=1.1e-09, abstol=1.1e-06).
Runtime: 0.000075 seconds.


ECOS 2.0.5 - (C) embotech GmbH, Zurich Switzerland, 2012-15. Web: www.embotech.com/ECOS

It     pcost       dcost      gap   pres   dres    k/t    mu     step   sigma     IR    |   BT
 0  +9.999e+02  +1.010e+03  +1e+03  3e-02  9e-03  1e+00  1e+00    ---    ---    2  2  - |  -  - 
 1  +1.000e+03  +1.000e+03  +1e+01  3e-04  1e-04  1e-02  1e-02  0.9890  1e-04   2  1  2 |  0  0
 2  +1.000e+03  +1.000e+03  +1e-01  4e-06  1e-06  1e-04  1e-04  0.9890  1e-04   2  1  1 |  0  0
 3  +1.000e+03  +1.000e+03  +1e-03  4e-08  1e-08  1e-06  1e-06  0.9890  1e-04   2  1  1 |  0  0
 4  +1.000e+03  +1.000e+03  +2e-05  5e-10  1e-10  2e-08  2e-08  0.9890  1e-04   2  0  1 |  0  0
 5  +1.000e+03  +1.000e+03  +2e-07  5e-12  2e-12  2e-10  2e-10  0.9890  1e-04   2  0  0 |  0  0

OPTIMAL (within feastol=5.0e-12, reltol=1.7e-10, abstol=1.7e-07).
Runtime: 0.002381 seconds.


ECOS 2.0.5 - (C) embotech GmbH, Zurich Switzerland, 2012-15. Web: www.embotech.com/ECOS

It     pcost       dcost      gap   pres   dres    k/t    mu     step   sigma     IR    |   BT
 0  +0.000e+00  -0.000e+00  +1e+03  4e-03  2e-04  1e+00  7e+02    ---    ---    1  2  - |  -  - 
 1  +1.316e+01  +1.351e+01  +7e+01  5e-04  2e-05  4e-01  4e+01  0.9495  1e-04   3  3  3 |  0  0
 2  +1.609e+02  +1.676e+02  +8e+00  6e-05  2e-06  7e+00  5e+00  0.9231  8e-02   4  4  4 |  0  0
 3  +1.698e+02  +1.699e+02  +9e-02  6e-07  2e-08  8e-02  6e-02  0.9890  1e-04   3  2  2 |  0  0
 4  +1.699e+02  +1.699e+02  +1e-03  7e-09  2e-10  8e-04  7e-04  0.9890  1e-04   3  2  2 |  0  0
 5  +1.699e+02  +1.699e+02  +1e-05  8e-11  2e-12  1e-05  7e-06  0.9890  1e-04   4  2  2 |  0  0
 6  +1.699e+02  +1.699e+02  +1e-07  1e-12  2e-14  1e-07  8e-08  0.9890  1e-04   3  2  2 |  0  0

OPTIMAL (within feastol=1.1e-12, reltol=7.3e-10, abstol=1.2e-07).
Runtime: 1.441027 seconds.


ECOS 2.0.5 - (C) embotech GmbH, Zurich Switzerland, 2012-15. Web: www.embotech.com/ECOS

It     pcost       dcost      gap   pres   dres    k/t    mu     step   sigma     IR    |   BT
 0  +0.000e+00  -0.000e+00  +2e+01  3e-01  2e-05  1e+00  1e+01    ---    ---    1  1  - |  -  - 
 1  +4.876e-01  +4.974e-01  +2e+00  3e-02  2e-06  1e-01  1e+00  0.9015  1e-03   2  2  2 |  0  0
 2  +2.380e+00  +2.437e+00  +1e-01  2e-03  2e-07  7e-02  1e-01  0.9641  6e-02   2  2  2 |  0  0
 3  +2.455e+00  +2.456e+00  +2e-03  2e-05  2e-09  7e-04  1e-03  0.9890  1e-04   1  1  1 |  0  0
 4  +2.456e+00  +2.456e+00  +2e-05  2e-07  2e-11  8e-06  1e-05  0.9890  1e-04   1  1  1 |  0  0
 5  +2.456e+00  +2.456e+00  +2e-07  3e-09  3e-13  9e-08  1e-07  0.9890  1e-04   1  1  1 |  0  0
 6  +2.456e+00  +2.456e+00  +2e-09  3e-11  3e-15  1e-09  2e-09  0.9890  1e-04   1  1  1 |  0  0

OPTIMAL (within feastol=2.9e-11, reltol=8.5e-10, abstol=2.1e-09).
Runtime: 0.000249 seconds.


ECOS 2.0.5 - (C) embotech GmbH, Zurich Switzerland, 2012-15. Web: www.embotech.com/ECOS

It     pcost       dcost      gap   pres   dres    k/t    mu     step   sigma     IR    |   BT
 0  +0.000e+00  -0.000e+00  +1e+01  3e-01  9e-05  1e+00  6e+00    ---    ---    1  1  - |  -  - 
 1  +4.127e-02  +4.170e-02  +5e-01  2e-02  5e-06  5e-02  3e-01  0.9478  1e-04   2  1  1 |  0  0
 2  +4.498e-01  +4.653e-01  +6e-02  3e-03  5e-07  2e-02  4e-02  0.9292  7e-02   2  2  2 |  0  0
 3  +4.694e-01  +4.695e-01  +6e-04  3e-05  5e-09  3e-04  4e-04  0.9890  1e-04   1  1  1 |  0  0
 4  +4.696e-01  +4.696e-01  +7e-06  3e-07  6e-11  3e-06  5e-06  0.9890  1e-04   1  1  1 |  0  0
 5  +4.696e-01  +4.696e-01  +8e-08  4e-09  7e-13  3e-08  5e-08  0.9890  1e-04   2  1  1 |  0  0
 6  +4.696e-01  +4.696e-01  +8e-10  4e-11  8e-15  4e-10  6e-10  0.9890  1e-04   2  1  1 |  0  0

OPTIMAL (within feastol=4.2e-11, reltol=1.8e-09, abstol=8.4e-10).
Runtime: 0.000120 seconds.

----------------------------------------------------------------------------
	SCS v2.1.1 - Splitting Conic Solver
	(c) Brendan O'Donoghue, Stanford University, 2012
----------------------------------------------------------------------------
Lin-sys: sparse-indirect
julia> # Check the status of the problem
       problem.status # :Optimal, :Infeasible, :Unbounded etc.
:Optimal

julia> # Get the optimum value
       problem.optval
7.7918849978570375