1+ from math import sqrt
2+
13from PEPit import PEP
24from PEPit .functions import SmoothStronglyConvexFunction
3- import numpy as np
45
56
67def 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