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, () -> ECOS.Optimizer(verbose=0))
Summation example
0.013567 seconds (4.64 k allocations: 11.763 MiB)
1.349140 seconds (2.13 M allocations: 106.883 MiB, 6.00% gc time)
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, () -> ECOS.Optimizer(verbose=0))
Indexing example
0.146036 seconds (126.00 k allocations: 17.675 MiB)
0.117719 seconds (175.28 k allocations: 80.086 MiB, 35.29% 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, () -> ECOS.Optimizer(verbose=0))
Matrix constraint example
0.174976 seconds (262.83 k allocations: 12.309 MiB, 7.72% gc time)
2.567839 seconds (865.58 k allocations: 379.401 MiB, 23.96% 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, () -> ECOS.Optimizer(verbose=0))
n = 3
A = randn(n, n);
#@time begin
X = Variable(n, n);
p = minimize(norm(vec(X' - A)), X[1,1] == 1);
solve!(p, () -> ECOS.Optimizer(verbose=0))
#end
Transpose example
0.052721 seconds (76.61 k allocations: 3.772 MiB, 19.07% gc time)
0.029236 seconds (41.06 k allocations: 2.125 MiB)
This page was generated using Literate.jl.