All of the examples can be found in Jupyter notebook form here.

Trade-off curves

using Random
Random.seed!(1)
m = 25;
n = 10;
A = randn(m, n);
b = randn(m, 1);
using Convex, SCS, LinearAlgebra


gammas = exp10.(range(-4, stop=2, length=100));

x_values = zeros(n, length(gammas));
x = Variable(n);
for i=1:length(gammas)
    cost = sumsquares(A*x - b) + gammas[i]*norm(x,1);
    problem = minimize(cost, [norm(x, Inf) <= 1]);
    solve!(problem, SCSSolver(verbose=0));
    x_values[:,i] = evaluate(x);
end

Plot the regularization path.

using Plots
plot(title = "Entries of x vs lambda", xaxis=:log, xlabel="lambda", ylabel="x" )
for i = 1:n
    plot!(gammas, x_values[i,:], label="x$i")
end
plot!()
10-4 10-3 10-2 10-1 100 101 102 -0.6-0.4-0.20.00.2Entries of x vs lambdalambdaxx1x2x3x4x5x6x7x8x9x10

This page was generated using Literate.jl.