Thu, 23 Jan 2025 23:35:28 +0100
Generic proximal penalty support
0 | 1 | /*! |
2 | Solver for the point source localisation problem with primal-dual proximal splitting. | |
3 | ||
4 | This corresponds to the manuscript | |
5 | ||
13
bdc57366d4f5
arXiv links, README beautification
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
6 | * Valkonen T. - _Proximal methods for point source localisation_, |
bdc57366d4f5
arXiv links, README beautification
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
7 | [arXiv:2212.02991](https://arxiv.org/abs/2212.02991). |
0 | 8 | |
35 | 9 | The main routine is [`pointsource_pdps_reg`]. |
0 | 10 | Both norm-2-squared and norm-1 data terms are supported. That is, implemented are solvers for |
11 | <div> | |
12 | $$ | |
13 | \min_{μ ∈ ℳ(Ω)}~ F_0(Aμ - b) + α \|μ\|_{ℳ(Ω)} + δ_{≥ 0}(μ), | |
14 | $$ | |
15 | for both $F_0(y)=\frac{1}{2}\|y\|_2^2$ and $F_0(y)=\|y\|_1$ with the forward operator | |
16 | $A \in 𝕃(ℳ(Ω); ℝ^n)$. | |
17 | </div> | |
18 | ||
19 | ## Approach | |
20 | ||
21 | <p> | |
22 | The problem above can be written as | |
23 | $$ | |
24 | \min_μ \max_y G(μ) + ⟨y, Aμ-b⟩ - F_0^*(μ), | |
25 | $$ | |
26 | where $G(μ) = α \|μ\|_{ℳ(Ω)} + δ_{≥ 0}(μ)$. | |
27 | The Fenchel–Rockafellar optimality conditions, employing the predual in $ℳ(Ω)$, are | |
28 | $$ | |
29 | 0 ∈ A_*y + ∂G(μ) | |
30 | \quad\text{and}\quad | |
31 | Aμ - b ∈ ∂ F_0^*(y). | |
32 | $$ | |
33 | The solution of the first part is as for forward-backward, treated in the manuscript. | |
34 | This is the task of <code>generic_pointsource_fb</code>, where we use <code>FBSpecialisation</code> | |
35 | to replace the specific residual $Aμ-b$ by $y$. | |
36 | For $F_0(y)=\frac{1}{2}\|y\|_2^2$ the second part reads $y = Aμ -b$. | |
37 | For $F_0(y)=\|y\|_1$ the second part reads $y ∈ ∂\|·\|_1(Aμ - b)$. | |
38 | </p> | |
39 | */ | |
40 | ||
41 | use numeric_literals::replace_float_literals; | |
42 | use serde::{Serialize, Deserialize}; | |
43 | use nalgebra::DVector; | |
44 | use clap::ValueEnum; | |
45 | ||
35 | 46 | use alg_tools::iterate::AlgIteratorFactory; |
0 | 47 | use alg_tools::euclidean::Euclidean; |
35 | 48 | use alg_tools::linops::Mapping; |
0 | 49 | use alg_tools::norms::{ |
32 | 50 | Linfinity, |
51 | Projection, | |
0 | 52 | }; |
35 | 53 | use alg_tools::mapping::{RealMapping, Instance}; |
0 | 54 | use alg_tools::nalgebra_support::ToNalgebraRealField; |
55 | use alg_tools::linops::AXPY; | |
56 | ||
57 | use crate::types::*; | |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
58 | use crate::measures::{DiscreteMeasure, RNDM}; |
32 | 59 | use crate::measures::merging::SpikeMerging; |
35 | 60 | use crate::forward_model::{ |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
61 | ForwardModel, |
35 | 62 | AdjointProductBoundedBy, |
63 | }; | |
0 | 64 | use crate::plot::{ |
65 | SeqPlotter, | |
66 | Plotting, | |
67 | PlotLookup | |
68 | }; | |
69 | use crate::fb::{ | |
32 | 70 | postprocess, |
35 | 71 | prune_with_stats |
32 | 72 | }; |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
73 | pub use crate::prox_penalty::{ |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
74 | FBGenericConfig, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
75 | ProxPenalty |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
76 | }; |
32 | 77 | use crate::regularisation::RegTerm; |
78 | use crate::dataterm::{ | |
79 | DataTerm, | |
80 | L2Squared, | |
81 | L1 | |
0 | 82 | }; |
83 | ||
84 | /// Acceleration | |
85 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, ValueEnum, Debug)] | |
86 | pub enum Acceleration { | |
87 | /// No acceleration | |
88 | #[clap(name = "none")] | |
89 | None, | |
90 | /// Partial acceleration, $ω = 1/\sqrt{1+σ}$ | |
91 | #[clap(name = "partial", help = "Partial acceleration, ω = 1/√(1+σ)")] | |
92 | Partial, | |
93 | /// Full acceleration, $ω = 1/\sqrt{1+2σ}$; no gap convergence guaranteed | |
94 | #[clap(name = "full", help = "Full acceleration, ω = 1/√(1+2σ); no gap convergence guaranteed")] | |
95 | Full | |
96 | } | |
97 | ||
35 | 98 | #[replace_float_literals(F::cast_from(literal))] |
99 | impl Acceleration { | |
100 | /// PDPS parameter acceleration. Updates τ and σ and returns ω. | |
101 | /// This uses dual strong convexity, not primal. | |
102 | fn accelerate<F : Float>(self, τ : &mut F, σ : &mut F, γ : F) -> F { | |
103 | match self { | |
104 | Acceleration::None => 1.0, | |
105 | Acceleration::Partial => { | |
106 | let ω = 1.0 / (1.0 + γ * (*σ)).sqrt(); | |
107 | *σ *= ω; | |
108 | *τ /= ω; | |
109 | ω | |
110 | }, | |
111 | Acceleration::Full => { | |
112 | let ω = 1.0 / (1.0 + 2.0 * γ * (*σ)).sqrt(); | |
113 | *σ *= ω; | |
114 | *τ /= ω; | |
115 | ω | |
116 | }, | |
117 | } | |
118 | } | |
119 | } | |
120 | ||
121 | /// Settings for [`pointsource_pdps_reg`]. | |
0 | 122 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] |
123 | #[serde(default)] | |
124 | pub struct PDPSConfig<F : Float> { | |
125 | /// Primal step length scaling. We must have `τ0 * σ0 < 1`. | |
126 | pub τ0 : F, | |
127 | /// Dual step length scaling. We must have `τ0 * σ0 < 1`. | |
128 | pub σ0 : F, | |
129 | /// Accelerate if available | |
130 | pub acceleration : Acceleration, | |
131 | /// Generic parameters | |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
132 | pub generic : FBGenericConfig<F>, |
0 | 133 | } |
134 | ||
135 | #[replace_float_literals(F::cast_from(literal))] | |
136 | impl<F : Float> Default for PDPSConfig<F> { | |
137 | fn default() -> Self { | |
138 | let τ0 = 0.5; | |
139 | PDPSConfig { | |
140 | τ0, | |
141 | σ0 : 0.99/τ0, | |
142 | acceleration : Acceleration::Partial, | |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
143 | generic : Default::default(), |
0 | 144 | } |
145 | } | |
146 | } | |
147 | ||
32 | 148 | /// Trait for data terms for the PDPS |
149 | #[replace_float_literals(F::cast_from(literal))] | |
150 | pub trait PDPSDataTerm<F : Float, V, const N : usize> : DataTerm<F, V, N> { | |
151 | /// Calculate some subdifferential at `x` for the conjugate | |
152 | fn some_subdifferential(&self, x : V) -> V; | |
153 | ||
154 | /// Factor of strong convexity of the conjugate | |
155 | #[inline] | |
156 | fn factor_of_strong_convexity(&self) -> F { | |
157 | 0.0 | |
158 | } | |
159 | ||
160 | /// Perform dual update | |
161 | fn dual_update(&self, _y : &mut V, _y_prev : &V, _σ : F); | |
0 | 162 | } |
163 | ||
32 | 164 | |
165 | #[replace_float_literals(F::cast_from(literal))] | |
35 | 166 | impl<F, V, const N : usize> PDPSDataTerm<F, V, N> |
167 | for L2Squared | |
168 | where | |
169 | F : Float, | |
170 | V : Euclidean<F> + AXPY<F>, | |
171 | for<'b> &'b V : Instance<V>, | |
172 | { | |
32 | 173 | fn some_subdifferential(&self, x : V) -> V { x } |
0 | 174 | |
32 | 175 | fn factor_of_strong_convexity(&self) -> F { |
176 | 1.0 | |
177 | } | |
178 | ||
179 | #[inline] | |
180 | fn dual_update(&self, y : &mut V, y_prev : &V, σ : F) { | |
35 | 181 | y.axpy(1.0 / (1.0 + σ), y_prev, σ / (1.0 + σ)); |
32 | 182 | } |
0 | 183 | } |
184 | ||
32 | 185 | #[replace_float_literals(F::cast_from(literal))] |
186 | impl<F : Float + nalgebra::RealField, const N : usize> | |
187 | PDPSDataTerm<F, DVector<F>, N> | |
188 | for L1 { | |
0 | 189 | fn some_subdifferential(&self, mut x : DVector<F>) -> DVector<F> { |
190 | // nalgebra sucks for providing second copies of the same stuff that's elsewhere as well. | |
191 | x.iter_mut() | |
192 | .for_each(|v| if *v != F::ZERO { *v = *v/<F as NumTraitsFloat>::abs(*v) }); | |
193 | x | |
194 | } | |
195 | ||
32 | 196 | #[inline] |
197 | fn dual_update(&self, y : &mut DVector<F>, y_prev : &DVector<F>, σ : F) { | |
198 | y.axpy(1.0, y_prev, σ); | |
0 | 199 | y.proj_ball_mut(1.0, Linfinity); |
200 | } | |
201 | } | |
202 | ||
203 | /// Iteratively solve the pointsource localisation problem using primal-dual proximal splitting. | |
204 | /// | |
205 | /// The `dataterm` should be either [`L1`] for norm-1 data term or [`L2Squared`] for norm-2-squared. | |
206 | /// The settings in `config` have their [respective documentation](PDPSConfig). `opA` is the | |
207 | /// forward operator $A$, $b$ the observable, and $\lambda$ the regularisation weight. | |
208 | /// The operator `op𝒟` is used for forming the proximal term. Typically it is a convolution | |
209 | /// operator. Finally, the `iterator` is an outer loop verbosity and iteration count control | |
210 | /// as documented in [`alg_tools::iterate`]. | |
211 | /// | |
212 | /// For the mathematical formulation, see the [module level](self) documentation and the manuscript. | |
213 | /// | |
214 | /// Returns the final iterate. | |
215 | #[replace_float_literals(F::cast_from(literal))] | |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
216 | pub fn pointsource_pdps_reg<F, I, A, D, Reg, P, const N : usize>( |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
217 | opA : &A, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
218 | b : &A::Observable, |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
219 | reg : Reg, |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
220 | prox_penalty : &P, |
32 | 221 | pdpsconfig : &PDPSConfig<F>, |
0 | 222 | iterator : I, |
32 | 223 | mut plotter : SeqPlotter<F, N>, |
0 | 224 | dataterm : D, |
35 | 225 | ) -> RNDM<F, N> |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
226 | where |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
227 | F : Float + ToNalgebraRealField, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
228 | I : AlgIteratorFactory<IterInfo<F, N>>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
229 | A : ForwardModel<RNDM<F, N>, F> |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
230 | + AdjointProductBoundedBy<RNDM<F, N>, P, FloatType=F>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
231 | A::PreadjointCodomain : RealMapping<F, N>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
232 | for<'b> &'b A::Observable : std::ops::Neg<Output=A::Observable> + Instance<A::Observable>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
233 | PlotLookup : Plotting<N>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
234 | RNDM<F, N> : SpikeMerging<F>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
235 | D : PDPSDataTerm<F, A::Observable, N>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
236 | Reg : RegTerm<F, N>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
237 | P : ProxPenalty<F, A::PreadjointCodomain, Reg, N>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
238 | { |
0 | 239 | |
35 | 240 | // Check parameters |
241 | assert!(pdpsconfig.τ0 > 0.0 && | |
242 | pdpsconfig.σ0 > 0.0 && | |
243 | pdpsconfig.τ0 * pdpsconfig.σ0 <= 1.0, | |
244 | "Invalid step length parameters"); | |
245 | ||
32 | 246 | // Set up parameters |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
247 | let config = &pdpsconfig.generic; |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
248 | let l = opA.adjoint_product_bound(prox_penalty).unwrap().sqrt(); |
32 | 249 | let mut τ = pdpsconfig.τ0 / l; |
250 | let mut σ = pdpsconfig.σ0 / l; | |
251 | let γ = dataterm.factor_of_strong_convexity(); | |
252 | ||
253 | // We multiply tolerance by τ for FB since our subproblems depending on tolerances are scaled | |
254 | // by τ compared to the conditional gradient approach. | |
255 | let tolerance = config.tolerance * τ * reg.tolerance_scaling(); | |
256 | let mut ε = tolerance.initial(); | |
257 | ||
258 | // Initialise iterates | |
259 | let mut μ = DiscreteMeasure::new(); | |
260 | let mut y = dataterm.some_subdifferential(-b); | |
261 | let mut y_prev = y.clone(); | |
35 | 262 | let full_stats = |μ : &RNDM<F, N>, ε, stats| IterInfo { |
263 | value : dataterm.calculate_fit_op(μ, opA, b) + reg.apply(μ), | |
264 | n_spikes : μ.len(), | |
265 | ε, | |
266 | // postprocessing: config.postprocessing.then(|| μ.clone()), | |
267 | .. stats | |
268 | }; | |
32 | 269 | let mut stats = IterInfo::new(); |
270 | ||
271 | // Run the algorithm | |
35 | 272 | for state in iterator.iter_init(|| full_stats(&μ, ε, stats.clone())) { |
32 | 273 | // Calculate smooth part of surrogate model. |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
274 | let mut τv = opA.preadjoint().apply(y * τ); |
32 | 275 | |
276 | // Save current base point | |
277 | let μ_base = μ.clone(); | |
278 | ||
279 | // Insert and reweigh | |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
280 | let (maybe_d, _within_tolerances) = prox_penalty.insert_and_reweigh( |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
281 | &mut μ, &mut τv, &μ_base, None, |
32 | 282 | τ, ε, |
35 | 283 | config, ®, &state, &mut stats |
32 | 284 | ); |
285 | ||
286 | // Prune and possibly merge spikes | |
35 | 287 | if config.merge_now(&state) { |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
288 | stats.merged += prox_penalty.merge_spikes(&mut μ, &mut τv, &μ_base, τ, ε, config, ®); |
35 | 289 | } |
290 | stats.pruned += prune_with_stats(&mut μ); | |
0 | 291 | |
32 | 292 | // Update step length parameters |
35 | 293 | let ω = pdpsconfig.acceleration.accelerate(&mut τ, &mut σ, γ); |
32 | 294 | |
295 | // Do dual update | |
296 | y = b.clone(); // y = b | |
297 | opA.gemv(&mut y, 1.0 + ω, &μ, -1.0); // y = A[(1+ω)μ^{k+1}]-b | |
298 | opA.gemv(&mut y, -ω, &μ_base, 1.0); // y = A[(1+ω)μ^{k+1} - ω μ^k]-b | |
299 | dataterm.dual_update(&mut y, &y_prev, σ); | |
300 | y_prev.copy_from(&y); | |
0 | 301 | |
35 | 302 | // Give statistics if requested |
303 | let iter = state.iteration(); | |
32 | 304 | stats.this_iters += 1; |
305 | ||
306 | state.if_verbose(|| { | |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
307 | plotter.plot_spikes(iter, maybe_d.as_ref(), Some(&τv), &μ); |
35 | 308 | full_stats(&μ, ε, std::mem::replace(&mut stats, IterInfo::new())) |
309 | }); | |
310 | ||
311 | ε = tolerance.update(ε, iter); | |
312 | } | |
32 | 313 | |
314 | postprocess(μ, config, dataterm, opA, b) | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
315 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
316 |