Thu, 23 Jan 2025 23:34:05 +0100
Merging adjustments, parameter tuning, etc.
| 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 | }; |
|
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
83 | use crate::measures::merging::SpikeMergingMethod; |
|
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
84 | |
| 0 | 85 | |
| 86 | /// Acceleration | |
| 87 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, ValueEnum, Debug)] | |
| 88 | pub enum Acceleration { | |
| 89 | /// No acceleration | |
| 90 | #[clap(name = "none")] | |
| 91 | None, | |
| 92 | /// Partial acceleration, $ω = 1/\sqrt{1+σ}$ | |
| 93 | #[clap(name = "partial", help = "Partial acceleration, ω = 1/√(1+σ)")] | |
| 94 | Partial, | |
| 95 | /// Full acceleration, $ω = 1/\sqrt{1+2σ}$; no gap convergence guaranteed | |
| 96 | #[clap(name = "full", help = "Full acceleration, ω = 1/√(1+2σ); no gap convergence guaranteed")] | |
| 97 | Full | |
| 98 | } | |
| 99 | ||
| 35 | 100 | #[replace_float_literals(F::cast_from(literal))] |
| 101 | impl Acceleration { | |
| 102 | /// PDPS parameter acceleration. Updates τ and σ and returns ω. | |
| 103 | /// This uses dual strong convexity, not primal. | |
| 104 | fn accelerate<F : Float>(self, τ : &mut F, σ : &mut F, γ : F) -> F { | |
| 105 | match self { | |
| 106 | Acceleration::None => 1.0, | |
| 107 | Acceleration::Partial => { | |
| 108 | let ω = 1.0 / (1.0 + γ * (*σ)).sqrt(); | |
| 109 | *σ *= ω; | |
| 110 | *τ /= ω; | |
| 111 | ω | |
| 112 | }, | |
| 113 | Acceleration::Full => { | |
| 114 | let ω = 1.0 / (1.0 + 2.0 * γ * (*σ)).sqrt(); | |
| 115 | *σ *= ω; | |
| 116 | *τ /= ω; | |
| 117 | ω | |
| 118 | }, | |
| 119 | } | |
| 120 | } | |
| 121 | } | |
| 122 | ||
| 123 | /// Settings for [`pointsource_pdps_reg`]. | |
| 0 | 124 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] |
| 125 | #[serde(default)] | |
| 126 | pub struct PDPSConfig<F : Float> { | |
| 127 | /// Primal step length scaling. We must have `τ0 * σ0 < 1`. | |
| 128 | pub τ0 : F, | |
| 129 | /// Dual step length scaling. We must have `τ0 * σ0 < 1`. | |
| 130 | pub σ0 : F, | |
| 131 | /// Accelerate if available | |
| 132 | pub acceleration : Acceleration, | |
| 133 | /// Generic parameters | |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
134 | pub generic : FBGenericConfig<F>, |
| 0 | 135 | } |
| 136 | ||
| 137 | #[replace_float_literals(F::cast_from(literal))] | |
| 138 | impl<F : Float> Default for PDPSConfig<F> { | |
| 139 | fn default() -> Self { | |
|
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
140 | let τ0 = 5.0; |
| 0 | 141 | PDPSConfig { |
| 142 | τ0, | |
| 143 | σ0 : 0.99/τ0, | |
| 144 | acceleration : Acceleration::Partial, | |
|
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
145 | generic : FBGenericConfig { |
|
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
146 | merging : SpikeMergingMethod { enabled : true, ..Default::default() }, |
|
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
147 | .. Default::default() |
|
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
148 | }, |
| 0 | 149 | } |
| 150 | } | |
| 151 | } | |
| 152 | ||
| 32 | 153 | /// Trait for data terms for the PDPS |
| 154 | #[replace_float_literals(F::cast_from(literal))] | |
| 155 | pub trait PDPSDataTerm<F : Float, V, const N : usize> : DataTerm<F, V, N> { | |
| 156 | /// Calculate some subdifferential at `x` for the conjugate | |
| 157 | fn some_subdifferential(&self, x : V) -> V; | |
| 158 | ||
| 159 | /// Factor of strong convexity of the conjugate | |
| 160 | #[inline] | |
| 161 | fn factor_of_strong_convexity(&self) -> F { | |
| 162 | 0.0 | |
| 163 | } | |
| 164 | ||
| 165 | /// Perform dual update | |
| 166 | fn dual_update(&self, _y : &mut V, _y_prev : &V, _σ : F); | |
| 0 | 167 | } |
| 168 | ||
| 32 | 169 | |
| 170 | #[replace_float_literals(F::cast_from(literal))] | |
| 35 | 171 | impl<F, V, const N : usize> PDPSDataTerm<F, V, N> |
| 172 | for L2Squared | |
| 173 | where | |
| 174 | F : Float, | |
| 175 | V : Euclidean<F> + AXPY<F>, | |
| 176 | for<'b> &'b V : Instance<V>, | |
| 177 | { | |
| 32 | 178 | fn some_subdifferential(&self, x : V) -> V { x } |
| 0 | 179 | |
| 32 | 180 | fn factor_of_strong_convexity(&self) -> F { |
| 181 | 1.0 | |
| 182 | } | |
| 183 | ||
| 184 | #[inline] | |
| 185 | fn dual_update(&self, y : &mut V, y_prev : &V, σ : F) { | |
| 35 | 186 | y.axpy(1.0 / (1.0 + σ), y_prev, σ / (1.0 + σ)); |
| 32 | 187 | } |
| 0 | 188 | } |
| 189 | ||
| 32 | 190 | #[replace_float_literals(F::cast_from(literal))] |
| 191 | impl<F : Float + nalgebra::RealField, const N : usize> | |
| 192 | PDPSDataTerm<F, DVector<F>, N> | |
| 193 | for L1 { | |
| 0 | 194 | fn some_subdifferential(&self, mut x : DVector<F>) -> DVector<F> { |
| 195 | // nalgebra sucks for providing second copies of the same stuff that's elsewhere as well. | |
| 196 | x.iter_mut() | |
| 197 | .for_each(|v| if *v != F::ZERO { *v = *v/<F as NumTraitsFloat>::abs(*v) }); | |
| 198 | x | |
| 199 | } | |
| 200 | ||
| 32 | 201 | #[inline] |
| 202 | fn dual_update(&self, y : &mut DVector<F>, y_prev : &DVector<F>, σ : F) { | |
| 203 | y.axpy(1.0, y_prev, σ); | |
| 0 | 204 | y.proj_ball_mut(1.0, Linfinity); |
| 205 | } | |
| 206 | } | |
| 207 | ||
| 208 | /// Iteratively solve the pointsource localisation problem using primal-dual proximal splitting. | |
| 209 | /// | |
| 210 | /// The `dataterm` should be either [`L1`] for norm-1 data term or [`L2Squared`] for norm-2-squared. | |
| 211 | /// The settings in `config` have their [respective documentation](PDPSConfig). `opA` is the | |
| 212 | /// forward operator $A$, $b$ the observable, and $\lambda$ the regularisation weight. | |
| 213 | /// The operator `op𝒟` is used for forming the proximal term. Typically it is a convolution | |
| 214 | /// operator. Finally, the `iterator` is an outer loop verbosity and iteration count control | |
| 215 | /// as documented in [`alg_tools::iterate`]. | |
| 216 | /// | |
| 217 | /// For the mathematical formulation, see the [module level](self) documentation and the manuscript. | |
| 218 | /// | |
| 219 | /// Returns the final iterate. | |
| 220 | #[replace_float_literals(F::cast_from(literal))] | |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
221 | 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
|
222 | opA : &A, |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
223 | b : &A::Observable, |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
224 | reg : Reg, |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
225 | prox_penalty : &P, |
| 32 | 226 | pdpsconfig : &PDPSConfig<F>, |
| 0 | 227 | iterator : I, |
| 32 | 228 | mut plotter : SeqPlotter<F, N>, |
| 0 | 229 | dataterm : D, |
| 35 | 230 | ) -> RNDM<F, N> |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
231 | where |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
232 | F : Float + ToNalgebraRealField, |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
233 | I : AlgIteratorFactory<IterInfo<F, N>>, |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
234 | A : ForwardModel<RNDM<F, N>, F> |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
235 | + AdjointProductBoundedBy<RNDM<F, N>, P, FloatType=F>, |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
236 | A::PreadjointCodomain : RealMapping<F, N>, |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
237 | 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
|
238 | PlotLookup : Plotting<N>, |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
239 | RNDM<F, N> : SpikeMerging<F>, |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
240 | D : PDPSDataTerm<F, A::Observable, N>, |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
241 | Reg : RegTerm<F, N>, |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
242 | P : ProxPenalty<F, A::PreadjointCodomain, Reg, N>, |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
243 | { |
| 0 | 244 | |
| 35 | 245 | // Check parameters |
| 246 | assert!(pdpsconfig.τ0 > 0.0 && | |
| 247 | pdpsconfig.σ0 > 0.0 && | |
| 248 | pdpsconfig.τ0 * pdpsconfig.σ0 <= 1.0, | |
| 249 | "Invalid step length parameters"); | |
| 250 | ||
| 32 | 251 | // Set up parameters |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
252 | let config = &pdpsconfig.generic; |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
253 | let l = opA.adjoint_product_bound(prox_penalty).unwrap().sqrt(); |
| 32 | 254 | let mut τ = pdpsconfig.τ0 / l; |
| 255 | let mut σ = pdpsconfig.σ0 / l; | |
| 256 | let γ = dataterm.factor_of_strong_convexity(); | |
| 257 | ||
| 258 | // We multiply tolerance by τ for FB since our subproblems depending on tolerances are scaled | |
| 259 | // by τ compared to the conditional gradient approach. | |
| 260 | let tolerance = config.tolerance * τ * reg.tolerance_scaling(); | |
| 261 | let mut ε = tolerance.initial(); | |
| 262 | ||
| 263 | // Initialise iterates | |
| 264 | let mut μ = DiscreteMeasure::new(); | |
| 265 | let mut y = dataterm.some_subdifferential(-b); | |
| 266 | let mut y_prev = y.clone(); | |
| 35 | 267 | let full_stats = |μ : &RNDM<F, N>, ε, stats| IterInfo { |
| 268 | value : dataterm.calculate_fit_op(μ, opA, b) + reg.apply(μ), | |
| 269 | n_spikes : μ.len(), | |
| 270 | ε, | |
| 271 | // postprocessing: config.postprocessing.then(|| μ.clone()), | |
| 272 | .. stats | |
| 273 | }; | |
| 32 | 274 | let mut stats = IterInfo::new(); |
| 275 | ||
| 276 | // Run the algorithm | |
| 35 | 277 | for state in iterator.iter_init(|| full_stats(&μ, ε, stats.clone())) { |
| 32 | 278 | // Calculate smooth part of surrogate model. |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
279 | let mut τv = opA.preadjoint().apply(y * τ); |
| 32 | 280 | |
| 281 | // Save current base point | |
| 282 | let μ_base = μ.clone(); | |
| 283 | ||
| 284 | // Insert and reweigh | |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
285 | let (maybe_d, _within_tolerances) = prox_penalty.insert_and_reweigh( |
|
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
286 | &mut μ, &mut τv, &μ_base, None, |
| 32 | 287 | τ, ε, |
| 35 | 288 | config, ®, &state, &mut stats |
| 32 | 289 | ); |
| 290 | ||
| 291 | // Prune and possibly merge spikes | |
| 35 | 292 | if config.merge_now(&state) { |
|
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
293 | stats.merged += prox_penalty.merge_spikes_no_fitness( |
|
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
294 | &mut μ, &mut τv, &μ_base, None, τ, ε, config, ®, |
|
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
295 | ); |
| 35 | 296 | } |
| 297 | stats.pruned += prune_with_stats(&mut μ); | |
| 0 | 298 | |
| 32 | 299 | // Update step length parameters |
| 35 | 300 | let ω = pdpsconfig.acceleration.accelerate(&mut τ, &mut σ, γ); |
| 32 | 301 | |
| 302 | // Do dual update | |
| 303 | y = b.clone(); // y = b | |
| 304 | opA.gemv(&mut y, 1.0 + ω, &μ, -1.0); // y = A[(1+ω)μ^{k+1}]-b | |
| 305 | opA.gemv(&mut y, -ω, &μ_base, 1.0); // y = A[(1+ω)μ^{k+1} - ω μ^k]-b | |
| 306 | dataterm.dual_update(&mut y, &y_prev, σ); | |
| 307 | y_prev.copy_from(&y); | |
| 0 | 308 | |
| 35 | 309 | // Give statistics if requested |
| 310 | let iter = state.iteration(); | |
| 32 | 311 | stats.this_iters += 1; |
| 312 | ||
| 313 | state.if_verbose(|| { | |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
314 | plotter.plot_spikes(iter, maybe_d.as_ref(), Some(&τv), &μ); |
| 35 | 315 | full_stats(&μ, ε, std::mem::replace(&mut stats, IterInfo::new())) |
| 316 | }); | |
| 317 | ||
| 318 | ε = tolerance.update(ε, iter); | |
| 319 | } | |
| 32 | 320 | |
| 321 | 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
|
322 | } |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
323 |