Skip to content

Commit 741899f

Browse files
committed
Rename unconstrained_convex_optimizationto unconstrained_convex_minimization
1 parent 50067ae commit 741899f

30 files changed

Lines changed: 1565 additions & 6 deletions
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using PEPit, OrderedCollections, Mosek, MosekTools
2+
3+
function wc_accelerated_gradient_convex(mu, L, n; solver=Mosek.Optimizer, verbose=true)
4+
5+
problem = PEP()
6+
7+
8+
param = OrderedDict("mu" => mu, "L" => L)
9+
func = declare_function!(problem, SmoothStronglyConvexFunction, param)
10+
11+
12+
xs = stationary_point!(func)
13+
fs = value!(func, xs)
14+
15+
16+
x0 = set_initial_point!(problem)
17+
18+
19+
set_initial_condition!(problem, (x0 - xs)^2 <= 1)
20+
21+
22+
x = x0
23+
y = x0
24+
lam = 1.0
25+
lam_old = lam
26+
27+
for _ in 1:n
28+
lam_old = lam
29+
lam = (1 + sqrt(4 * lam_old^2 + 1)) / 2
30+
x_old = x
31+
x = y - 1 / L * gradient!(func, y)
32+
y = x + (lam_old - 1) / lam * (x - x_old)
33+
end
34+
35+
36+
set_performance_metric!(problem, value!(func, x) - fs)
37+
38+
39+
pepit_tau = solve!(problem; solver=solver, verbose=verbose)
40+
41+
42+
theoretical_tau = L / (2 * lam_old^2)
43+
44+
mu != 0 && @warn "Momentum is tuned for non-strongly convex functions."
45+
46+
47+
if verbose
48+
println("*** Example file: worst-case performance of accelerated gradient method ***")
49+
println("\tPEPit guarantee:\t f(x_n)-f_* <= $(round(pepit_tau, digits=6)) ||x_0 - x_*||^2")
50+
println("\tTheoretical guarantee:\t f(x_n)-f_* <= $(round(theoretical_tau, digits=6)) ||x_0 - x_*||^2")
51+
end
52+
53+
54+
return pepit_tau, theoretical_tau
55+
end
56+
57+
pepit_tau, theoretical_tau = wc_accelerated_gradient_convex(0, 1, 1; solver=Mosek.Optimizer, verbose=true)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using PEPit, OrderedCollections, Mosek, MosekTools
2+
3+
function wc_accelerated_gradient_convex_simplified(mu, L, n; solver=Mosek.Optimizer, verbose=true)
4+
5+
problem = PEP()
6+
7+
8+
param = OrderedDict("mu" => mu, "L" => L)
9+
func = declare_function!(problem, SmoothStronglyConvexFunction, param)
10+
11+
12+
xs = stationary_point!(func)
13+
fs = value!(func, xs)
14+
15+
16+
x0 = set_initial_point!(problem)
17+
18+
19+
set_initial_condition!(problem, (x0 - xs)^2 <= 1)
20+
21+
22+
x_new = x0
23+
y = x0
24+
for i in 1:n
25+
ipy = i - 1
26+
x_old = x_new
27+
x_new = y - 1 / L * gradient!(func, y)
28+
y = x_new + ipy / (ipy + 3) * (x_new - x_old)
29+
end
30+
31+
32+
set_performance_metric!(problem, value!(func, x_new) - fs)
33+
34+
35+
pepit_tau = solve!(problem; solver=solver, verbose=verbose)
36+
37+
38+
theoretical_tau = 2 * L / (n^2 + 5 * n + 6)
39+
mu != 0 && @warn "Momentum is tuned for non-strongly convex functions."
40+
41+
42+
if verbose
43+
println("*** Example file: worst-case performance of accelerated gradient method ***")
44+
println("\tPEPit guarantee:\t f(x_n)-f_* <= $(round(pepit_tau, digits=6)) ||x_0 - x_*||^2")
45+
println("\tTheoretical guarantee:\t f(x_n)-f_* <= $(round(theoretical_tau, digits=6)) ||x_0 - x_*||^2")
46+
end
47+
48+
49+
return pepit_tau, theoretical_tau
50+
end
51+
52+
pepit_tau, theoretical_tau = wc_accelerated_gradient_convex_simplified(0, 1, 1; solver=Mosek.Optimizer, verbose=true)

