Skip to content

Commit 1999ea0

Browse files
authored
Merge pull request #123 from PerformanceEstimation/fix/feature-fista
Small fix
2 parents 37fb579 + b3c6aba commit 1999ea0

2 files changed

Lines changed: 23 additions & 20 deletions

File tree

PEPit/examples/composite_convex_minimization/accelerated_proximal_gradient.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
from math import sqrt
2+
13
from PEPit import PEP
24
from PEPit.functions import SmoothStronglyConvexFunction
35
from PEPit.functions import ConvexFunction
46
from PEPit.primitive_steps import proximal_step
57

6-
import numpy as np
78

89
def wc_accelerated_proximal_gradient(mu, L, n, wrapper="cvxpy", solver=None, verbose=1):
910
"""
@@ -32,14 +33,14 @@ def wc_accelerated_proximal_gradient(mu, L, n, wrapper="cvxpy", solver=None, ver
3233
.. math::
3334
3435
\\begin{eqnarray}
35-
\\text{Set: }\\lambda_{t+1} & = & \\frac{1}{2} \\left(1 + \\sqrt{4\\lambda_t^2 + 1}\\right)\\\\
36-
x_{t} & = & \\arg\\min_x \\left\\{h(x)+\\frac{L}{2}\|x-\\left(y_{t} - \\frac{1}{L} \\nabla f(y_t)\\right)\\|^2 \\right\\}\\\\
37-
y_{t+1} & = & x_{t} + \\frac{\\lambda_t-1}{\\lambda_{t+1}} (x_t-x_{t-1}).
36+
\\text{Set: }\\lambda_{t+1} & = & \\frac{1 + \\sqrt{4\\lambda_t^2 + 1}}{2}\\\\
37+
x_t & = & \\arg\\min_x \\left\\{h(x)+\\frac{L}{2}\|x-\\left(y_t - \\frac{1}{L} \\nabla f(y_t)\\right)\\|^2 \\right\\}\\\\
38+
y_{t+1} & = & x_t + \\frac{\\lambda_t-1}{\\lambda_{t+1}} (x_t-x_{t-1}).
3839
\\end{eqnarray}
3940
4041
**Theoretical guarantee**: The following worst-case guarantee can be found in e.g., [1, Theorem 4.4]:
4142
42-
.. math:: f(x_n)-f_\\star \\leqslant \\frac{L\\|x_0-x_\\star\\|^2}{\\lambda_n^2}.
43+
.. math:: f(x_n)-f_\\star \\leqslant \\frac{L}{2}\\frac{\\|x_0-x_\\star\\|^2}{\\lambda_n^2}.
4344
4445
**References**:
4546
@@ -120,21 +121,21 @@ def wc_accelerated_proximal_gradient(mu, L, n, wrapper="cvxpy", solver=None, ver
120121
lam = 1
121122
for i in range(n):
122123
lam_old = lam
123-
lam = (1 + np.sqrt(4 * lam_old ** 2 + 1)) / 2
124+
lam = (1 + sqrt(4 * lam_old ** 2 + 1)) / 2
124125
x_old = x_new
125126
x_new, _, hx_new = proximal_step(y - 1 / L * f.gradient(y), h, 1 / L)
126-
y = x_new + (lam_old - 1) / lam * (x_new - x_old)
127+
y = x_new + (lam_old - 1) / lam * (x_new - x_old)
127128

128-
# Set the performance metric to the function value accuracy
129+
# Set the performance metric to the function value accuracy
129130
problem.set_performance_metric((f(x_new) + hx_new) - Fs)
130131

131132
# Solve the PEP
132133
pepit_verbose = max(verbose, 0)
133134
pepit_tau = problem.solve(wrapper=wrapper, solver=solver, verbose=pepit_verbose)
134135

135136
# Theoretical guarantee (for comparison)
136-
theoretical_tau = L / 2 / lam_old**2
137-
137+
theoretical_tau = L / (2 * lam_old ** 2)
138+
138139
if mu != 0:
139140
print('Warning: momentum is tuned for non-strongly convex functions.')
140141

PEPit/examples/unconstrained_convex_minimization/accelerated_gradient_convex.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from math import sqrt
2+
13
from PEPit import PEP
24
from PEPit.functions import SmoothStronglyConvexFunction
3-
import numpy as np
45

56

67
def wc_accelerated_gradient_convex(mu, L, n, wrapper="cvxpy", solver=None, verbose=1):
@@ -22,19 +23,20 @@ def wc_accelerated_gradient_convex(mu, L, n, wrapper="cvxpy", solver=None, verbo
2223
:math:`\\tau(n, L, \\mu)` is computed as the worst-case value of
2324
:math:`f(x_n)-f_\\star` when :math:`\\|x_0 - x_\\star\\|^2 \\leqslant 1`.
2425
25-
**Algorithm**: Initialize :math:`\\lambda_1=1`, :math:`y_1=x_0`. One iteration of accelerated gradient method is described by
26+
**Algorithm**: Initialize :math:`\\lambda_1=1`, :math:`y_1=x_0`.
27+
One iteration of accelerated gradient method is described by
2628
2729
.. math::
2830
2931
\\begin{eqnarray}
30-
\\text{Set: }\\lambda_{t+1} & = & \\frac{1}{2} \\left(1 + \\sqrt{4\\lambda_t^2 + 1}\\right)\\\\
32+
\\text{Set: }\\lambda_{t+1} & = & \\frac{1 + \\sqrt{4\\lambda_t^2 + 1}}{2} \\\\
3133
x_{t} & = & y_t - \\frac{1}{L} \\nabla f(y_t),\\\\
3234
y_{t+1} & = & x_{t} + \\frac{\\lambda_t-1}{\\lambda_{t+1}} (x_t-x_{t-1}).
3335
\\end{eqnarray}
3436
3537
**Theoretical guarantee**: The following worst-case guarantee can be found in e.g., [2, Theorem 4.4]:
3638
37-
.. math:: f(x_n)-f_\\star \\leqslant \\frac{L\\|x_0-x_\\star\\|^2}{\\lambda_n^2}.
39+
.. math:: f(x_n)-f_\\star \\leqslant \\frac{L}{2}\\frac{\\|x_0-x_\\star\\|^2}{\\lambda_n^2}.
3840
3941
**References**:
4042
@@ -114,11 +116,11 @@ def wc_accelerated_gradient_convex(mu, L, n, wrapper="cvxpy", solver=None, verbo
114116
lam = 1
115117

116118
for _ in range(n):
117-
lam_old = lam
118-
lam = (1 + np.sqrt(4 * lam_old ** 2 + 1)) / 2
119-
x_old = x
120-
x = y - 1 / L * func.gradient(y)
121-
y = x + (lam_old - 1) / lam * (x - x_old)
119+
lam_old = lam
120+
lam = (1 + sqrt(4 * lam_old ** 2 + 1)) / 2
121+
x_old = x
122+
x = y - 1 / L * func.gradient(y)
123+
y = x + (lam_old - 1) / lam * (x - x_old)
122124

123125
# Set the performance metric to the function value accuracy
124126
problem.set_performance_metric(func(x) - fs)
@@ -128,7 +130,7 @@ def wc_accelerated_gradient_convex(mu, L, n, wrapper="cvxpy", solver=None, verbo
128130
pepit_tau = problem.solve(wrapper=wrapper, solver=solver, verbose=pepit_verbose)
129131

130132
# Theoretical guarantee (for comparison)
131-
theoretical_tau = L / 2 / lam_old**2
133+
theoretical_tau = L / (2 * lam_old**2)
132134

133135
if mu != 0:
134136
print('Warning: momentum is tuned for non-strongly convex functions.')

0 commit comments

Comments
 (0)