All of the examples can be found in Jupyter notebook form here.
Paper examples
using Convex, ECOS
Summation.
println("Summation example")
x = Variable();
e = 0;
@time begin
for i = 1:1000
global e
e += x;
end
p = minimize(e, x>=1);
end
@time solve!(p, ECOSSolver())
Summation example
0.027473 seconds (4.64 k allocations: 11.763 MiB, 46.26% gc time)
----------------------------------------------------------------------------
SCS v2.1.1 - Splitting Conic Solver
(c) Brendan O'Donoghue, Stanford University, 2012
----------------------------------------------------------------------------
Lin-sys: sparse-indirect, nnz in A = 125, CG tol ~ 1/iter^(2.00)
eps = 1.00e-05, alpha = 1.50, max_iters = 5000, normalize = 1, scale = 1.00
acceleration_lookback = 10, rho_x = 1.00e-03
Variables n = 9, constraints m = 75
Cones: primal zero / dual free vars: 39
sd vars: 36, sd blks: 1
Setup time: 2.06e-04s
----------------------------------------------------------------------------
Iter | pri res | dua res | rel gap | pri obj | dua obj | kap/tau | time (s)
----------------------------------------------------------------------------
0| 4.97e+18 4.10e+19 1.00e+00 -8.89e+18 7.29e+19 3.72e+19 2.79e-04
20| 3.16e-09 3.34e-09 5.90e-10 -2.40e-09 -1.81e-09 3.79e-17 1.54e-03
----------------------------------------------------------------------------
Status: Solved
Timing: Solve time: 1.54e-03s
Lin-sys: avg # CG iterations: 1.90, avg solve time: 3.51e-06s
Cones: avg projection time: 5.22e-05s
Acceleration: avg step time: 1.35e-05s
----------------------------------------------------------------------------
Error metrics:
dist(s, K) = 8.2379e-10, dist(y, K*) = 3.2732e-09, s'y/|s||y| = -1.6903e-12
primal res: |Ax + s - b|_2 / (1 + |b|_2) = 3.1596e-09
dual res: |A'y + c|_2 / (1 + |c|_2) = 3.3352e-09
rel gap: |c'x + b'y| / (1 + |c'x| + |b'y|) = 5.9001e-10
----------------------------------------------------------------------------
c'x = -0.0000, -b'y = -0.0000
============================================================================
----------------------------------------------------------------------------
SCS v2.1.1 - Splitting Conic Solver
(c) Brendan O'Donoghue, Stanford University, 2012
----------------------------------------------------------------------------
Lin-sys: sparse-indirect, nnz in A = 27, CG tol ~ 1/iter^(2.00)
eps = 1.00e-05, alpha = 1.50, max_iters = 5000, normalize = 1, scale = 1.00
acceleration_lookback = 10, rho_x = 1.00e-03
Variables n = 6, constraints m = 17
Cones: primal zero / dual free vars: 2
linear vars: 8
soc vars: 7, soc blks: 2
Setup time: 3.79e-05s
----------------------------------------------------------------------------
Iter | pri res | dua res | rel gap | pri obj | dua obj | kap/tau | time (s)
----------------------------------------------------------------------------
0| 1.65e+19 1.98e+19 1.00e+00 -3.08e+19 5.62e+18 4.89e+19 1.86e-05
60| 2.67e-09 6.52e-09 2.01e-09 6.32e-03 6.32e-03 1.25e-16 3.61e-04
----------------------------------------------------------------------------
Status: Solved
Timing: Solve time: 3.63e-04s
Lin-sys: avg # CG iterations: 3.15, avg solve time: 9.30e-07s
Cones: avg projection time: 1.14e-07s
Acceleration: avg step time: 4.04e-06s
----------------------------------------------------------------------------
Error metrics:
dist(s, K) = 1.1734e-16, dist(y, K*) = 2.7756e-17, s'y/|s||y| = -5.0362e-17
primal res: |Ax + s - b|_2 / (1 + |b|_2) = 2.6652e-09
dual res: |A'y + c|_2 / (1 + |c|_2) = 6.5229e-09
rel gap: |c'x + b'y| / (1 + |c'x| + |b'y|) = 2.0108e-09
----------------------------------------------------------------------------
c'x = 0.0063, -b'y = 0.0063
============================================================================
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 +1.000e+03 +1.000e+03 +7e+01 1e-02 4e-05 1e+00 4e+01 --- --- 1 1 - | - -
1 +1.000e+03 +1.000e+03 +8e-01 1e-04 4e-07 1e-02 4e-01 0.9890 1e-04 1 1 0 | 0 0
2 +1.000e+03 +1.000e+03 +9e-03 1e-06 4e-09 2e-04 5e-03 0.9890 1e-04 1 0 0 | 0 0
3 +1.000e+03 +1.000e+03 +1e-04 1e-08 5e-11 3e-06 5e-05 0.9890 1e-04 1 0 0 | 0 0
4 +1.000e+03 +1.000e+03 +1e-06 2e-10 5e-13 3e-08 6e-07 0.9890 1e-04 0.040663 seconds (97.66 k allocations: 5.013 MiB)
Indexing.
println("Indexing example")
x = Variable(1000, 1);
e = 0;
@time begin
for i = 1:1000
global e
e += x[i];
end
p = minimize(e, x >= ones(1000, 1));
end
@time solve!(p, ECOSSolver())
Indexing example
0.181705 seconds (125.90 k allocations: 17.667 MiB, 8.98% gc time)
0.145975 seconds (160.90 k allocations: 79.098 MiB, 53.70% gc time)
Matrix constraints.
println("Matrix constraint example")
n, m, p = 100, 100, 100
X = Variable(m, n);
A = randn(p, m);
b = randn(p, n);
@time begin
p = minimize(norm(vec(X)), A * X == b);
end
@time solve!(p, ECOSSolver())
Matrix constraint example
0.159357 seconds (242.37 k allocations: 11.278 MiB)
1.867681 seconds (211.75 k allocations: 147.876 MiB, 15.79% gc time)
Transpose.
println("Transpose example")
X = Variable(5, 5);
A = randn(5, 5);
@time begin
p = minimize(norm2(X - A), X' == X);
end
@time solve!(p, ECOSSolver())
n = 3
A = randn(n, n);
#@time begin
X = Variable(n, n);
p = minimize(norm(vec(X' - A)), X[1,1] == 1);
solve!(p, ECOSSolver())
#end
Transpose example
0.287097 seconds (76.47 k allocations: 3.767 MiB, 79.17% gc time)
0.025857 seconds (33.33 k allocations: 1.664 MiB)
This page was generated using Literate.jl.