examples/unconstrained_convex_optimization/accelerated_gradient_strongly_convex.jl renamed to examples/unconstrained_convex_minimization/accelerated_gradient_strongly_convex.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function wc_accelerated_gradient_strongly_convex(mu, L, n; verbose=false)
2828
mu == 0 && @warn "Momentum is tuned for strongly convex functions!"
2929

3030
if verbose
31-
@info "🐱 Example file: worst-case performance of the accelerated gradient method"
31+
@info "🐱 Example file: worst-case performance of the accelerated gradient method"
3232
@info "💻 PEPit guarantee: f(x_n)-f_* <= $(round(PEPit_tau, digits=6)) (f(x_0) - f(x_*) + mu/2*||x_0 - x_*||^2)"
3333
@info "📝 Theoretical guarantee: f(x_n)-f_* <= $(round(theoretical_tau, digits=6)) (f(x_0) - f(x_*) + mu/2*||x_0 - x_*||^2)"
3434
end
@@ -50,4 +50,3 @@ function wc_accelerated_gradient_strongly_convex(mu, L, n; verbose=false)
5050
end
5151

5252
PEPit_val, theoretical_val = wc_accelerated_gradient_strongly_convex(0.1, 1.0, 2, verbose=true)
53-
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using PEPit, OrderedCollections, Mosek, MosekTools
2+
3+
function wc_accelerated_proximal_point(A0, gammas, n; solver=Mosek.Optimizer, verbose=true)
4+
5+
problem = PEP()
6+
7+
8+
func = declare_function!(problem, ConvexFunction, OrderedDict())
9+
10+
11+
xs = stationary_point!(func)
12+
fs = value!(func, xs)
13+
14+
15+
x0 = set_initial_point!(problem)
16+
17+
18+
set_initial_condition!(problem, value!(func, x0) - fs + A0 / 2 * (x0 - xs)^2 <= 1)
19+
20+
21+
x, v = x0, x0
22+
A = A0
23+
for i in 1:n
24+
alpha = (sqrt((A * gammas[i])^2 + 4 * A * gammas[i]) - A * gammas[i]) / 2
25+
y = (1 - alpha) * x + alpha * v
26+
x, _, _ = proximal_step!(y, func, gammas[i])
27+
v = v + 1 / alpha * (x - y)
28+
A = (1 - alpha) * A
29+
end
30+
31+
32+
set_performance_metric!(problem, value!(func, x) - fs)
33+
34+
35+
pepit_tau = solve!(problem; solver=solver, verbose=verbose)
36+
37+
38+
accumulation = 0.0
39+
for i in 1:n
40+
accumulation += sqrt(gammas[i])
41+
end
42+
theoretical_tau = 4 / A0 / accumulation^2
43+
44+
45+
if verbose
46+
println("*** Example file: worst-case performance of fast proximal point method ***")
47+
println("\tPEPit guarantee:\t f(x_n)-f_* <= $(round(pepit_tau, digits=6)) (f(x_0) - f_* + A/2* ||x_0 - x_*||^2)")
48+
println("\tTheoretical guarantee:\t f(x_n)-f_* <= $(round(theoretical_tau, digits=6)) (f(x_0) - f_* + A/2* ||x_0 - x_*||^2)")
49+
end
50+
51+
52+
return pepit_tau, theoretical_tau
53+
end
54+
55+
56+
pepit_tau, theoretical_tau = wc_accelerated_proximal_point(5, [(i + 1) / 1.1 for i in 0:2], 3; solver=Mosek.Optimizer, verbose=true)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using PEPit, OrderedCollections, Mosek, MosekTools
2+
3+
function wc_conjugate_gradient(L, n; solver=Mosek.Optimizer, verbose=true)
4+
5+
problem = PEP()
6+
7+
8+
param = OrderedDict("L" => L)
9+
func = declare_function!(problem, SmoothConvexFunction, param)
10+
11+
12+
xs = stationary_point!(func)
13+
fs = value!(func, xs)
14+
15+
16+
x0 = set_initial_point!(problem)
17+
18+
19+
set_initial_condition!(problem, (x0 - xs)^2 <= 1)
20+
21+
22+
x_new = x0
23+
g0, f0 = oracle!(func, x0)
24+
span = Any[g0]
25+
local gx, fx
26+
for i in 1:n
27+
x_old = x_new
28+
x_new, gx, fx = exact_linesearch_step!(x_new, func, span)
29+
push!(span, gx)
30+
push!(span, x_old - x_new)
31+
end
32+
33+
34+
set_performance_metric!(problem, fx - fs)
35+
36+
37+
pepit_tau = solve!(problem; solver=solver, verbose=verbose)
38+
39+
40+
theta_new = 1.0
41+
for i in 0:(n - 1)
42+
if i < n - 1
43+
theta_new = (1 + sqrt(4 * theta_new^2 + 1)) / 2
44+
else
45+
theta_new = (1 + sqrt(8 * theta_new^2 + 1)) / 2
46+
end
47+
end
48+
theoretical_tau = L / (2 * theta_new^2)
49+
50+
if verbose
51+
println("*** Example file: worst-case performance of conjugate gradient method ***")
52+
println("\tPEPit guarantee:\t f(x_n)-f_* <= $(round(pepit_tau, digits=6)) ||x_0 - x_*||^2")
53+
println("\tTheoretical guarantee:\t f(x_n)-f_* <= $(round(theoretical_tau, digits=6)) ||x_0 - x_*||^2")
54+
end
55+
56+
return pepit_tau, theoretical_tau
57+
end
58+
59+
pepit_tau, theoretical_tau = wc_conjugate_gradient(1.0, 2; solver=Mosek.Optimizer, verbose=true)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using PEPit, OrderedCollections, Mosek, MosekTools
2+
3+
function wc_conjugate_gradient_qg_convex(L, n; solver=Mosek.Optimizer, verbose=true)
4+
5+
problem = PEP()
6+
7+
8+
func = declare_function!(problem, ConvexQGFunction, OrderedDict("L" => L))
9+
10+
11+
xs = stationary_point!(func)
12+
fs = value!(func, xs)
13+
14+
15+
x0 = set_initial_point!(problem)
16+
17+
18+
set_initial_condition!(problem, (x0 - xs)^2 <= 1)
19+
20+
21+
x_new = x0
22+
g0, f0 = oracle!(func, x0)
23+
span = [g0]
24+
local gx, fx
25+
for i in 1:n
26+
x_old = x_new
27+
x_new, gx, fx = exact_linesearch_step!(x_new, func, span)
28+
push!(span, gx)
29+
push!(span, x_old - x_new)
30+
end
31+
32+
33+
set_performance_metric!(problem, fx - fs)
34+
35+
36+
pepit_tau = solve!(problem; solver=solver, verbose=verbose)
37+
38+
39+
theoretical_tau = L / (2 * (n + 1))
40+
41+
if verbose
42+
println("*** Example file: worst-case performance of conjugate gradient method ***")
43+
println("\tPEPit guarantee:\t f(x_n)-f_* <= $(round(pepit_tau, digits=6)) ||x_0 - x_*||^2")
44+
println("\tTheoretical guarantee:\t f(x_n)-f_* <= $(round(theoretical_tau, digits=6)) ||x_0 - x_*||^2")
45+
end
46+
47+
48+
return pepit_tau, theoretical_tau
49+
end
50+
51+
pepit_tau, theoretical_tau = wc_conjugate_gradient_qg_convex(1.0, 12; solver=Mosek.Optimizer, verbose=true)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using PEPit, OrderedCollections, Mosek, MosekTools
2+
3+
function wc_cyclic_coordinate_descent(L, n; solver=Mosek.Optimizer, verbose=true)
4+
5+
problem = PEP()
6+
7+
8+
d = length(L)
9+
partition = declare_block_partition!(problem, d)
10+
11+
12+
param = OrderedDict("partition" => partition, "L" => L)
13+
func = declare_function!(problem, BlockSmoothConvexFunctionCheap, param)
14+
15+
16+
xs = stationary_point!(func)
17+
fs = value!(func, xs)
18+
19+
20+
x0 = set_initial_point!(problem)
21+
22+
23+
set_initial_condition!(problem, (x0 - xs)^2 <= 1)
24+
25+
26+
x = x0
27+
for k in 0:(n - 1)
28+
i = k % d
29+
x = x - 1 / L[i + 1] * get_block(partition, gradient!(func, x), i + 1)
30+
end
31+
32+
33+
set_performance_metric!(problem, value!(func, x) - fs)
34+
35+
36+
pepit_tau = solve!(problem; solver=solver, verbose=verbose)
37+
38+
39+
theoretical_tau = nothing
40+
41+
if verbose
42+
println("*** Example file: worst-case performance of cyclic coordinate descent with fixed step-sizes ***")
43+
println("\tPEPit guarantee:\t f(x_n)-f_* <= $(round(pepit_tau, digits=6)) ||x_0 - x_*||^2")
44+
end
45+
46+
return pepit_tau, theoretical_tau
47+
end
48+
49+
50+
L = [1.0, 2.0, 10.0]
51+
pepit_tau, theoretical_tau = wc_cyclic_coordinate_descent(L, 9; solver=Mosek.Optimizer, verbose=true)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using PEPit, OrderedCollections, Mosek, MosekTools
2+
3+
function wc_epsilon_subgradient_method(M, n, gamma, eps, R; solver=Mosek.Optimizer, verbose=true)
4+
5+
problem = PEP()
6+
7+
8+
func = declare_function!(problem, ConvexFunction, OrderedDict())
9+
10+
11+
xs = stationary_point!(func)
12+
fs = value!(func, xs)
13+
14+
15+
x0 = set_initial_point!(problem)
16+
17+
18+
set_initial_condition!(problem, (x0 - xs)^2 <= R^2)
19+
20+
21+
x = x0
22+
for _ in 1:n
23+
x, gx, fx, epsilon = epsilon_subgradient_step!(x, func, gamma)
24+
set_performance_metric!(problem, fx - fs)
25+
add_constraint!(problem, epsilon <= eps)
26+
add_constraint!(problem, gx^2 <= M^2)
27+
end
28+
29+
30+
gx, fx = oracle!(func, x)
31+
add_constraint!(problem, gx^2 <= M^2)
32+
set_performance_metric!(problem, fx - fs)
33+
34+
35+
pepit_tau = solve!(problem; solver=solver, verbose=verbose)
36+
37+
38+
theoretical_tau = (R^2 + 2 * (n + 1) * gamma * eps + (n + 1) * gamma^2 * M^2) / (2 * (n + 1) * gamma)
39+
40+
if verbose
41+
println("*** Example file: worst-case performance of the epsilon-subgradient method ***")
42+
println("\tPEPit guarantee:\t min_(0 <= t <= n) f(x_i) - f_* <= $(round(pepit_tau, digits=6))")
43+
println("\tTheoretical guarantee:\t min_(0 <= t <= n) f(x_i) - f_* <= $(round(theoretical_tau, digits=6))")
44+
end
45+
46+
47+
return pepit_tau, theoretical_tau
48+
end
49+
50+
51+
M, n, eps, R = 2, 6, 0.1, 1
52+
gamma = 1 / sqrt(n + 1)
53+
pepit_tau, theoretical_tau = wc_epsilon_subgradient_method(M, n, gamma, eps, R; verbose=true)

0 commit comments

Comments
 (0)