Thu, 23 Jan 2025 23:34:05 +0100
Merging adjustments, parameter tuning, etc.
0 | 1 | /*! |
2 | Solver for the point source localisation problem using a forward-backward splitting method. | |
3 | ||
4 | This corresponds to the manuscript | |
5 | ||
13
bdc57366d4f5
arXiv links, README beautification
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
6 | * Valkonen T. - _Proximal methods for point source localisation_, |
bdc57366d4f5
arXiv links, README beautification
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
7 | [arXiv:2212.02991](https://arxiv.org/abs/2212.02991). |
0 | 8 | |
35 | 9 | The main routine is [`pointsource_fb_reg`]. |
0 | 10 | |
11 | ## Problem | |
12 | ||
13 | <p> | |
14 | Our objective is to solve | |
15 | $$ | |
16 | \min_{μ ∈ ℳ(Ω)}~ F_0(Aμ-b) + α \|μ\|_{ℳ(Ω)} + δ_{≥ 0}(μ), | |
17 | $$ | |
18 | where $F_0(y)=\frac{1}{2}\|y\|_2^2$ and the forward operator $A \in 𝕃(ℳ(Ω); ℝ^n)$. | |
19 | </p> | |
20 | ||
21 | ## Approach | |
22 | ||
23 | <p> | |
24 | As documented in more detail in the paper, on each step we approximately solve | |
25 | $$ | |
26 | \min_{μ ∈ ℳ(Ω)}~ F(x) + α \|μ\|_{ℳ(Ω)} + δ_{≥ 0}(x) + \frac{1}{2}\|μ-μ^k|_𝒟^2, | |
27 | $$ | |
28 | where $𝒟: 𝕃(ℳ(Ω); C_c(Ω))$ is typically a convolution operator. | |
29 | </p> | |
30 | ||
31 | ## Finite-dimensional subproblems. | |
32 | ||
33 | With $C$ a projection from [`DiscreteMeasure`] to the weights, and $x^k$ such that $x^k=Cμ^k$, we | |
34 | form the discretised linearised inner problem | |
35 | <p> | |
36 | $$ | |
37 | \min_{x ∈ ℝ^n}~ τ\bigl(F(Cx^k) + [C^*∇F(Cx^k)]^⊤(x-x^k) + α {\vec 1}^⊤ x\bigr) | |
38 | + δ_{≥ 0}(x) + \frac{1}{2}\|x-x^k\|_{C^*𝒟C}^2, | |
39 | $$ | |
40 | equivalently | |
41 | $$ | |
42 | \begin{aligned} | |
43 | \min_x~ & τF(Cx^k) - τ[C^*∇F(Cx^k)]^⊤x^k + \frac{1}{2} (x^k)^⊤ C^*𝒟C x^k | |
44 | \\ | |
45 | & | |
46 | - [C^*𝒟C x^k - τC^*∇F(Cx^k)]^⊤ x | |
47 | \\ | |
48 | & | |
49 | + \frac{1}{2} x^⊤ C^*𝒟C x | |
50 | + τα {\vec 1}^⊤ x + δ_{≥ 0}(x), | |
51 | \end{aligned} | |
52 | $$ | |
53 | In other words, we obtain the quadratic non-negativity constrained problem | |
54 | $$ | |
55 | \min_{x ∈ ℝ^n}~ \frac{1}{2} x^⊤ Ã x - b̃^⊤ x + c + τα {\vec 1}^⊤ x + δ_{≥ 0}(x). | |
56 | $$ | |
57 | where | |
58 | $$ | |
59 | \begin{aligned} | |
60 | Ã & = C^*𝒟C, | |
61 | \\ | |
62 | g̃ & = C^*𝒟C x^k - τ C^*∇F(Cx^k) | |
63 | = C^* 𝒟 μ^k - τ C^*A^*(Aμ^k - b) | |
64 | \\ | |
65 | c & = τ F(Cx^k) - τ[C^*∇F(Cx^k)]^⊤x^k + \frac{1}{2} (x^k)^⊤ C^*𝒟C x^k | |
66 | \\ | |
67 | & | |
68 | = \frac{τ}{2} \|Aμ^k-b\|^2 - τ[Aμ^k-b]^⊤Aμ^k + \frac{1}{2} \|μ_k\|_{𝒟}^2 | |
69 | \\ | |
70 | & | |
71 | = -\frac{τ}{2} \|Aμ^k-b\|^2 + τ[Aμ^k-b]^⊤ b + \frac{1}{2} \|μ_k\|_{𝒟}^2. | |
72 | \end{aligned} | |
73 | $$ | |
74 | </p> | |
75 | ||
35 | 76 | We solve this with either SSN or FB as determined by |
0 | 77 | [`InnerSettings`] in [`FBGenericConfig::inner`]. |
78 | */ | |
79 | ||
80 | use numeric_literals::replace_float_literals; | |
81 | use serde::{Serialize, Deserialize}; | |
82 | use colored::Colorize; | |
83 | ||
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
84 | use alg_tools::iterate::AlgIteratorFactory; |
0 | 85 | use alg_tools::euclidean::Euclidean; |
35 | 86 | use alg_tools::linops::{Mapping, GEMV}; |
0 | 87 | use alg_tools::mapping::RealMapping; |
88 | use alg_tools::nalgebra_support::ToNalgebraRealField; | |
35 | 89 | use alg_tools::instance::Instance; |
0 | 90 | |
91 | use crate::types::*; | |
92 | use crate::measures::{ | |
93 | DiscreteMeasure, | |
35 | 94 | RNDM, |
0 | 95 | }; |
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
96 | use crate::measures::merging::SpikeMerging; |
35 | 97 | use crate::forward_model::{ |
98 | ForwardModel, | |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
99 | AdjointProductBoundedBy, |
35 | 100 | }; |
0 | 101 | use crate::plot::{ |
102 | SeqPlotter, | |
103 | Plotting, | |
104 | PlotLookup | |
105 | }; | |
32 | 106 | use crate::regularisation::RegTerm; |
107 | use crate::dataterm::{ | |
108 | calculate_residual, | |
109 | L2Squared, | |
110 | DataTerm, | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
111 | }; |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
112 | pub use crate::prox_penalty::{ |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
113 | FBGenericConfig, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
114 | ProxPenalty |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
115 | }; |
0 | 116 | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
117 | /// Settings for [`pointsource_fb_reg`]. |
0 | 118 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] |
119 | #[serde(default)] | |
120 | pub struct FBConfig<F : Float> { | |
121 | /// Step length scaling | |
122 | pub τ0 : F, | |
123 | /// Generic parameters | |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
124 | pub generic : FBGenericConfig<F>, |
0 | 125 | } |
126 | ||
127 | #[replace_float_literals(F::cast_from(literal))] | |
128 | impl<F : Float> Default for FBConfig<F> { | |
129 | fn default() -> Self { | |
130 | FBConfig { | |
131 | τ0 : 0.99, | |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
132 | generic : Default::default(), |
0 | 133 | } |
134 | } | |
135 | } | |
136 | ||
35 | 137 | pub(crate) fn prune_with_stats<F : Float, const N : usize>( |
138 | μ : &mut RNDM<F, N>, | |
139 | ) -> usize { | |
32 | 140 | let n_before_prune = μ.len(); |
141 | μ.prune(); | |
142 | debug_assert!(μ.len() <= n_before_prune); | |
35 | 143 | n_before_prune - μ.len() |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
144 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
145 | |
32 | 146 | #[replace_float_literals(F::cast_from(literal))] |
147 | pub(crate) fn postprocess< | |
148 | F : Float, | |
149 | V : Euclidean<F> + Clone, | |
35 | 150 | A : GEMV<F, RNDM<F, N>, Codomain = V>, |
32 | 151 | D : DataTerm<F, V, N>, |
152 | const N : usize | |
153 | > ( | |
35 | 154 | mut μ : RNDM<F, N>, |
32 | 155 | config : &FBGenericConfig<F>, |
156 | dataterm : D, | |
157 | opA : &A, | |
158 | b : &V, | |
35 | 159 | ) -> RNDM<F, N> |
160 | where | |
161 | RNDM<F, N> : SpikeMerging<F>, | |
162 | for<'a> &'a RNDM<F, N> : Instance<RNDM<F, N>>, | |
163 | { | |
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
164 | μ.merge_spikes_fitness(config.final_merging_method(), |
32 | 165 | |μ̃| dataterm.calculate_fit_op(μ̃, opA, b), |
166 | |&v| v); | |
167 | μ.prune(); | |
168 | μ | |
169 | } | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
170 | |
32 | 171 | /// Iteratively solve the pointsource localisation problem using forward-backward splitting. |
0 | 172 | /// |
32 | 173 | /// The settings in `config` have their [respective documentation](FBConfig). `opA` is the |
0 | 174 | /// forward operator $A$, $b$ the observable, and $\lambda$ the regularisation weight. |
175 | /// The operator `op𝒟` is used for forming the proximal term. Typically it is a convolution | |
176 | /// operator. Finally, the `iterator` is an outer loop verbosity and iteration count control | |
177 | /// as documented in [`alg_tools::iterate`]. | |
178 | /// | |
32 | 179 | /// For details on the mathematical formulation, see the [module level](self) documentation. |
180 | /// | |
0 | 181 | /// The implementation relies on [`alg_tools::bisection_tree::BTFN`] presentations of |
182 | /// sums of simple functions usign bisection trees, and the related | |
183 | /// [`alg_tools::bisection_tree::Aggregator`]s, to efficiently search for component functions | |
184 | /// active at a specific points, and to maximise their sums. Through the implementation of the | |
185 | /// [`alg_tools::bisection_tree::BT`] bisection trees, it also relies on the copy-on-write features | |
186 | /// of [`std::sync::Arc`] to only update relevant parts of the bisection tree when adding functions. | |
187 | /// | |
188 | /// Returns the final iterate. | |
189 | #[replace_float_literals(F::cast_from(literal))] | |
32 | 190 | pub fn pointsource_fb_reg< |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
191 | F, I, A, Reg, P, const N : usize |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
192 | >( |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
193 | opA : &A, |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
194 | b : &A::Observable, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
195 | reg : Reg, |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
196 | prox_penalty : &P, |
32 | 197 | fbconfig : &FBConfig<F>, |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
198 | iterator : I, |
32 | 199 | mut plotter : SeqPlotter<F, N>, |
35 | 200 | ) -> RNDM<F, N> |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
201 | where |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
202 | F : Float + ToNalgebraRealField, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
203 | I : AlgIteratorFactory<IterInfo<F, N>>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
204 | for<'b> &'b A::Observable : std::ops::Neg<Output=A::Observable>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
205 | A : ForwardModel<RNDM<F, N>, F> |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
206 | + AdjointProductBoundedBy<RNDM<F, N>, P, FloatType=F>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
207 | A::PreadjointCodomain : RealMapping<F, N>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
208 | PlotLookup : Plotting<N>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
209 | RNDM<F, N> : SpikeMerging<F>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
210 | Reg : RegTerm<F, N>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
211 | P : ProxPenalty<F, A::PreadjointCodomain, Reg, N>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
212 | { |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
213 | |
32 | 214 | // Set up parameters |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
215 | let config = &fbconfig.generic; |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
216 | let τ = fbconfig.τ0/opA.adjoint_product_bound(prox_penalty).unwrap(); |
32 | 217 | // We multiply tolerance by τ for FB since our subproblems depending on tolerances are scaled |
218 | // by τ compared to the conditional gradient approach. | |
219 | let tolerance = config.tolerance * τ * reg.tolerance_scaling(); | |
220 | let mut ε = tolerance.initial(); | |
221 | ||
222 | // Initialise iterates | |
223 | let mut μ = DiscreteMeasure::new(); | |
224 | let mut residual = -b; | |
35 | 225 | |
226 | // Statistics | |
227 | let full_stats = |residual : &A::Observable, | |
228 | μ : &RNDM<F, N>, | |
229 | ε, stats| IterInfo { | |
230 | value : residual.norm2_squared_div2() + reg.apply(μ), | |
231 | n_spikes : μ.len(), | |
232 | ε, | |
233 | //postprocessing: config.postprocessing.then(|| μ.clone()), | |
234 | .. stats | |
235 | }; | |
32 | 236 | let mut stats = IterInfo::new(); |
237 | ||
238 | // Run the algorithm | |
35 | 239 | for state in iterator.iter_init(|| full_stats(&residual, &μ, ε, stats.clone())) { |
32 | 240 | // Calculate smooth part of surrogate model. |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
241 | let mut τv = opA.preadjoint().apply(residual * τ); |
32 | 242 | |
243 | // Save current base point | |
244 | let μ_base = μ.clone(); | |
245 | ||
246 | // Insert and reweigh | |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
247 | let (maybe_d, _within_tolerances) = prox_penalty.insert_and_reweigh( |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
248 | &mut μ, &mut τv, &μ_base, None, |
32 | 249 | τ, ε, |
35 | 250 | config, ®, &state, &mut stats |
32 | 251 | ); |
252 | ||
253 | // Prune and possibly merge spikes | |
35 | 254 | if config.merge_now(&state) { |
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
255 | stats.merged += prox_penalty.merge_spikes( |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
256 | &mut μ, &mut τv, &μ_base, None, τ, ε, config, ®, |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
257 | Some(|μ̃ : &RNDM<F, N>| L2Squared.calculate_fit_op(μ̃, opA, b)), |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
258 | ); |
35 | 259 | } |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
260 | |
35 | 261 | stats.pruned += prune_with_stats(&mut μ); |
32 | 262 | |
263 | // Update residual | |
264 | residual = calculate_residual(&μ, opA, b); | |
265 | ||
35 | 266 | let iter = state.iteration(); |
32 | 267 | stats.this_iters += 1; |
268 | ||
35 | 269 | // Give statistics if needed |
32 | 270 | state.if_verbose(|| { |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
271 | plotter.plot_spikes(iter, maybe_d.as_ref(), Some(&τv), &μ); |
35 | 272 | full_stats(&residual, &μ, ε, std::mem::replace(&mut stats, IterInfo::new())) |
273 | }); | |
274 | ||
275 | // Update main tolerance for next iteration | |
276 | ε = tolerance.update(ε, iter); | |
277 | } | |
32 | 278 | |
279 | postprocess(μ, config, L2Squared, opA, b) | |
280 | } | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
281 | |
32 | 282 | /// Iteratively solve the pointsource localisation problem using inertial forward-backward splitting. |
283 | /// | |
284 | /// The settings in `config` have their [respective documentation](FBConfig). `opA` is the | |
285 | /// forward operator $A$, $b$ the observable, and $\lambda$ the regularisation weight. | |
286 | /// The operator `op𝒟` is used for forming the proximal term. Typically it is a convolution | |
287 | /// operator. Finally, the `iterator` is an outer loop verbosity and iteration count control | |
288 | /// as documented in [`alg_tools::iterate`]. | |
289 | /// | |
290 | /// For details on the mathematical formulation, see the [module level](self) documentation. | |
291 | /// | |
292 | /// The implementation relies on [`alg_tools::bisection_tree::BTFN`] presentations of | |
293 | /// sums of simple functions usign bisection trees, and the related | |
294 | /// [`alg_tools::bisection_tree::Aggregator`]s, to efficiently search for component functions | |
295 | /// active at a specific points, and to maximise their sums. Through the implementation of the | |
296 | /// [`alg_tools::bisection_tree::BT`] bisection trees, it also relies on the copy-on-write features | |
297 | /// of [`std::sync::Arc`] to only update relevant parts of the bisection tree when adding functions. | |
298 | /// | |
299 | /// Returns the final iterate. | |
300 | #[replace_float_literals(F::cast_from(literal))] | |
301 | pub fn pointsource_fista_reg< | |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
302 | F, I, A, Reg, P, const N : usize |
32 | 303 | >( |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
304 | opA : &A, |
32 | 305 | b : &A::Observable, |
306 | reg : Reg, | |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
307 | prox_penalty : &P, |
32 | 308 | fbconfig : &FBConfig<F>, |
309 | iterator : I, | |
310 | mut plotter : SeqPlotter<F, N>, | |
35 | 311 | ) -> RNDM<F, N> |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
312 | where |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
313 | F : Float + ToNalgebraRealField, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
314 | I : AlgIteratorFactory<IterInfo<F, N>>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
315 | for<'b> &'b A::Observable : std::ops::Neg<Output=A::Observable>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
316 | A : ForwardModel<RNDM<F, N>, F> |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
317 | + AdjointProductBoundedBy<RNDM<F, N>, P, FloatType=F>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
318 | A::PreadjointCodomain : RealMapping<F, N>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
319 | PlotLookup : Plotting<N>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
320 | RNDM<F, N> : SpikeMerging<F>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
321 | Reg : RegTerm<F, N>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
322 | P : ProxPenalty<F, A::PreadjointCodomain, Reg, N>, |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
323 | { |
32 | 324 | |
325 | // Set up parameters | |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
326 | let config = &fbconfig.generic; |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
327 | let τ = fbconfig.τ0/opA.adjoint_product_bound(prox_penalty).unwrap(); |
32 | 328 | let mut λ = 1.0; |
329 | // We multiply tolerance by τ for FB since our subproblems depending on tolerances are scaled | |
330 | // by τ compared to the conditional gradient approach. | |
331 | let tolerance = config.tolerance * τ * reg.tolerance_scaling(); | |
332 | let mut ε = tolerance.initial(); | |
333 | ||
334 | // Initialise iterates | |
335 | let mut μ = DiscreteMeasure::new(); | |
336 | let mut μ_prev = DiscreteMeasure::new(); | |
337 | let mut residual = -b; | |
35 | 338 | let mut warned_merging = false; |
339 | ||
340 | // Statistics | |
341 | let full_stats = |ν : &RNDM<F, N>, ε, stats| IterInfo { | |
342 | value : L2Squared.calculate_fit_op(ν, opA, b) + reg.apply(ν), | |
343 | n_spikes : ν.len(), | |
344 | ε, | |
345 | // postprocessing: config.postprocessing.then(|| ν.clone()), | |
346 | .. stats | |
347 | }; | |
32 | 348 | let mut stats = IterInfo::new(); |
349 | ||
350 | // Run the algorithm | |
35 | 351 | for state in iterator.iter_init(|| full_stats(&μ, ε, stats.clone())) { |
32 | 352 | // Calculate smooth part of surrogate model. |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
353 | let mut τv = opA.preadjoint().apply(residual * τ); |
32 | 354 | |
355 | // Save current base point | |
356 | let μ_base = μ.clone(); | |
357 | ||
358 | // Insert new spikes and reweigh | |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
359 | let (maybe_d, _within_tolerances) = prox_penalty.insert_and_reweigh( |
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
360 | &mut μ, &mut τv, &μ_base, None, |
32 | 361 | τ, ε, |
35 | 362 | config, ®, &state, &mut stats |
32 | 363 | ); |
364 | ||
365 | // (Do not) merge spikes. | |
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
366 | if config.merge_now(&state) && !warned_merging { |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
367 | let err = format!("Merging not supported for μFISTA"); |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
368 | println!("{}", err.red()); |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
369 | warned_merging = true; |
32 | 370 | } |
371 | ||
372 | // Update inertial prameters | |
373 | let λ_prev = λ; | |
374 | λ = 2.0 * λ_prev / ( λ_prev + (4.0 + λ_prev * λ_prev).sqrt() ); | |
375 | let θ = λ / λ_prev - λ; | |
376 | ||
377 | // Perform inertial update on μ. | |
378 | // This computes μ ← (1 + θ) * μ - θ * μ_prev, pruning spikes where both μ | |
379 | // and μ_prev have zero weight. Since both have weights from the finite-dimensional | |
380 | // subproblem with a proximal projection step, this is likely to happen when the | |
381 | // spike is not needed. A copy of the pruned μ without artithmetic performed is | |
382 | // stored in μ_prev. | |
383 | let n_before_prune = μ.len(); | |
384 | μ.pruning_sub(1.0 + θ, θ, &mut μ_prev); | |
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
385 | //let μ_new = (&μ * (1.0 + θ)).sub_matching(&(&μ_prev * θ)); |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
386 | // μ_prev = μ; |
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
387 | // μ = μ_new; |
32 | 388 | debug_assert!(μ.len() <= n_before_prune); |
389 | stats.pruned += n_before_prune - μ.len(); | |
390 | ||
391 | // Update residual | |
392 | residual = calculate_residual(&μ, opA, b); | |
393 | ||
35 | 394 | let iter = state.iteration(); |
32 | 395 | stats.this_iters += 1; |
396 | ||
35 | 397 | // Give statistics if needed |
32 | 398 | state.if_verbose(|| { |
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
399 | plotter.plot_spikes(iter, maybe_d.as_ref(), Some(&τv), &μ_prev); |
35 | 400 | full_stats(&μ_prev, ε, std::mem::replace(&mut stats, IterInfo::new())) |
401 | }); | |
402 | ||
403 | // Update main tolerance for next iteration | |
404 | ε = tolerance.update(ε, iter); | |
405 | } | |
32 | 406 | |
407 | postprocess(μ_prev, config, L2Squared, opA, b) | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
408 | } |