-
Notifications
You must be signed in to change notification settings - Fork 0
/
example1.jl
42 lines (33 loc) · 1.18 KB
/
example1.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using LinearAlgebra
using PlotsOptim
## function F = f + g
A = Matrix{Float64}([1. 1.; 0. 1.]) .* 0.5
x0 = Vector([-0.25, 1.2])
b = A * x0
f(A, b, x) = 0.5 * norm(A * x - b)^2
g(x) = 0.2 * norm(x, 1)
F(A, b, x) = f(A, b, x) + g(x)
function main()
## Plotting in intermediate space
xmin, xmax = -1, 2
ymin, ymax = -0.5, 1.5
## Base plot
axisbounds = (; xmin, xmax, ymin, ymax)
axis = baseaxis(axisbounds)
## Plot smooth function f
axisf = copy(axis)
add_segment!(axisf, [[0, ymin], [0, ymax]]; color = "black")
add_segment!(axisf, [[xmin, 0], [xmax, 0]]; color = "black")
add_contour!(axisf, x -> f(A, b, x), axisbounds; levels = 0.1:0.1:1.0)
savefig(axisf, "./Lasso_f")
## Plot nonsmooth function F
axisF = copy(axis)
add_contour!(axisF, x -> F(A, b, x), axisbounds; levels = [ 0.2, 0.28, 0.4, 0.55, 0.67, 0.79, 0.91, 1.0, 1.16, 1.28, 1.40])
add_segment!(axisF, [[0, ymin], [0, ymax]])
add_text!(axisF, [1.8, 0.2], raw"$\mathcal M_1$"; color = "chartreuse")
add_segment!(axisF, [[xmin, 0], [xmax, 0]])
add_text!(axisF, [0.2, 1.3], raw"$\mathcal M_2$"; color = "chartreuse")
savefig(axisF, "./Lasso_F")
return
end
main()