Tue, 31 Dec 2024 09:34:24 -0500
Early transport sketches
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 | |
9 | The main routine is [`pointsource_pdps`]. It is based on specilisatinn of | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
10 | [`generic_pointsource_fb_reg`] through relevant [`FBSpecialisation`] implementations. |
0 | 11 | Both norm-2-squared and norm-1 data terms are supported. That is, implemented are solvers for |
12 | <div> | |
13 | $$ | |
14 | \min_{μ ∈ ℳ(Ω)}~ F_0(Aμ - b) + α \|μ\|_{ℳ(Ω)} + δ_{≥ 0}(μ), | |
15 | $$ | |
16 | for both $F_0(y)=\frac{1}{2}\|y\|_2^2$ and $F_0(y)=\|y\|_1$ with the forward operator | |
17 | $A \in 𝕃(ℳ(Ω); ℝ^n)$. | |
18 | </div> | |
19 | ||
20 | ## Approach | |
21 | ||
22 | <p> | |
23 | The problem above can be written as | |
24 | $$ | |
25 | \min_μ \max_y G(μ) + ⟨y, Aμ-b⟩ - F_0^*(μ), | |
26 | $$ | |
27 | where $G(μ) = α \|μ\|_{ℳ(Ω)} + δ_{≥ 0}(μ)$. | |
28 | The Fenchel–Rockafellar optimality conditions, employing the predual in $ℳ(Ω)$, are | |
29 | $$ | |
30 | 0 ∈ A_*y + ∂G(μ) | |
31 | \quad\text{and}\quad | |
32 | Aμ - b ∈ ∂ F_0^*(y). | |
33 | $$ | |
34 | The solution of the first part is as for forward-backward, treated in the manuscript. | |
35 | This is the task of <code>generic_pointsource_fb</code>, where we use <code>FBSpecialisation</code> | |
36 | to replace the specific residual $Aμ-b$ by $y$. | |
37 | For $F_0(y)=\frac{1}{2}\|y\|_2^2$ the second part reads $y = Aμ -b$. | |
38 | For $F_0(y)=\|y\|_1$ the second part reads $y ∈ ∂\|·\|_1(Aμ - b)$. | |
39 | </p> | |
40 | ||
41 | Based on zero initialisation for $μ$, we use the [`Subdifferentiable`] trait to make an | |
42 | initialisation corresponding to the second part of the optimality conditions. | |
43 | In the algorithm itself, standard proximal steps are taking with respect to $F\_0^* + ⟨b, ·⟩$. | |
44 | */ | |
45 | ||
46 | use numeric_literals::replace_float_literals; | |
47 | use serde::{Serialize, Deserialize}; | |
48 | use nalgebra::DVector; | |
49 | use clap::ValueEnum; | |
50 | ||
32 | 51 | use alg_tools::iterate::{ |
52 | AlgIteratorFactory, | |
53 | AlgIteratorState, | |
54 | }; | |
0 | 55 | use alg_tools::loc::Loc; |
56 | use alg_tools::euclidean::Euclidean; | |
32 | 57 | use alg_tools::linops::Apply; |
0 | 58 | use alg_tools::norms::{ |
32 | 59 | Linfinity, |
60 | Projection, | |
0 | 61 | }; |
62 | use alg_tools::bisection_tree::{ | |
63 | BTFN, | |
64 | PreBTFN, | |
65 | Bounds, | |
66 | BTNodeLookup, | |
67 | BTNode, | |
68 | BTSearch, | |
69 | SupportGenerator, | |
70 | LocalAnalysis, | |
71 | }; | |
72 | use alg_tools::mapping::RealMapping; | |
73 | use alg_tools::nalgebra_support::ToNalgebraRealField; | |
74 | use alg_tools::linops::AXPY; | |
75 | ||
76 | use crate::types::*; | |
77 | use crate::measures::DiscreteMeasure; | |
32 | 78 | use crate::measures::merging::SpikeMerging; |
0 | 79 | use crate::forward_model::ForwardModel; |
32 | 80 | use crate::seminorms::DiscreteMeasureOp; |
0 | 81 | use crate::plot::{ |
82 | SeqPlotter, | |
83 | Plotting, | |
84 | PlotLookup | |
85 | }; | |
86 | use crate::fb::{ | |
87 | FBGenericConfig, | |
32 | 88 | insert_and_reweigh, |
89 | postprocess, | |
90 | prune_and_maybe_simple_merge | |
91 | }; | |
92 | use crate::regularisation::RegTerm; | |
93 | use crate::dataterm::{ | |
94 | DataTerm, | |
95 | L2Squared, | |
96 | L1 | |
0 | 97 | }; |
98 | ||
99 | /// Acceleration | |
100 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, ValueEnum, Debug)] | |
101 | pub enum Acceleration { | |
102 | /// No acceleration | |
103 | #[clap(name = "none")] | |
104 | None, | |
105 | /// Partial acceleration, $ω = 1/\sqrt{1+σ}$ | |
106 | #[clap(name = "partial", help = "Partial acceleration, ω = 1/√(1+σ)")] | |
107 | Partial, | |
108 | /// Full acceleration, $ω = 1/\sqrt{1+2σ}$; no gap convergence guaranteed | |
109 | #[clap(name = "full", help = "Full acceleration, ω = 1/√(1+2σ); no gap convergence guaranteed")] | |
110 | Full | |
111 | } | |
112 | ||
113 | /// Settings for [`pointsource_pdps`]. | |
114 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] | |
115 | #[serde(default)] | |
116 | pub struct PDPSConfig<F : Float> { | |
117 | /// Primal step length scaling. We must have `τ0 * σ0 < 1`. | |
118 | pub τ0 : F, | |
119 | /// Dual step length scaling. We must have `τ0 * σ0 < 1`. | |
120 | pub σ0 : F, | |
121 | /// Accelerate if available | |
122 | pub acceleration : Acceleration, | |
123 | /// Generic parameters | |
124 | pub insertion : FBGenericConfig<F>, | |
125 | } | |
126 | ||
127 | #[replace_float_literals(F::cast_from(literal))] | |
128 | impl<F : Float> Default for PDPSConfig<F> { | |
129 | fn default() -> Self { | |
130 | let τ0 = 0.5; | |
131 | PDPSConfig { | |
132 | τ0, | |
133 | σ0 : 0.99/τ0, | |
134 | acceleration : Acceleration::Partial, | |
135 | insertion : Default::default() | |
136 | } | |
137 | } | |
138 | } | |
139 | ||
32 | 140 | /// Trait for data terms for the PDPS |
141 | #[replace_float_literals(F::cast_from(literal))] | |
142 | pub trait PDPSDataTerm<F : Float, V, const N : usize> : DataTerm<F, V, N> { | |
143 | /// Calculate some subdifferential at `x` for the conjugate | |
144 | fn some_subdifferential(&self, x : V) -> V; | |
145 | ||
146 | /// Factor of strong convexity of the conjugate | |
147 | #[inline] | |
148 | fn factor_of_strong_convexity(&self) -> F { | |
149 | 0.0 | |
150 | } | |
151 | ||
152 | /// Perform dual update | |
153 | fn dual_update(&self, _y : &mut V, _y_prev : &V, _σ : F); | |
0 | 154 | } |
155 | ||
32 | 156 | |
157 | #[replace_float_literals(F::cast_from(literal))] | |
158 | impl<F : Float, V : Euclidean<F> + AXPY<F>, const N : usize> | |
159 | PDPSDataTerm<F, V, N> | |
160 | for L2Squared { | |
161 | fn some_subdifferential(&self, x : V) -> V { x } | |
0 | 162 | |
32 | 163 | fn factor_of_strong_convexity(&self) -> F { |
164 | 1.0 | |
165 | } | |
166 | ||
167 | #[inline] | |
168 | fn dual_update(&self, y : &mut V, y_prev : &V, σ : F) { | |
169 | y.axpy(1.0 / (1.0 + σ), &y_prev, σ / (1.0 + σ)); | |
170 | } | |
0 | 171 | } |
172 | ||
32 | 173 | #[replace_float_literals(F::cast_from(literal))] |
174 | impl<F : Float + nalgebra::RealField, const N : usize> | |
175 | PDPSDataTerm<F, DVector<F>, N> | |
176 | for L1 { | |
0 | 177 | fn some_subdifferential(&self, mut x : DVector<F>) -> DVector<F> { |
178 | // nalgebra sucks for providing second copies of the same stuff that's elsewhere as well. | |
179 | x.iter_mut() | |
180 | .for_each(|v| if *v != F::ZERO { *v = *v/<F as NumTraitsFloat>::abs(*v) }); | |
181 | x | |
182 | } | |
183 | ||
32 | 184 | #[inline] |
185 | fn dual_update(&self, y : &mut DVector<F>, y_prev : &DVector<F>, σ : F) { | |
186 | y.axpy(1.0, y_prev, σ); | |
0 | 187 | y.proj_ball_mut(1.0, Linfinity); |
188 | } | |
189 | } | |
190 | ||
191 | /// Iteratively solve the pointsource localisation problem using primal-dual proximal splitting. | |
192 | /// | |
193 | /// The `dataterm` should be either [`L1`] for norm-1 data term or [`L2Squared`] for norm-2-squared. | |
194 | /// The settings in `config` have their [respective documentation](PDPSConfig). `opA` is the | |
195 | /// forward operator $A$, $b$ the observable, and $\lambda$ the regularisation weight. | |
196 | /// The operator `op𝒟` is used for forming the proximal term. Typically it is a convolution | |
197 | /// operator. Finally, the `iterator` is an outer loop verbosity and iteration count control | |
198 | /// as documented in [`alg_tools::iterate`]. | |
199 | /// | |
200 | /// For the mathematical formulation, see the [module level](self) documentation and the manuscript. | |
201 | /// | |
202 | /// Returns the final iterate. | |
203 | #[replace_float_literals(F::cast_from(literal))] | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
204 | pub fn pointsource_pdps_reg<'a, F, I, A, GA, 𝒟, BTA, G𝒟, S, K, D, Reg, const N : usize>( |
0 | 205 | opA : &'a A, |
206 | b : &'a A::Observable, | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
207 | reg : Reg, |
0 | 208 | op𝒟 : &'a 𝒟, |
32 | 209 | pdpsconfig : &PDPSConfig<F>, |
0 | 210 | iterator : I, |
32 | 211 | mut plotter : SeqPlotter<F, N>, |
0 | 212 | dataterm : D, |
213 | ) -> DiscreteMeasure<Loc<F, N>, F> | |
214 | where F : Float + ToNalgebraRealField, | |
215 | I : AlgIteratorFactory<IterInfo<F, N>>, | |
216 | for<'b> &'b A::Observable : std::ops::Neg<Output=A::Observable> | |
217 | + std::ops::Add<A::Observable, Output=A::Observable>, | |
218 | //+ std::ops::Mul<F, Output=A::Observable>, // <-- FIXME: compiler overflow | |
219 | A::Observable : std::ops::MulAssign<F>, | |
220 | GA : SupportGenerator<F, N, SupportType = S, Id = usize> + Clone, | |
221 | A : ForwardModel<Loc<F, N>, F, PreadjointCodomain = BTFN<F, GA, BTA, N>> | |
32 | 222 | + Lipschitz<&'a 𝒟, FloatType=F>, |
0 | 223 | BTA : BTSearch<F, N, Data=usize, Agg=Bounds<F>>, |
224 | G𝒟 : SupportGenerator<F, N, SupportType = K, Id = usize> + Clone, | |
225 | 𝒟 : DiscreteMeasureOp<Loc<F, N>, F, PreCodomain = PreBTFN<F, G𝒟, N>>, | |
226 | 𝒟::Codomain : RealMapping<F, N>, | |
227 | S: RealMapping<F, N> + LocalAnalysis<F, Bounds<F>, N>, | |
228 | K: RealMapping<F, N> + LocalAnalysis<F, Bounds<F>, N>, | |
229 | BTNodeLookup: BTNode<F, usize, Bounds<F>, N>, | |
230 | PlotLookup : Plotting<N>, | |
231 | DiscreteMeasure<Loc<F, N>, F> : SpikeMerging<F>, | |
32 | 232 | D : PDPSDataTerm<F, A::Observable, N>, |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
233 | Reg : RegTerm<F, N> { |
0 | 234 | |
32 | 235 | // Set up parameters |
236 | let config = &pdpsconfig.insertion; | |
237 | let op𝒟norm = op𝒟.opnorm_bound(); | |
0 | 238 | let l = opA.lipschitz_factor(&op𝒟).unwrap().sqrt(); |
32 | 239 | let mut τ = pdpsconfig.τ0 / l; |
240 | let mut σ = pdpsconfig.σ0 / l; | |
241 | let γ = dataterm.factor_of_strong_convexity(); | |
242 | ||
243 | // We multiply tolerance by τ for FB since our subproblems depending on tolerances are scaled | |
244 | // by τ compared to the conditional gradient approach. | |
245 | let tolerance = config.tolerance * τ * reg.tolerance_scaling(); | |
246 | let mut ε = tolerance.initial(); | |
247 | ||
248 | // Initialise iterates | |
249 | let mut μ = DiscreteMeasure::new(); | |
250 | let mut y = dataterm.some_subdifferential(-b); | |
251 | let mut y_prev = y.clone(); | |
252 | let mut stats = IterInfo::new(); | |
253 | ||
254 | // Run the algorithm | |
255 | iterator.iterate(|state| { | |
256 | // Calculate smooth part of surrogate model. | |
257 | // Using `std::mem::replace` here is not ideal, and expects that `empty_observable` | |
258 | // has no significant overhead. For some reosn Rust doesn't allow us simply moving | |
259 | // the residual and replacing it below before the end of this closure. | |
260 | y *= -τ; | |
261 | let r = std::mem::replace(&mut y, opA.empty_observable()); | |
262 | let minus_τv = opA.preadjoint().apply(r); | |
263 | ||
264 | // Save current base point | |
265 | let μ_base = μ.clone(); | |
266 | ||
267 | // Insert and reweigh | |
268 | let (d, within_tolerances) = insert_and_reweigh( | |
269 | &mut μ, &minus_τv, &μ_base, None, | |
270 | op𝒟, op𝒟norm, | |
271 | τ, ε, | |
272 | config, ®, state, &mut stats | |
273 | ); | |
274 | ||
275 | // Prune and possibly merge spikes | |
276 | prune_and_maybe_simple_merge( | |
277 | &mut μ, &minus_τv, &μ_base, | |
278 | op𝒟, | |
279 | τ, ε, | |
280 | config, ®, state, &mut stats | |
281 | ); | |
0 | 282 | |
32 | 283 | // Update step length parameters |
284 | let ω = match pdpsconfig.acceleration { | |
285 | Acceleration::None => 1.0, | |
286 | Acceleration::Partial => { | |
287 | let ω = 1.0 / (1.0 + γ * σ).sqrt(); | |
288 | σ = σ * ω; | |
289 | τ = τ / ω; | |
290 | ω | |
291 | }, | |
292 | Acceleration::Full => { | |
293 | let ω = 1.0 / (1.0 + 2.0 * γ * σ).sqrt(); | |
294 | σ = σ * ω; | |
295 | τ = τ / ω; | |
296 | ω | |
297 | }, | |
298 | }; | |
299 | ||
300 | // Do dual update | |
301 | y = b.clone(); // y = b | |
302 | opA.gemv(&mut y, 1.0 + ω, &μ, -1.0); // y = A[(1+ω)μ^{k+1}]-b | |
303 | opA.gemv(&mut y, -ω, &μ_base, 1.0); // y = A[(1+ω)μ^{k+1} - ω μ^k]-b | |
304 | dataterm.dual_update(&mut y, &y_prev, σ); | |
305 | y_prev.copy_from(&y); | |
0 | 306 | |
32 | 307 | // Update main tolerance for next iteration |
308 | let ε_prev = ε; | |
309 | ε = tolerance.update(ε, state.iteration()); | |
310 | stats.this_iters += 1; | |
311 | ||
312 | // Give function value if needed | |
313 | state.if_verbose(|| { | |
314 | // Plot if so requested | |
315 | plotter.plot_spikes( | |
316 | format!("iter {} end; {}", state.iteration(), within_tolerances), &d, | |
317 | "start".to_string(), Some(&minus_τv), | |
318 | reg.target_bounds(τ, ε_prev), &μ, | |
319 | ); | |
320 | // Calculate mean inner iterations and reset relevant counters. | |
321 | // Return the statistics | |
322 | let res = IterInfo { | |
323 | value : dataterm.calculate_fit_op(&μ, opA, b) + reg.apply(&μ), | |
324 | n_spikes : μ.len(), | |
325 | ε : ε_prev, | |
326 | postprocessing: config.postprocessing.then(|| μ.clone()), | |
327 | .. stats | |
328 | }; | |
329 | stats = IterInfo::new(); | |
330 | res | |
331 | }) | |
332 | }); | |
333 | ||
334 | 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
|
335 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
336 |