22from PEPit .functions import BlockConvexConcaveFunction
33from PEPit .point import Point
44from PEPit .expression import Expression
5-
5+ import numpy as np
66
77def wc_proximal_point (gamma , n , wrapper = "cvxpy" , solver = None , verbose = 1 ):
88 """
@@ -100,7 +100,6 @@ def wc_proximal_point(gamma, n, wrapper="cvxpy", solver=None, verbose=1):
100100 func = problem .declare_function (function_class = BlockConvexConcaveFunction , partition = block_partition )
101101 # Start by defining its unique optimal point xs = x_* and corresponding function value fs = f_*
102102 zs = func .stationary_point ()
103- fs = func (zs )
104103
105104 # Then define the starting point x0 of the algorithm
106105 z0 = problem .set_initial_point ()
@@ -110,42 +109,42 @@ def wc_proximal_point(gamma, n, wrapper="cvxpy", solver=None, verbose=1):
110109
111110 # Run n steps of the proximal point method
112111 z = z0
113- z_avg = z
114- count = 1
112+ z_prev = z
113+
115114 for _ in range (n ):
116115
117116
118117 # Compute x from the docstring equation.
119118 gz = Point ()
120119 fz = Expression ()
120+ z_prev = z
121121 z = z - gamma * block_partition .get_block (gz , 0 )
122122 z = z + gamma * block_partition .get_block (gz , 1 )
123- z_avg += z
124- count += 1
123+
125124 # Add point to Function f.
126125 func .add_point ((z , gz , fz ))
127126
128- z_avg /= count
129- #func.add_point((z_avg, func.gradient(z_avg), func(z_avg)))
127+
130128 # Set the performance metric to the final distance to optimum in function values
131- problem .set_performance_metric (func ( z_avg ) - fs )
129+ problem .set_performance_metric (( z - z_prev ) ** 2 )
132130
133131 # Solve the PEP
134132 pepit_verbose = max (verbose , 0 )
135133 pepit_tau = problem .solve (wrapper = wrapper , solver = solver , verbose = pepit_verbose )
136134
137135 # Compute theoretical guarantee (for comparison)
138- theoretical_tau = 1 / (gamma * n )
136+ #theoretical_tau = 1 / (gamma * n)
137+ theoretical_tau = np .power ((1.0 - (1.0 / n )), n - 1 )/ n
139138
140139 # Print conclusion if required
141140 if verbose != - 1 :
142141 print ('*** Example file: worst-case performance of proximal point method ***' )
143- print ('\t PEPit guarantee:\t f(z_avg)-f_* <= {:.6} ||z_0 - z_*||^2' .format (pepit_tau ))
144- print ('\t Theoretical guarantee:\t f(z_avg)-f_* <= {:.6} ||z_0 - z_*||^2' .format (theoretical_tau ))
142+ print ('\t PEPit guarantee:\t ||z_n - z_n-1||^2 <= {:.6} ||z_0 - z_*||^2' .format (pepit_tau ))
143+ print ('\t Theoretical guarantee:\t ||z_n - z_n-1||^2 <= {:.6} ||z_0 - z_*||^2' .format (theoretical_tau ))
145144
146145 # Return the worst-case guarantee of the evaluated method (and the reference theoretical value)
147146 return pepit_tau , theoretical_tau
148147
149148
150149if __name__ == "__main__" :
151- pepit_tau , theoretical_tau = wc_proximal_point (gamma = 0. 2 , n = 10 , wrapper = "cvxpy" , solver = None , verbose = 1 )
150+ pepit_tau , theoretical_tau = wc_proximal_point (gamma = 2 , n = 5 , wrapper = "cvxpy" , solver = None , verbose = 1 )
0 commit comments