-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest_examples.py
704 lines (525 loc) · 33.7 KB
/
test_examples.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
import unittest
import numpy as np
from PEPit.examples.unconstrained_convex_minimization import wc_conjugate_gradient
from PEPit.examples.unconstrained_convex_minimization import wc_conjugate_gradient_qg_convex
from PEPit.examples.unconstrained_convex_minimization import wc_gradient_descent
from PEPit.examples.unconstrained_convex_minimization import wc_gradient_descent_lc
from PEPit.examples.unconstrained_convex_minimization import wc_gradient_descent_qg_convex
from PEPit.examples.unconstrained_convex_minimization import wc_gradient_descent_qg_convex_decreasing
from PEPit.examples.unconstrained_convex_minimization import wc_gradient_descent_quadratics
from PEPit.examples.unconstrained_convex_minimization import wc_gradient_descent_silver_stepsize_convex
from PEPit.examples.unconstrained_convex_minimization import wc_gradient_descent_silver_stepsize_strongly_convex
from PEPit.examples.unconstrained_convex_minimization import wc_subgradient_method_rsi_eb
from PEPit.examples.unconstrained_convex_minimization import wc_accelerated_gradient_convex
from PEPit.examples.unconstrained_convex_minimization import wc_accelerated_gradient_strongly_convex
from PEPit.examples.unconstrained_convex_minimization import wc_accelerated_proximal_point
from PEPit.examples.unconstrained_convex_minimization import wc_proximal_point
from PEPit.examples.unconstrained_convex_minimization import wc_gradient_exact_line_search
from PEPit.examples.unconstrained_convex_minimization import wc_heavy_ball_momentum
from PEPit.examples.unconstrained_convex_minimization import wc_heavy_ball_momentum_qg_convex
from PEPit.examples.unconstrained_convex_minimization import wc_inexact_accelerated_gradient
from PEPit.examples.unconstrained_convex_minimization import wc_inexact_gradient_descent
from PEPit.examples.unconstrained_convex_minimization import wc_inexact_gradient_exact_line_search
from PEPit.examples.unconstrained_convex_minimization import wc_optimized_gradient
from PEPit.examples.unconstrained_convex_minimization import wc_robust_momentum
from PEPit.examples.unconstrained_convex_minimization import wc_subgradient_method
from PEPit.examples.unconstrained_convex_minimization import wc_triple_momentum
from PEPit.examples.unconstrained_convex_minimization import wc_information_theoretic
from PEPit.examples.unconstrained_convex_minimization import wc_optimized_gradient_for_gradient
from PEPit.examples.unconstrained_convex_minimization import wc_epsilon_subgradient_method
from PEPit.examples.unconstrained_convex_minimization import wc_cyclic_coordinate_descent
from PEPit.examples.composite_convex_minimization import wc_accelerated_douglas_rachford_splitting
from PEPit.examples.composite_convex_minimization import wc_accelerated_proximal_gradient
from PEPit.examples.composite_convex_minimization import wc_bregman_proximal_point
from PEPit.examples.composite_convex_minimization import wc_frank_wolfe
from PEPit.examples.composite_convex_minimization import wc_douglas_rachford_splitting
from PEPit.examples.composite_convex_minimization import wc_douglas_rachford_splitting_contraction
from PEPit.examples.composite_convex_minimization import wc_improved_interior_algorithm
from PEPit.examples.composite_convex_minimization import wc_no_lips_in_bregman_divergence
from PEPit.examples.composite_convex_minimization import wc_no_lips_in_function_value
from PEPit.examples.composite_convex_minimization import wc_proximal_gradient
from PEPit.examples.composite_convex_minimization import wc_proximal_gradient_quadratics
from PEPit.examples.composite_convex_minimization import wc_three_operator_splitting
from PEPit.examples.nonconvex_optimization import wc_gradient_descent as wc_gradient_descent_non_convex
from PEPit.examples.nonconvex_optimization import wc_no_lips_1
from PEPit.examples.nonconvex_optimization import wc_no_lips_2
from PEPit.examples.stochastic_and_randomized_convex_minimization import wc_saga
from PEPit.examples.stochastic_and_randomized_convex_minimization import wc_sgd_overparametrized
from PEPit.examples.stochastic_and_randomized_convex_minimization import wc_sgd
from PEPit.examples.stochastic_and_randomized_convex_minimization import wc_point_saga
from PEPit.examples.stochastic_and_randomized_convex_minimization import \
wc_randomized_coordinate_descent_smooth_strongly_convex
from PEPit.examples.stochastic_and_randomized_convex_minimization import wc_randomized_coordinate_descent_smooth_convex
from PEPit.examples.monotone_inclusions_variational_inequalities import \
wc_accelerated_proximal_point as wc_accelerated_proximal_point_operators
from PEPit.examples.monotone_inclusions_variational_inequalities import \
wc_douglas_rachford_splitting as wc_douglas_rachford_splitting_operators
from PEPit.examples.monotone_inclusions_variational_inequalities import \
wc_douglas_rachford_splitting_2 as wc_douglas_rachford_splitting_operators_2
from PEPit.examples.monotone_inclusions_variational_inequalities import wc_optimal_strongly_monotone_proximal_point as \
wc_optimal_strongly_monotone_proximal_point_operators
from PEPit.examples.monotone_inclusions_variational_inequalities import \
wc_proximal_point as wc_proximal_point_method_operators
from PEPit.examples.monotone_inclusions_variational_inequalities import \
wc_three_operator_splitting as wc_three_operator_splitting_operators
from PEPit.examples.monotone_inclusions_variational_inequalities import \
wc_optimistic_gradient as wc_optimistic_gradient_operators
from PEPit.examples.monotone_inclusions_variational_inequalities import \
wc_past_extragradient as wc_past_extragradient_operators
from PEPit.examples.fixed_point_problems import wc_halpern_iteration
from PEPit.examples.fixed_point_problems import wc_krasnoselskii_mann_constant_step_sizes
from PEPit.examples.fixed_point_problems import wc_krasnoselskii_mann_increasing_step_sizes
from PEPit.examples.fixed_point_problems import wc_inconsistent_halpern_iteration
from PEPit.examples.fixed_point_problems import wc_optimal_contractive_halpern_iteration
from PEPit.examples.potential_functions import wc_accelerated_gradient_method
from PEPit.examples.potential_functions import wc_gradient_descent_lyapunov_1
from PEPit.examples.potential_functions import wc_gradient_descent_lyapunov_2
from PEPit.examples.adaptive_methods import wc_polyak_steps_in_distance_to_optimum
from PEPit.examples.adaptive_methods import wc_polyak_steps_in_function_value
from PEPit.examples.low_dimensional_worst_cases_scenarios import wc_inexact_gradient as wc_inexact_gradient_low_dim
from PEPit.examples.low_dimensional_worst_cases_scenarios import wc_optimized_gradient as wc_optimized_gradient_low_dim
from PEPit.examples.low_dimensional_worst_cases_scenarios import wc_frank_wolfe as wc_frank_wolfe_low_dim
from PEPit.examples.low_dimensional_worst_cases_scenarios import wc_proximal_point as wc_proximal_point_low_dim
from PEPit.examples.low_dimensional_worst_cases_scenarios import wc_halpern_iteration as wc_halpern_iteration_low_dim
from PEPit.examples.low_dimensional_worst_cases_scenarios import \
wc_gradient_descent as wc_gradient_descent_non_convex_low_dim
from PEPit.examples.low_dimensional_worst_cases_scenarios import \
wc_alternate_projections as wc_alternate_projections_low_dim
from PEPit.examples.low_dimensional_worst_cases_scenarios import \
wc_averaged_projections as wc_averaged_projections_low_dim
from PEPit.examples.low_dimensional_worst_cases_scenarios import wc_dykstra as wc_dykstra_low_dim
from PEPit.examples.inexact_proximal_methods import wc_accelerated_inexact_forward_backward
from PEPit.examples.inexact_proximal_methods import wc_partially_inexact_douglas_rachford_splitting
from PEPit.examples.inexact_proximal_methods import wc_relatively_inexact_proximal_point_algorithm
from PEPit.examples.continuous_time_models import wc_accelerated_gradient_flow_convex
from PEPit.examples.continuous_time_models import wc_gradient_flow_convex
from PEPit.examples.continuous_time_models import wc_accelerated_gradient_flow_strongly_convex
from PEPit.examples.continuous_time_models import wc_gradient_flow_strongly_convex
from PEPit.examples.tutorials import wc_gradient_descent_contraction
class TestExamplesCVXPY(unittest.TestCase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.wrapper = "cvxpy"
def setUp(self):
self.n = 6
self.mu = .1
self.L = 1
self.verbose = -1
self.relative_precision = 10 ** -3
self.absolute_precision = 5 * 10 ** -5
def test_optimized_gradient(self):
L, n = 3, 4
wc, theory = wc_optimized_gradient(L, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_optimized_gradient_for_gradient(self):
L, n = 3, 4
wc, theory = wc_optimized_gradient_for_gradient(L, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_epsilon_subgradient_method(self):
M, n, eps, R = 2, 6, 2, 1
gamma = 1 / (np.sqrt(n + 1))
wc, theory = wc_epsilon_subgradient_method(M=M, n=n, gamma=gamma, eps=eps, R=R, wrapper=self.wrapper, verbose=self.verbose)
self.assertLessEqual(wc, theory)
def test_information_theoretic(self):
mu, L, n = .01, 3, 3
wc, theory = wc_information_theoretic(mu=mu, L=L, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_gradient_descent(self):
L, n = 3, 4
gamma = 1 / L
wc, theory = wc_gradient_descent(L=L, gamma=gamma, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_gradient_descent_lc(self):
Lg, mug = 3, .3
LM, muM = 1., 0.1
gamma, n = 1 / (Lg * LM ** 2), 3
for typeM in ["gen", "sym", "skew"]:
wc, theory = wc_gradient_descent_lc(mug=mug, Lg=Lg,
typeM=typeM, muM=muM, LM=LM,
gamma=gamma, n=n,
verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=2*self.relative_precision * theory)
def test_gradient_descent_quadratics(self):
L, mu, n = 3, .3, 4
gamma = 1/L
wc, theory = wc_gradient_descent_quadratics(mu=mu, L=L, gamma=gamma, n=n,
wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_gradient_descent_silver_stepsize_convex(self):
L, n = 2.8, 2
wc, theory = wc_gradient_descent_silver_stepsize_convex(L=L, n=n,
verbose=self.verbose)
self.assertLessEqual(wc, theory)
def test_gradient_descent_silver_stepsize_strongly_convex(self):
L, mu, n = 3.2, .1, 17
wc, theory = wc_gradient_descent_silver_stepsize_strongly_convex(L=L, mu=mu, n=n,
verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_cyclic_coordinate_descent_one_block(self):
n = 9
L = 1.
wc, _ = wc_cyclic_coordinate_descent(L=[L], n=n, wrapper=self.wrapper, verbose=self.verbose)
wc_GD, _ = wc_gradient_descent(L, 1 / L, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, wc_GD, delta=self.relative_precision * wc_GD)
def test_cyclic_coordinate_descent(self):
n = 9
L = [1., 2., 10.]
wc, _ = wc_cyclic_coordinate_descent(L=L, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, 1.48928, delta=self.relative_precision * 1.48928)
def test_gradient_descent_qg_convex(self):
L, n = 1, 4
gamma = .1 / L
wc, theory = wc_gradient_descent_qg_convex(L, gamma, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_gradient_descent_qg_convex_decreasing(self):
L, n = 1, 4
wc, theory = wc_gradient_descent_qg_convex_decreasing(L, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_gradient_exact_line_search(self):
L, mu, n = 3, .1, 1
wc, theory = wc_gradient_exact_line_search(L=L, mu=mu, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_subgradient_method(self):
M, n = 2, 10
gamma = 1 / (np.sqrt(n + 1) * M)
wc, theory = wc_subgradient_method(M=M, n=n, gamma=gamma, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_subgradient_method_rsi_eb(self):
mu = .1
L = 1
gamma = mu / L ** 2
n = 4
wc, theory = wc_subgradient_method_rsi_eb(mu=mu, L=L, gamma=gamma, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_conjugate_gradient(self):
L, n = 3, 2
wc, theory = wc_conjugate_gradient(L=L, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_conjugate_gradient_qg_convex(self):
L, n = 3.5, 12
wc, theory = wc_conjugate_gradient_qg_convex(L=L, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_inexact_gradient_exact_line_search(self):
L, mu, epsilon, n = 3, .1, .1, 2
wc, theory = wc_inexact_gradient_exact_line_search(L=L, mu=mu, epsilon=epsilon, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_inexact_gradient_descent(self):
L, mu, epsilon, n = 3, .1, .1, 2
wc, theory = wc_inexact_gradient_descent(L=L, mu=mu, epsilon=epsilon, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_proximal_point(self):
n, gamma = 3, .1
wc, theory = wc_proximal_point(gamma=gamma, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_optimized_gradient_method(self):
L, n = 3, 4
wc, theory = wc_optimized_gradient_low_dim(L, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_inexact_gradient(self):
L, mu, epsilon, n = 3, .1, .1, 2
wc, theory = wc_inexact_gradient_low_dim(L=L, mu=mu, epsilon=epsilon, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_frank_wolfe_low_dim(self):
D, L, n = 1., 1., 10
wc, theory = wc_frank_wolfe_low_dim(L, D, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertLessEqual(wc, theory)
def test_proximal_point_low_dim(self):
n, alpha = 11, 2.2
wc, theory = wc_proximal_point_low_dim(alpha=alpha, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_halpern_iteration_low_dim(self):
n = 15
wc, theory = wc_halpern_iteration_low_dim(n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=2*self.relative_precision * theory)
def test_gradient_descent_non_convex_low_dim(self):
L, n = 1, 5
gamma = 1 / L
wc, theory = wc_gradient_descent_non_convex_low_dim(L, gamma, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_alternate_projections_low_dim(self):
n1 = 9
n2 = 10
wc1, _ = wc_alternate_projections_low_dim(n1, wrapper=self.wrapper, verbose=self.verbose)
wc2, _ = wc_alternate_projections_low_dim(n2, wrapper=self.wrapper, verbose=self.verbose)
self.assertLessEqual(wc2, wc1)
def test_averaged_projections_low_dim(self):
n1 = 10
n2 = 11
wc1, _ = wc_averaged_projections_low_dim(n1, wrapper=self.wrapper, verbose=self.verbose)
wc2, _ = wc_averaged_projections_low_dim(n2, wrapper=self.wrapper, verbose=self.verbose)
self.assertLessEqual(wc2, wc1)
def test_dykstra_low_dim(self):
n1 = 8
n2 = 10
wc1, _ = wc_dykstra_low_dim(n1, wrapper=self.wrapper, verbose=self.verbose)
wc2, _ = wc_dykstra_low_dim(n2, wrapper=self.wrapper, verbose=self.verbose)
self.assertLessEqual(wc2, wc1)
def test_inexact_accelerated_gradient_1(self):
L, epsilon, n = 3, 0, 5
wc, theory = wc_inexact_accelerated_gradient(L=L, epsilon=epsilon, n=n, wrapper=self.wrapper, verbose=self.verbose)
# Less accurate requirement due to ill conditioning of this specific SDP (no Slater point)
local_relative_precision = 10 ** -2
self.assertAlmostEqual(theory, wc, delta=local_relative_precision * theory)
def test_inexact_accelerated_gradient_2(self):
L, epsilon, n = 2, .01, 5
wc, theory = wc_inexact_accelerated_gradient(L=L, epsilon=epsilon, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertLessEqual(theory, wc * (1 + self.relative_precision))
def test_inexact_accelerated_gradient_3(self):
L, epsilon, n = 2, .1, 5
wc, theory = wc_inexact_accelerated_gradient(L=L, epsilon=epsilon, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertLessEqual(theory, wc * (1 + self.relative_precision))
def test_heavy_ball_momentum(self):
L, mu, n = 1, .1, 3
alpha = 1 / (2 * L) # alpha \in [0, 1/L]
beta = np.sqrt((1 - alpha * mu) * (1 - L * alpha))
wc, theory = wc_heavy_ball_momentum(mu=mu, L=L, alpha=alpha, beta=beta, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertLessEqual(wc, theory * (1 + self.relative_precision))
def test_heavy_ball_momentum_qg_convex(self):
L, n = 1, 5
wc, theory = wc_heavy_ball_momentum_qg_convex(L=L, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertLessEqual(wc, theory * (1 + self.relative_precision))
def test_accelerated_proximal_point(self):
A0, n = 1, 3
gammas = [1, 1, 1]
wc, theory = wc_accelerated_proximal_point(A0=A0, gammas=gammas, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertLessEqual(wc, theory * (1 + self.relative_precision))
def test_triple_momentum(self):
L, mu, n = 1, .1, 4
# Compare theoretical rate in epsilon=0 case
wc, theory = wc_triple_momentum(mu=mu, L=L, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(theory, wc, delta=self.relative_precision * theory)
def test_robust_momentum(self):
L, mu, lam = 1, .1, .5
# Compare theoretical rate in epsilon=0 case
wc, theory = wc_robust_momentum(mu=mu, L=L, lam=lam, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(theory, wc, delta=self.relative_precision * theory)
def test_accelerated_gradient_convex(self):
mu, L, n = 0, 1, 10
wc, theory = wc_accelerated_gradient_convex(mu, L, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_accelerated_gradient_strongly_convex(self):
L, mu, n = 1, .1, 5
wc, theory = wc_accelerated_gradient_strongly_convex(mu=mu, L=L, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertLessEqual(wc, theory)
def test_accelerated_proximal_gradient_method(self):
mu, L, n = 0, 1, 5
wc, theory = wc_accelerated_proximal_gradient(mu, L, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_accelerated_douglas_rachford_splitting(self):
mu, L, alpha = 0.1, 1, 0.9
n_list = range(1, 9)
ref_pesto_bounds = [0.2027, 0.1929, 0.1839, 0.1737, 0.1627, 0.1514, 0.1400, 0.1289]
for n in n_list:
wc, _ = wc_accelerated_douglas_rachford_splitting(mu, L, alpha, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, ref_pesto_bounds[n - 1], delta=self.relative_precision * ref_pesto_bounds[n - 1])
def test_bregman_proximal_point_method(self):
gamma, n = 3, 5
wc, theory = wc_bregman_proximal_point(gamma=gamma, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_conditional_gradient_frank_wolfe(self):
D, L, n = 1., 1., 10
wc, theory = wc_frank_wolfe(L, D, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertLessEqual(wc, theory)
def test_douglas_rachford_splitting_contraction(self):
mu, L, alpha, theta, n = 0.1, 1, 3, 1, 1
wc, theory = wc_douglas_rachford_splitting_contraction(mu, L, alpha, theta, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_douglas_rachford_splitting(self):
L, alpha, theta, n = 1, 1, 1, 10
wc, theory = wc_douglas_rachford_splitting(L, alpha, theta, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_improved_interior_algorithm(self):
L, mu, c, n = 1, 1, 1, 5
lam = 1 / L
wc, theory = wc_improved_interior_algorithm(L, mu, c, lam, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertLessEqual(wc, theory)
def test_no_lips_in_bregman_divergence(self):
L, n = 0.1, 3
gamma = 1 / L
wc, theory = wc_no_lips_in_bregman_divergence(L, gamma, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_no_lips_in_function_value(self):
L, n = 1, 3
gamma = 1 / L / 2
wc, theory = wc_no_lips_in_function_value(L, gamma, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_proximal_gradient(self):
L, mu, gamma, n = 1, .1, 1, 2
wc, theory = wc_proximal_gradient(L=L, mu=mu, gamma=gamma, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_proximal_gradient_quadratics(self):
L, mu, gamma, n = 1, .1, 1, 2
wc, theory = wc_proximal_gradient_quadratics(L=L, mu=mu, gamma=gamma, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_three_operator_splitting(self):
mu, L1, L3, alpha, theta = 0.1, 10, 1, 1, 1
n_list = range(1, 4)
ref_pesto_bounds = [0.8304, 0.6895, 0.5726]
for n in n_list:
wc, _ = wc_three_operator_splitting(mu, L1, L3, alpha, theta, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, ref_pesto_bounds[n - 1], delta=self.relative_precision * ref_pesto_bounds[n - 1])
def test_gradient_descent_non_convex(self):
L, n = 1, 5
gamma = 1 / L
wc, theory = wc_gradient_descent_non_convex(L, gamma, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_no_lips_1(self):
L, n = 1, 5
gamma = 1 / L / 2
wc, theory = wc_no_lips_1(L, gamma, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_no_lips_2(self):
L, n = 1, 3
gamma = 1 / L
wc, theory = wc_no_lips_2(L, gamma, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_saga(self):
L, mu, n = 1, 0.1, 5
wc, theory = wc_saga(L, mu, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_sgd(self):
L, mu, v, R, n = 1, 0.1, 1, 2, 5
gamma = 1 / L
wc, theory = wc_sgd(L, mu, gamma, v, R, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_sgd_overparametrized(self):
L, mu, n = 1, 0.1, 5
gamma = 1 / L
wc, theory = wc_sgd_overparametrized(L, mu, gamma, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_point_saga(self):
L, mu, n = 1, 0.1, 10
wc, theory = wc_point_saga(L, mu, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertLessEqual(wc, theory)
def test_randomized_coordinate(self):
L, d, t = 1, 3, 10
gamma = 1 / L
wc, theory = wc_randomized_coordinate_descent_smooth_convex(L=L, gamma=gamma, d=d, t=t, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_randomized_coordinate_strongly_convex(self):
L, mu, d = 1, 0.1, 3
gamma = 2 / (L + mu)
wc, theory = wc_randomized_coordinate_descent_smooth_strongly_convex(L=L, mu=mu, gamma=gamma, d=d,
wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_accelerated_proximal_point_operators(self):
alpha, n = 2.1, 10
wc, theory = wc_accelerated_proximal_point_operators(alpha, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_proximal_point_method_operators(self):
alpha, n = 2.1, 3
wc, theory = wc_proximal_point_method_operators(alpha, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_wc_optimal_strongly_monotone_proximal_point_operators(self):
n, mu = 3, 0.23
wc, theory = wc_optimal_strongly_monotone_proximal_point_operators(n=n, mu=mu, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_douglas_rachford_splitting_operators(self):
L, mu, alpha, theta = 1, 0.1, 1.3, 0.9
wc, theory = wc_douglas_rachford_splitting_operators(L, mu, alpha, theta, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_douglas_rachford_splitting_operators_2(self):
beta, mu, alpha, theta = 1.2, 0.1, 0.3, 1.5
wc, theory = wc_douglas_rachford_splitting_operators_2(beta, mu, alpha, theta, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_three_operator_splitting_operators(self):
L, mu, beta, alpha, theta = 1, 0.1, 1, 1.3, 0.9
n_list = range(1, 2)
ref_pesto_bounds = [0.7797]
for n in n_list:
wc, _ = wc_three_operator_splitting_operators(L, mu, beta, alpha, theta, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, ref_pesto_bounds[n - 1], delta=self.relative_precision * ref_pesto_bounds[n - 1])
def test_optimistic_gradient(self):
n1, n2, L, gamma = 5, 6, 1, 1 / 4
wc1, _ = wc_optimistic_gradient_operators(n=n1, gamma=gamma, L=L, wrapper=self.wrapper, verbose=self.verbose)
wc2, _ = wc_optimistic_gradient_operators(n=n2, gamma=gamma, L=L, wrapper=self.wrapper, verbose=self.verbose)
self.assertLessEqual(wc2, wc1)
def test_past_extragradient(self):
n1, n2, L, gamma = 5, 6, 1, 1 / 4
wc1, _ = wc_past_extragradient_operators(n=n1, gamma=gamma, L=L, wrapper=self.wrapper, verbose=self.verbose)
wc2, _ = wc_past_extragradient_operators(n=n2, gamma=gamma, L=L, wrapper=self.wrapper, verbose=self.verbose)
self.assertLessEqual(wc2, wc1)
def test_halpern_iteration(self):
n = 10
wc, theory = wc_halpern_iteration(n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_krasnoselskii_mann_constant_step_sizes(self):
n = 10
wc, theory = wc_krasnoselskii_mann_constant_step_sizes(n, gamma=3 / 4, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_krasnoselskii_mann_increasing_step_sizes(self):
n = 10
ref_pesto_bound = 0.059527
wc, _ = wc_krasnoselskii_mann_increasing_step_sizes(n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, ref_pesto_bound, delta=self.relative_precision * ref_pesto_bound)
def test_wc_inconsistent_halpern_iteration(self):
n = 25
wc, theory = wc_inconsistent_halpern_iteration(n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertLessEqual(wc, theory)
def test_wc_optimal_contractive_halpern_iteration(self):
n, gamma = 3, 1.13
wc, theory = wc_optimal_contractive_halpern_iteration(n=n, gamma=gamma, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_gradient_descent_lyapunov_1(self):
L, n = 1, 10
gamma = 1 / L
wc, theory = wc_gradient_descent_lyapunov_1(L, gamma, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.absolute_precision)
def test_gradient_descent_lyapunov_2(self):
L, n = 1, 10
gamma = 1 / L
wc, theory = wc_gradient_descent_lyapunov_2(L, gamma, n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.absolute_precision)
def test_accelerated_gradient_method(self):
L, lam = 1, 10
gamma = 1 / L
wc, theory = wc_accelerated_gradient_method(L, gamma, lam, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.absolute_precision)
def test_polyak_steps_in_distance_to_optimum(self):
L, mu = 1, 0.1
gamma = 2 / L
wc, theory = wc_polyak_steps_in_distance_to_optimum(L, mu, gamma, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.absolute_precision)
def test_polyak_steps_in_function_value(self):
L, mu = 1, 0.1
gamma = 2 / L
wc, theory = wc_polyak_steps_in_function_value(L, mu, gamma, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.absolute_precision)
def test_accelerated_inexact_forward_backward(self):
L, zeta, n = 10, .87, 10
wc, theory = wc_accelerated_inexact_forward_backward(L=L, zeta=zeta, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertLessEqual(wc, theory)
def test_partially_inexact_douglas_rachford_splitting(self):
mu, L, gamma, sigma, n = 1, 5., 1.4, 0.2, 5
wc, theory = wc_partially_inexact_douglas_rachford_splitting(mu, L, n, gamma, sigma, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
def test_relatively_inexact_proximal_point_algorithm(self):
gamma, sigma, n = 2, 0.3, 5
wc, theory = wc_relatively_inexact_proximal_point_algorithm(n, gamma, sigma, wrapper=self.wrapper, verbose=self.verbose)
self.assertLessEqual(wc, theory)
def test_accelerated_gradient_flow_convex(self):
t = 3.4
wc, theory = wc_accelerated_gradient_flow_convex(t=t, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.absolute_precision)
def test_gradient_flow_convex(self):
t = 3.4
wc, theory = wc_gradient_flow_convex(t=t, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.absolute_precision)
def test_accelerated_gradient_flow_strongly_convex(self):
mu = 2.1
for psd in {True, False}:
wc, theory = wc_accelerated_gradient_flow_strongly_convex(mu=mu, psd=psd, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.absolute_precision)
def test_gradient_flow_strongly_convex(self):
mu = .8
wc, theory = wc_gradient_flow_strongly_convex(mu=mu, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.absolute_precision)
def test_gradient_descent_contraction(self):
L, mu, n = 1, 0.1, 1
gamma = 1 / L
wc, theory = wc_gradient_descent_contraction(L=L, mu=mu, gamma=gamma, n=n, wrapper=self.wrapper, verbose=self.verbose)
self.assertAlmostEqual(wc, theory, delta=self.relative_precision * theory)
class TestExamplesMosek(TestExamplesCVXPY):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.wrapper = "mosek"