/
ChambollePock.jl
508 lines (485 loc) · 18 KB
/
ChambollePock.jl
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
@doc raw"""
ChambollePockState <: AbstractPrimalDualSolverState
stores all options and variables within a linearized or exact Chambolle Pock.
The following list provides the order for the constructor, where the previous iterates are
initialized automatically and values with a default may be left out.
* `m` - base point on ``\mathcal M``
* `n` - base point on ``\mathcal N``
* `p` - an initial point on ``x^{(0)} ∈\mathcal M`` (and its previous iterate)
* `X` - an initial tangent vector ``X^{(0)}∈T^*\mathcal N`` (and its previous iterate)
* `pbar` - the relaxed iterate used in the next dual update step (when using `:primal` relaxation)
* `Xbar` - the relaxed iterate used in the next primal update step (when using `:dual` relaxation)
* `primal_stepsize` – (`1/sqrt(8)`) proximal parameter of the primal prox
* `dual_stepsize` – (`1/sqrt(8)`) proximal parameter of the dual prox
* `acceleration` – (`0.`) acceleration factor due to Chambolle & Pock
* `relaxation` – (`1.`) relaxation in the primal relaxation step (to compute `pbar`)
* `relax` – (`:primal`) which variable to relax (`:primal` or `:dual`)
* `stop` - a [`StoppingCriterion`](@ref)
* `variant` – (`exact`) whether to perform an `:exact` or `:linearized` Chambolle-Pock
* `update_primal_base` (`(p,o,i) -> o.m`) function to update the primal base
* `update_dual_base` (`(p,o,i) -> o.n`) function to update the dual base
* `retraction_method` – (`default_retraction_method(M, typeof(p))`) the retraction to use
* `inverse_retraction_method` - (`default_inverse_retraction_method(M, typeof(p))`) an inverse
retraction to use on the manifold ``\mathcal M``.
* `inverse_retraction_method_dual` - (`default_inverse_retraction_method(N, typeof(n))`)
an inverse retraction to use on manifold ``\mathcal N``.
* `vector_transport_method` - (`default_vector_transport_method(M, typeof(p))`) a vector transport to
use on the manifold ``\mathcal M``.
* `vector_transport_method_dual` - (`default_vector_transport_method(N, typeof(n))`) a
vector transport to use on manifold ``\mathcal N``.
where for the last two the functions a [`AbstractManoptProblem`](@ref)` p`,
[`AbstractManoptSolverState`](@ref)` o` and the current iterate `i` are the arguments.
If you activate these to be different from the default identity, you have to provide
`p.Λ` for the algorithm to work (which might be `missing` in the linearized case).
# Constructor
ChambollePockState(M::AbstractManifold,
m::P, n::Q, p::P, X::T, primal_stepsize::Float64, dual_stepsize::Float64;
kwargs...
)
where all other fields from above are keyword arguments with their default values given in brackets,
as well as `N=TangentBundle(M)`
"""
mutable struct ChambollePockState{
P,
Q,
T,
RM<:AbstractRetractionMethod,
IRM<:AbstractInverseRetractionMethod,
IRM_Dual<:AbstractInverseRetractionMethod,
VTM<:AbstractVectorTransportMethod,
VTM_Dual<:AbstractVectorTransportMethod,
} <: AbstractPrimalDualSolverState
m::P
n::Q
p::P
pbar::P
X::T
Xbar::T
primal_stepsize::Float64
dual_stepsize::Float64
acceleration::Float64
relaxation::Float64
relax::Symbol
stop::StoppingCriterion
variant::Symbol
update_primal_base::Union{Function,Missing}
update_dual_base::Union{Function,Missing}
retraction_method::RM
inverse_retraction_method::IRM
inverse_retraction_method_dual::IRM_Dual
vector_transport_method::VTM
vector_transport_method_dual::VTM_Dual
function ChambollePockState(
M::AbstractManifold,
m::P,
n::Q,
p::P,
X::T;
N=TangentBundle(M),
primal_stepsize::Float64=1 / sqrt(8),
dual_stepsize::Float64=1 / sqrt(8),
acceleration::Float64=0.0,
relaxation::Float64=1.0,
relax::Symbol=:primal,
stopping_criterion::StoppingCriterion=StopAfterIteration(300),
variant::Symbol=:exact,
update_primal_base::Union{Function,Missing}=missing,
update_dual_base::Union{Function,Missing}=missing,
retraction_method::RM=default_retraction_method(M, typeof(p)),
inverse_retraction_method::IRM=default_inverse_retraction_method(M, typeof(p)),
inverse_retraction_method_dual::IRM_Dual=default_inverse_retraction_method(
N, typeof(p)
),
vector_transport_method::VTM=default_vector_transport_method(M, typeof(n)),
vector_transport_method_dual::VTM_Dual=default_vector_transport_method(
N, typeof(n)
),
) where {
P,
Q,
T,
RM<:AbstractRetractionMethod,
IRM<:AbstractInverseRetractionMethod,
IRM_Dual<:AbstractInverseRetractionMethod,
VTM<:AbstractVectorTransportMethod,
VTM_Dual<:AbstractVectorTransportMethod,
}
return new{P,Q,T,RM,IRM,IRM_Dual,VTM,VTM_Dual}(
m,
n,
p,
copy(M, p),
X,
copy(N, X),
primal_stepsize,
dual_stepsize,
acceleration,
relaxation,
relax,
stopping_criterion,
variant,
update_primal_base,
update_dual_base,
retraction_method,
inverse_retraction_method,
inverse_retraction_method_dual,
vector_transport_method,
vector_transport_method_dual,
)
end
end
function show(io::IO, cps::ChambollePockState)
i = get_count(cps, :Iterations)
Iter = (i > 0) ? "After $i iterations\n" : ""
Conv = indicates_convergence(cps.stop) ? "Yes" : "No"
s = """
# Solver state for `Manopt.jl`s Chambolle-Pock Algorithm
$Iter
## Parameters
* primal_stepsize: $(cps.primal_stepsize)
* dual_stepsize: $(cps.dual_stepsize)
* acceleration: $(cps.acceleration)
* relaxation: $(cps.relaxation)
* relax: $(cps.relax)
* variant: :$(cps.variant)
* retraction_method: $(cps.retraction_method)
* inverse_retraction_method: $(cps.inverse_retraction_method)
* vector_transport_method: $(cps.vector_transport_method)
* inverse_retraction_method_dual: $(cps.inverse_retraction_method_dual)
* vector_transport_method_dual: $(cps.vector_transport_method_dual)
## Stopping Criterion
$(status_summary(cps.stop))
This indicates convergence: $Conv"""
return print(io, s)
end
get_solver_result(apds::AbstractPrimalDualSolverState) = get_iterate(apds)
get_iterate(apds::AbstractPrimalDualSolverState) = apds.p
function set_iterate!(apds::AbstractPrimalDualSolverState, p)
apds.p = p
return apds
end
@doc raw"""
ChambollePock(
M, N, cost, x0, ξ0, m, n, prox_F, prox_G_dual, adjoint_linear_operator;
forward_operator=missing,
linearized_forward_operator=missing,
evaluation=AllocatingEvaluation()
)
Perform the Riemannian Chambolle–Pock algorithm.
Given a `cost` function $\mathcal E:\mathcal M → ℝ$ of the form
```math
\mathcal E(p) = F(p) + G( Λ(p) ),
```
where $F:\mathcal M → ℝ$, $G:\mathcal N → ℝ$,
and $Λ:\mathcal M → \mathcal N$. The remaining input parameters are
* `p, X` primal and dual start points $x∈\mathcal M$ and $ξ∈T_n\mathcal N$
* `m,n` base points on $\mathcal M$ and $\mathcal N$, respectively.
* `adjoint_linearized_operator` the adjoint $DΛ^*$ of the linearized operator $DΛ(m): T_{m}\mathcal M → T_{Λ(m)}\mathcal N$
* `prox_F, prox_G_Dual` the proximal maps of $F$ and $G^\ast_n$
note that depending on the [`AbstractEvaluationType`](@ref) `evaluation` the last three parameters
as well as the forward_operator `Λ` and the `linearized_forward_operator` can be given as
allocating functions `(Manifolds, parameters) -> result` or as mutating functions
`(Manifold, result, parameters)` -> result` to spare allocations.
By default, this performs the exact Riemannian Chambolle Pock algorithm, see the optional parameter
`DΛ` for their linearized variant.
For more details on the algorithm, see[^BergmannHerzogSilvaLouzeiroTenbrinckVidalNunez2020].
# Optional Parameters
* `acceleration` – (`0.05`)
* `dual_stepsize` – (`1/sqrt(8)`) proximal parameter of the primal prox
* `evaluation` ([`AllocatingEvaluation`](@ref)`()) specify whether the proximal maps and operators are
allocating functions `(Manifolds, parameters) -> result` or given as mutating functions
`(Manifold, result, parameters)` -> result` to spare allocations.
* `Λ` (`missing`) the (forward) operator $Λ(⋅)$ (required for the `:exact` variant)
* `linearized_forward_operator` (`missing`) its linearization $DΛ(⋅)[⋅]$ (required for the `:linearized` variant)
* `primal_stepsize` – (`1/sqrt(8)`) proximal parameter of the dual prox
* `relaxation` – (`1.`)
* `relax` – (`:primal`) whether to relax the primal or dual
* `variant` - (`:exact` if `Λ` is missing, otherwise `:linearized`) variant to use.
Note that this changes the arguments the `forward_operator` will be called.
* `stopping_criterion` – (`stopAtIteration(100)`) a [`StoppingCriterion`](@ref)
* `update_primal_base` – (`missing`) function to update `m` (identity by default/missing)
* `update_dual_base` – (`missing`) function to update `n` (identity by default/missing)
* `retraction_method` – (`default_retraction_method(M, typeof(p))`) the rectraction to use
* `inverse_retraction_method` - (`default_inverse_retraction_method(M, typeof(p))`) an inverse retraction to use.
* `vector_transport_method` - (`default_vector_transport_method(M, typeof(p))`) a vector transport to use
# Output
the obtained (approximate) minimizer ``p^*``, see [`get_solver_return`](@ref) for details
[^BergmannHerzogSilvaLouzeiroTenbrinckVidalNunez2020]:
> R. Bergmann, R. Herzog, M. Silva Louzeiro, D. Tenbrinck, J. Vidal-Núñez:
> _Fenchel Duality Theory and a Primal-Dual Algorithm on Riemannian Manifolds_,
> Foundations of Computational Mathematics, 2021.
> doi: [10.1007/s10208-020-09486-5](http://dx.doi.org/10.1007/s10208-020-09486-5)
> arXiv: [1908.02022](http://arxiv.org/abs/1908.02022)
"""
function ChambollePock(
M::AbstractManifold,
N::AbstractManifold,
cost::TF,
p::P,
X::T,
m::P,
n::Q,
prox_F::Function,
prox_G_dual::Function,
adjoint_linear_operator::Function;
Λ::Union{Function,Missing}=missing,
linearized_forward_operator::Union{Function,Missing}=missing,
kwargs...,
) where {TF,P,T,Q}
q = copy(M, p)
Y = copy(N, n, X)
m2 = copy(M, m)
n2 = copy(N, n)
return ChambollePock!(
M,
N,
cost,
q,
Y,
m2,
n2,
prox_F,
prox_G_dual,
adjoint_linear_operator;
Λ=Λ,
linearized_forward_operator=linearized_forward_operator,
kwargs...,
)
end
@doc raw"""
ChambollePock(M, N, cost, x0, ξ0, m, n, prox_F, prox_G_dual, adjoint_linear_operator)
Perform the Riemannian Chambolle–Pock algorithm in place of `x`, `ξ`, and potentially `m`,
`n` if they are not fixed. See [`ChambollePock`](@ref) for details and optional parameters.
"""
function ChambollePock!(
M::AbstractManifold,
N::AbstractManifold,
cost::TF,
p::P,
X::T,
m::P,
n::Q,
prox_F::Function,
prox_G_dual::Function,
adjoint_linear_operator::Function;
Λ::Union{Function,Missing}=missing,
linearized_forward_operator::Union{Function,Missing}=missing,
acceleration=0.05,
dual_stepsize=1 / sqrt(8),
primal_stepsize=1 / sqrt(8),
relaxation=1.0,
relax::Symbol=:primal,
stopping_criterion::StoppingCriterion=StopAfterIteration(200),
update_primal_base::Union{Function,Missing}=missing,
update_dual_base::Union{Function,Missing}=missing,
retraction_method::RM=default_retraction_method(M, typeof(p)),
inverse_retraction_method::IRM=default_inverse_retraction_method(M, typeof(p)),
vector_transport_method::VTM=default_vector_transport_method(M, typeof(p)),
variant=ismissing(Λ) ? :exact : :linearized,
kwargs...,
) where {
TF,
P,
Q,
T,
RM<:AbstractRetractionMethod,
IRM<:AbstractInverseRetractionMethod,
VTM<:AbstractVectorTransportMethod,
}
pdmo = PrimalDualManifoldObjective(
cost,
prox_F,
prox_G_dual,
adjoint_linear_operator;
linearized_forward_operator=linearized_forward_operator,
Λ=Λ,
)
dpdmo = decorate_objective!(M, pdmo; kwargs...)
tmp = TwoManifoldProblem(M, N, dpdmo)
o = ChambollePockState(
M,
m,
n,
p,
X;
N=N,
primal_stepsize=primal_stepsize,
dual_stepsize=dual_stepsize,
acceleration=acceleration,
relaxation=relaxation,
stopping_criterion=stopping_criterion,
relax=relax,
update_primal_base=update_primal_base,
update_dual_base=update_dual_base,
variant=variant,
retraction_method=retraction_method,
inverse_retraction_method=inverse_retraction_method,
vector_transport_method=vector_transport_method,
)
o = decorate_state!(o; kwargs...)
return get_solver_return(solve!(tmp, o))
end
function initialize_solver!(::TwoManifoldProblem, ::ChambollePockState) end
function step_solver!(tmp::TwoManifoldProblem, cps::ChambollePockState, iter)
N = get_manifold(tmp, 2)
primal_dual_step!(tmp, cps, Val(cps.relax))
cps.m =
ismissing(cps.update_primal_base) ? cps.m : cps.update_primal_base(tmp, cps, iter)
if !ismissing(cps.update_dual_base)
n_old = deepcopy(cps.n)
cps.n = cps.update_dual_base(tmp, cps, iter)
vector_transport_to!(
N, cps.X, n_old, cps.X, cps.n, cps.vector_transport_method_dual
)
vector_transport_to!(
N, cps.Xbar, n_old, cps.Xbar, cps.n, cps.vector_transport_method_dual
)
end
return cps
end
#
# Variant 1: primal relax
#
function primal_dual_step!(tmp::TwoManifoldProblem, cps::ChambollePockState, ::Val{:primal})
dual_update!(tmp, cps, cps.pbar, Val(cps.variant))
obj = get_objective(tmp)
M = get_manifold(tmp, 1)
N = get_manifold(tmp, 2)
if !hasproperty(obj, :Λ!!) || ismissing(obj.Λ!!)
ptXn = cps.X
else
ptXn = vector_transport_to(
N, cps.n, cps.X, forward_operator(tmp, cps.m), cps.vector_transport_method_dual
)
end
p_old = cps.p
cps.p = get_primal_prox!(
tmp,
cps.p,
cps.primal_stepsize,
retract(
M,
cps.p,
vector_transport_to(
M,
cps.m,
-cps.primal_stepsize *
(adjoint_linearized_operator(tmp, cps.m, cps.n, ptXn)),
cps.p,
cps.vector_transport_method,
),
cps.retraction_method,
),
)
update_prox_parameters!(cps)
retract!(
M,
cps.pbar,
cps.p,
-cps.relaxation * inverse_retract(M, cps.p, p_old, cps.inverse_retraction_method),
cps.retraction_method,
)
return cps
end
#
# Variant 2: dual relax
#
function primal_dual_step!(tmp::TwoManifoldProblem, cps::ChambollePockState, ::Val{:dual})
obj = get_objective(tmp)
M = get_manifold(tmp, 1)
N = get_manifold(tmp, 2)
if !hasproperty(obj, :Λ!!) || ismissing(obj.Λ!!)
ptXbar = cps.Xbar
else
ptXbar = vector_transport_to(
N,
cps.n,
cps.Xbar,
forward_operator(tmp, cps.m),
cps.vector_transport_method_dual,
)
end
get_primal_prox!(
tmp,
cps.p,
cps.primal_stepsize,
retract(
M,
cps.p,
vector_transport_to(
M,
cps.m,
-cps.primal_stepsize *
(adjoint_linearized_operator(tmp, cps.m, cps.n, ptXbar)),
cps.p,
cps.vector_transport_method,
),
cps.retraction_method,
),
)
X_old = deepcopy(cps.X)
dual_update!(tmp, cps, cps.p, Val(cps.variant))
update_prox_parameters!(cps)
cps.Xbar = cps.X + cps.relaxation * (cps.X - X_old)
return cps
end
#
# Dual step: linearized
# depending on whether its primal relaxed or dual relaxed we start from start=o.x or start=o.xbar here
#
function dual_update!(
tmp::TwoManifoldProblem, cps::ChambollePockState, start::P, ::Val{:linearized}
) where {P}
M = get_manifold(tmp, 1)
N = get_manifold(tmp, 2)
obj = get_objective(tmp)
# (1) compute update direction
X_update = linearized_forward_operator(
tmp, cps.m, inverse_retract(M, cps.m, start, cps.inverse_retraction_method), cps.n
)
# (2) if p.Λ is missing, we assume that n = Λ(m) and do not PT, otherwise we do
(hasproperty(obj, :Λ!!) && !ismissing(obj.Λ!!)) && vector_transport_to!(
N,
X_update,
forward_operator(tmp, cps.m),
X_update,
cps.n,
cps.vector_transport_method_dual,
)
# (3) to the dual update
get_dual_prox!(
tmp, cps.X, cps.n, cps.dual_stepsize, cps.X + cps.dual_stepsize * X_update
)
return cps
end
#
# Dual step: exact
# depending on whether its primal relaxed or dual relaxed we start from start=o.x or start=o.xbar here
#
function dual_update!(
tmp::TwoManifoldProblem, cps::ChambollePockState, start::P, ::Val{:exact}
) where {P}
N = get_manifold(tmp, 2)
ξ_update = inverse_retract(
N, cps.n, forward_operator(tmp, start), cps.inverse_retraction_method_dual
)
get_dual_prox!(
tmp, cps.X, cps.n, cps.dual_stepsize, cps.X + cps.dual_stepsize * ξ_update
)
return cps
end
@doc raw"""
update_prox_parameters!(o)
update the prox parameters as described in Algorithm 2 of Chambolle, Pock, 2010, i.e.
1. ``θ_{n} = \frac{1}{\sqrt{1+2γτ_n}}``
2. ``τ_{n+1} = θ_nτ_n``
3. ``σ_{n+1} = \frac{σ_n}{θ_n}``
"""
function update_prox_parameters!(pds::S) where {S<:AbstractPrimalDualSolverState}
if pds.acceleration > 0
pds.relaxation = 1 / sqrt(1 + 2 * pds.acceleration * pds.primal_stepsize)
pds.primal_stepsize = pds.primal_stepsize * pds.relaxation
pds.dual_stepsize = pds.dual_stepsize / pds.relaxation
end
return pds
end