Mon, 05 Dec 2022 23:50:22 +0200
Zenodo packaging hacks
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 | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
9 | The main routine is [`pointsource_fb_reg`]. It is based on [`generic_pointsource_fb_reg`], which is |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
10 | also used by our [primal-dual proximal splitting][crate::pdps] implementation. |
0 | 11 | |
12 | FISTA-type inertia can also be enabled through [`FBConfig::meta`]. | |
13 | ||
14 | ## Problem | |
15 | ||
16 | <p> | |
17 | Our objective is to solve | |
18 | $$ | |
19 | \min_{μ ∈ ℳ(Ω)}~ F_0(Aμ-b) + α \|μ\|_{ℳ(Ω)} + δ_{≥ 0}(μ), | |
20 | $$ | |
21 | where $F_0(y)=\frac{1}{2}\|y\|_2^2$ and the forward operator $A \in 𝕃(ℳ(Ω); ℝ^n)$. | |
22 | </p> | |
23 | ||
24 | ## Approach | |
25 | ||
26 | <p> | |
27 | As documented in more detail in the paper, on each step we approximately solve | |
28 | $$ | |
29 | \min_{μ ∈ ℳ(Ω)}~ F(x) + α \|μ\|_{ℳ(Ω)} + δ_{≥ 0}(x) + \frac{1}{2}\|μ-μ^k|_𝒟^2, | |
30 | $$ | |
31 | where $𝒟: 𝕃(ℳ(Ω); C_c(Ω))$ is typically a convolution operator. | |
32 | </p> | |
33 | ||
34 | ## Finite-dimensional subproblems. | |
35 | ||
36 | With $C$ a projection from [`DiscreteMeasure`] to the weights, and $x^k$ such that $x^k=Cμ^k$, we | |
37 | form the discretised linearised inner problem | |
38 | <p> | |
39 | $$ | |
40 | \min_{x ∈ ℝ^n}~ τ\bigl(F(Cx^k) + [C^*∇F(Cx^k)]^⊤(x-x^k) + α {\vec 1}^⊤ x\bigr) | |
41 | + δ_{≥ 0}(x) + \frac{1}{2}\|x-x^k\|_{C^*𝒟C}^2, | |
42 | $$ | |
43 | equivalently | |
44 | $$ | |
45 | \begin{aligned} | |
46 | \min_x~ & τF(Cx^k) - τ[C^*∇F(Cx^k)]^⊤x^k + \frac{1}{2} (x^k)^⊤ C^*𝒟C x^k | |
47 | \\ | |
48 | & | |
49 | - [C^*𝒟C x^k - τC^*∇F(Cx^k)]^⊤ x | |
50 | \\ | |
51 | & | |
52 | + \frac{1}{2} x^⊤ C^*𝒟C x | |
53 | + τα {\vec 1}^⊤ x + δ_{≥ 0}(x), | |
54 | \end{aligned} | |
55 | $$ | |
56 | In other words, we obtain the quadratic non-negativity constrained problem | |
57 | $$ | |
58 | \min_{x ∈ ℝ^n}~ \frac{1}{2} x^⊤ Ã x - b̃^⊤ x + c + τα {\vec 1}^⊤ x + δ_{≥ 0}(x). | |
59 | $$ | |
60 | where | |
61 | $$ | |
62 | \begin{aligned} | |
63 | Ã & = C^*𝒟C, | |
64 | \\ | |
65 | g̃ & = C^*𝒟C x^k - τ C^*∇F(Cx^k) | |
66 | = C^* 𝒟 μ^k - τ C^*A^*(Aμ^k - b) | |
67 | \\ | |
68 | c & = τ F(Cx^k) - τ[C^*∇F(Cx^k)]^⊤x^k + \frac{1}{2} (x^k)^⊤ C^*𝒟C x^k | |
69 | \\ | |
70 | & | |
71 | = \frac{τ}{2} \|Aμ^k-b\|^2 - τ[Aμ^k-b]^⊤Aμ^k + \frac{1}{2} \|μ_k\|_{𝒟}^2 | |
72 | \\ | |
73 | & | |
74 | = -\frac{τ}{2} \|Aμ^k-b\|^2 + τ[Aμ^k-b]^⊤ b + \frac{1}{2} \|μ_k\|_{𝒟}^2. | |
75 | \end{aligned} | |
76 | $$ | |
77 | </p> | |
78 | ||
79 | We solve this with either SSN or FB via [`quadratic_nonneg`] as determined by | |
80 | [`InnerSettings`] in [`FBGenericConfig::inner`]. | |
81 | */ | |
82 | ||
83 | use numeric_literals::replace_float_literals; | |
84 | use serde::{Serialize, Deserialize}; | |
85 | use colored::Colorize; | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
86 | use nalgebra::{DVector, DMatrix}; |
0 | 87 | |
88 | use alg_tools::iterate::{ | |
89 | AlgIteratorFactory, | |
90 | AlgIteratorState, | |
91 | }; | |
92 | use alg_tools::euclidean::Euclidean; | |
93 | use alg_tools::linops::Apply; | |
94 | use alg_tools::sets::Cube; | |
95 | use alg_tools::loc::Loc; | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
96 | use alg_tools::mapping::Mapping; |
0 | 97 | use alg_tools::bisection_tree::{ |
98 | BTFN, | |
99 | PreBTFN, | |
100 | Bounds, | |
101 | BTNodeLookup, | |
102 | BTNode, | |
103 | BTSearch, | |
104 | P2Minimise, | |
105 | SupportGenerator, | |
106 | LocalAnalysis, | |
107 | Bounded, | |
108 | }; | |
109 | use alg_tools::mapping::RealMapping; | |
110 | use alg_tools::nalgebra_support::ToNalgebraRealField; | |
111 | ||
112 | use crate::types::*; | |
113 | use crate::measures::{ | |
114 | DiscreteMeasure, | |
115 | DeltaMeasure, | |
116 | }; | |
117 | use crate::measures::merging::{ | |
118 | SpikeMergingMethod, | |
119 | SpikeMerging, | |
120 | }; | |
121 | use crate::forward_model::ForwardModel; | |
122 | use crate::seminorms::{ | |
123 | DiscreteMeasureOp, Lipschitz | |
124 | }; | |
125 | use crate::subproblem::{ | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
126 | nonneg::quadratic_nonneg, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
127 | unconstrained::quadratic_unconstrained, |
0 | 128 | InnerSettings, |
129 | InnerMethod, | |
130 | }; | |
131 | use crate::tolerance::Tolerance; | |
132 | use crate::plot::{ | |
133 | SeqPlotter, | |
134 | Plotting, | |
135 | PlotLookup | |
136 | }; | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
137 | use crate::regularisation::{ |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
138 | NonnegRadonRegTerm, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
139 | RadonRegTerm, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
140 | }; |
0 | 141 | |
142 | /// Method for constructing $μ$ on each iteration | |
143 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] | |
144 | #[allow(dead_code)] | |
145 | pub enum InsertionStyle { | |
146 | /// Resuse previous $μ$ from previous iteration, optimising weights | |
147 | /// before inserting new spikes. | |
148 | Reuse, | |
149 | /// Start each iteration with $μ=0$. | |
150 | Zero, | |
151 | } | |
152 | ||
153 | /// Meta-algorithm type | |
154 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] | |
155 | #[allow(dead_code)] | |
156 | pub enum FBMetaAlgorithm { | |
157 | /// No meta-algorithm | |
158 | None, | |
159 | /// FISTA-style inertia | |
160 | InertiaFISTA, | |
161 | } | |
162 | ||
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
163 | /// Settings for [`pointsource_fb_reg`]. |
0 | 164 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] |
165 | #[serde(default)] | |
166 | pub struct FBConfig<F : Float> { | |
167 | /// Step length scaling | |
168 | pub τ0 : F, | |
169 | /// Meta-algorithm to apply | |
170 | pub meta : FBMetaAlgorithm, | |
171 | /// Generic parameters | |
172 | pub insertion : FBGenericConfig<F>, | |
173 | } | |
174 | ||
175 | /// Settings for the solution of the stepwise optimality condition in algorithms based on | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
176 | /// [`generic_pointsource_fb_reg`]. |
0 | 177 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] |
178 | #[serde(default)] | |
179 | pub struct FBGenericConfig<F : Float> { | |
180 | /// Method for constructing $μ$ on each iteration; see [`InsertionStyle`]. | |
181 | pub insertion_style : InsertionStyle, | |
182 | /// Tolerance for point insertion. | |
183 | pub tolerance : Tolerance<F>, | |
184 | /// Stop looking for predual maximum (where to isert a new point) below | |
185 | /// `tolerance` multiplied by this factor. | |
186 | pub insertion_cutoff_factor : F, | |
187 | /// Settings for branch and bound refinement when looking for predual maxima | |
188 | pub refinement : RefinementSettings<F>, | |
189 | /// Maximum insertions within each outer iteration | |
190 | pub max_insertions : usize, | |
191 | /// Pair `(n, m)` for maximum insertions `m` on first `n` iterations. | |
192 | pub bootstrap_insertions : Option<(usize, usize)>, | |
193 | /// Inner method settings | |
194 | pub inner : InnerSettings<F>, | |
195 | /// Spike merging method | |
196 | pub merging : SpikeMergingMethod<F>, | |
197 | /// Tolerance multiplier for merges | |
198 | pub merge_tolerance_mult : F, | |
199 | /// Spike merging method after the last step | |
200 | pub final_merging : SpikeMergingMethod<F>, | |
201 | /// Iterations between merging heuristic tries | |
202 | pub merge_every : usize, | |
203 | /// Save $μ$ for postprocessing optimisation | |
204 | pub postprocessing : bool | |
205 | } | |
206 | ||
207 | #[replace_float_literals(F::cast_from(literal))] | |
208 | impl<F : Float> Default for FBConfig<F> { | |
209 | fn default() -> Self { | |
210 | FBConfig { | |
211 | τ0 : 0.99, | |
212 | meta : FBMetaAlgorithm::None, | |
213 | insertion : Default::default() | |
214 | } | |
215 | } | |
216 | } | |
217 | ||
218 | #[replace_float_literals(F::cast_from(literal))] | |
219 | impl<F : Float> Default for FBGenericConfig<F> { | |
220 | fn default() -> Self { | |
221 | FBGenericConfig { | |
222 | insertion_style : InsertionStyle::Reuse, | |
223 | tolerance : Default::default(), | |
224 | insertion_cutoff_factor : 1.0, | |
225 | refinement : Default::default(), | |
226 | max_insertions : 100, | |
227 | //bootstrap_insertions : None, | |
228 | bootstrap_insertions : Some((10, 1)), | |
229 | inner : InnerSettings { | |
230 | method : InnerMethod::SSN, | |
231 | .. Default::default() | |
232 | }, | |
233 | merging : SpikeMergingMethod::None, | |
234 | //merging : Default::default(), | |
235 | final_merging : Default::default(), | |
236 | merge_every : 10, | |
237 | merge_tolerance_mult : 2.0, | |
238 | postprocessing : false, | |
239 | } | |
240 | } | |
241 | } | |
242 | ||
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
243 | /// Trait for specialisation of [`generic_pointsource_fb_reg`] to basic FB, FISTA. |
0 | 244 | /// |
245 | /// The idea is that the residual $Aμ - b$ in the forward step can be replaced by an arbitrary | |
246 | /// value. For example, to implement [primal-dual proximal splitting][crate::pdps] we replace it | |
247 | /// with the dual variable $y$. We can then also implement alternative data terms, as the | |
248 | /// (pre)differential of $F(μ)=F\_0(Aμ-b)$ is $F\'(μ) = A\_*F\_0\'(Aμ-b)$. In the case of the | |
249 | /// quadratic fidelity $F_0(y)=\frac{1}{2}\\|y\\|_2^2$ in a Hilbert space, of course, | |
250 | /// $F\_0\'(Aμ-b)=Aμ-b$ is the residual. | |
251 | pub trait FBSpecialisation<F : Float, Observable : Euclidean<F>, const N : usize> : Sized { | |
252 | /// Updates the residual and does any necessary pruning of `μ`. | |
253 | /// | |
254 | /// Returns the new residual and possibly a new step length. | |
255 | /// | |
256 | /// The measure `μ` may also be modified to apply, e.g., inertia to it. | |
257 | /// The updated residual should correspond to the residual at `μ`. | |
258 | /// See the [trait documentation][FBSpecialisation] for the use and meaning of the residual. | |
259 | /// | |
260 | /// The parameter `μ_base` is the base point of the iteration, typically the previous iterate, | |
261 | /// but for, e.g., FISTA has inertia applied to it. | |
262 | fn update( | |
263 | &mut self, | |
264 | μ : &mut DiscreteMeasure<Loc<F, N>, F>, | |
265 | μ_base : &DiscreteMeasure<Loc<F, N>, F>, | |
266 | ) -> (Observable, Option<F>); | |
267 | ||
268 | /// Calculates the data term value corresponding to iterate `μ` and available residual. | |
269 | /// | |
270 | /// Inertia and other modifications, as deemed, necessary, should be applied to `μ`. | |
271 | /// | |
272 | /// The blanket implementation correspondsn to the 2-norm-squared data fidelity | |
273 | /// $\\|\text{residual}\\|\_2^2/2$. | |
274 | fn calculate_fit( | |
275 | &self, | |
276 | _μ : &DiscreteMeasure<Loc<F, N>, F>, | |
277 | residual : &Observable | |
278 | ) -> F { | |
279 | residual.norm2_squared_div2() | |
280 | } | |
281 | ||
282 | /// Calculates the data term value at $μ$. | |
283 | /// | |
284 | /// Unlike [`Self::calculate_fit`], no inertia, etc., should be applied to `μ`. | |
285 | fn calculate_fit_simple( | |
286 | &self, | |
287 | μ : &DiscreteMeasure<Loc<F, N>, F>, | |
288 | ) -> F; | |
289 | ||
290 | /// Returns the final iterate after any necessary postprocess pruning, merging, etc. | |
291 | fn postprocess(self, mut μ : DiscreteMeasure<Loc<F, N>, F>, merging : SpikeMergingMethod<F>) | |
292 | -> DiscreteMeasure<Loc<F, N>, F> | |
293 | where DiscreteMeasure<Loc<F, N>, F> : SpikeMerging<F> { | |
294 | μ.merge_spikes_fitness(merging, | |
295 | |μ̃| self.calculate_fit_simple(μ̃), | |
296 | |&v| v); | |
297 | μ.prune(); | |
298 | μ | |
299 | } | |
300 | ||
301 | /// Returns measure to be used for value calculations, which may differ from μ. | |
302 | fn value_μ<'c, 'b : 'c>(&'b self, μ : &'c DiscreteMeasure<Loc<F, N>, F>) | |
303 | -> &'c DiscreteMeasure<Loc<F, N>, F> { | |
304 | μ | |
305 | } | |
306 | } | |
307 | ||
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
308 | /// Specialisation of [`generic_pointsource_fb_reg`] to basic μFB. |
0 | 309 | struct BasicFB< |
310 | 'a, | |
311 | F : Float + ToNalgebraRealField, | |
312 | A : ForwardModel<Loc<F, N>, F>, | |
313 | const N : usize | |
314 | > { | |
315 | /// The data | |
316 | b : &'a A::Observable, | |
317 | /// The forward operator | |
318 | opA : &'a A, | |
319 | } | |
320 | ||
321 | /// Implementation of [`FBSpecialisation`] for basic μFB forward-backward splitting. | |
322 | #[replace_float_literals(F::cast_from(literal))] | |
323 | impl<'a, F : Float + ToNalgebraRealField , A : ForwardModel<Loc<F, N>, F>, const N : usize> | |
324 | FBSpecialisation<F, A::Observable, N> for BasicFB<'a, F, A, N> { | |
325 | fn update( | |
326 | &mut self, | |
327 | μ : &mut DiscreteMeasure<Loc<F, N>, F>, | |
328 | _μ_base : &DiscreteMeasure<Loc<F, N>, F> | |
329 | ) -> (A::Observable, Option<F>) { | |
330 | μ.prune(); | |
331 | //*residual = self.opA.apply(μ) - self.b; | |
332 | let mut residual = self.b.clone(); | |
333 | self.opA.gemv(&mut residual, 1.0, μ, -1.0); | |
334 | (residual, None) | |
335 | } | |
336 | ||
337 | fn calculate_fit_simple( | |
338 | &self, | |
339 | μ : &DiscreteMeasure<Loc<F, N>, F>, | |
340 | ) -> F { | |
341 | let mut residual = self.b.clone(); | |
342 | self.opA.gemv(&mut residual, 1.0, μ, -1.0); | |
343 | residual.norm2_squared_div2() | |
344 | } | |
345 | } | |
346 | ||
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
347 | /// Specialisation of [`generic_pointsource_fb_reg`] to FISTA. |
0 | 348 | struct FISTA< |
349 | 'a, | |
350 | F : Float + ToNalgebraRealField, | |
351 | A : ForwardModel<Loc<F, N>, F>, | |
352 | const N : usize | |
353 | > { | |
354 | /// The data | |
355 | b : &'a A::Observable, | |
356 | /// The forward operator | |
357 | opA : &'a A, | |
358 | /// Current inertial parameter | |
359 | λ : F, | |
360 | /// Previous iterate without inertia applied. | |
361 | /// We need to store this here because `μ_base` passed to [`FBSpecialisation::update`] will | |
362 | /// have inertia applied to it, so is not useful to use. | |
363 | μ_prev : DiscreteMeasure<Loc<F, N>, F>, | |
364 | } | |
365 | ||
366 | /// Implementation of [`FBSpecialisation`] for μFISTA inertial forward-backward splitting. | |
367 | #[replace_float_literals(F::cast_from(literal))] | |
368 | impl<'a, F : Float + ToNalgebraRealField, A : ForwardModel<Loc<F, N>, F>, const N : usize> | |
369 | FBSpecialisation<F, A::Observable, N> for FISTA<'a, F, A, N> { | |
370 | fn update( | |
371 | &mut self, | |
372 | μ : &mut DiscreteMeasure<Loc<F, N>, F>, | |
373 | _μ_base : &DiscreteMeasure<Loc<F, N>, F> | |
374 | ) -> (A::Observable, Option<F>) { | |
375 | // Update inertial parameters | |
376 | let λ_prev = self.λ; | |
377 | self.λ = 2.0 * λ_prev / ( λ_prev + (4.0 + λ_prev * λ_prev).sqrt() ); | |
378 | let θ = self.λ / λ_prev - self.λ; | |
379 | // Perform inertial update on μ. | |
380 | // This computes μ ← (1 + θ) * μ - θ * μ_prev, pruning spikes where both μ | |
381 | // and μ_prev have zero weight. Since both have weights from the finite-dimensional | |
382 | // subproblem with a proximal projection step, this is likely to happen when the | |
383 | // spike is not needed. A copy of the pruned μ without artithmetic performed is | |
384 | // stored in μ_prev. | |
385 | μ.pruning_sub(1.0 + θ, θ, &mut self.μ_prev); | |
386 | ||
387 | //*residual = self.opA.apply(μ) - self.b; | |
388 | let mut residual = self.b.clone(); | |
389 | self.opA.gemv(&mut residual, 1.0, μ, -1.0); | |
390 | (residual, None) | |
391 | } | |
392 | ||
393 | fn calculate_fit_simple( | |
394 | &self, | |
395 | μ : &DiscreteMeasure<Loc<F, N>, F>, | |
396 | ) -> F { | |
397 | let mut residual = self.b.clone(); | |
398 | self.opA.gemv(&mut residual, 1.0, μ, -1.0); | |
399 | residual.norm2_squared_div2() | |
400 | } | |
401 | ||
402 | fn calculate_fit( | |
403 | &self, | |
404 | _μ : &DiscreteMeasure<Loc<F, N>, F>, | |
405 | _residual : &A::Observable | |
406 | ) -> F { | |
407 | self.calculate_fit_simple(&self.μ_prev) | |
408 | } | |
409 | ||
410 | // For FISTA we need to do a final pruning as well, due to the limited | |
411 | // pruning that can be done on each step. | |
412 | fn postprocess(mut self, μ_base : DiscreteMeasure<Loc<F, N>, F>, merging : SpikeMergingMethod<F>) | |
413 | -> DiscreteMeasure<Loc<F, N>, F> | |
414 | where DiscreteMeasure<Loc<F, N>, F> : SpikeMerging<F> { | |
415 | let mut μ = self.μ_prev; | |
416 | self.μ_prev = μ_base; | |
417 | μ.merge_spikes_fitness(merging, | |
418 | |μ̃| self.calculate_fit_simple(μ̃), | |
419 | |&v| v); | |
420 | μ.prune(); | |
421 | μ | |
422 | } | |
423 | ||
424 | fn value_μ<'c, 'b : 'c>(&'c self, _μ : &'c DiscreteMeasure<Loc<F, N>, F>) | |
425 | -> &'c DiscreteMeasure<Loc<F, N>, F> { | |
426 | &self.μ_prev | |
427 | } | |
428 | } | |
429 | ||
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
430 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
431 | /// Abstraction of regularisation terms for [`generic_pointsource_fb_reg`]. |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
432 | pub trait RegTerm<F : Float + ToNalgebraRealField, const N : usize> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
433 | : for<'a> Apply<&'a DiscreteMeasure<Loc<F, N>, F>, Output = F> { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
434 | /// Approximately solve the problem |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
435 | /// <div>$$ |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
436 | /// \min_{x ∈ ℝ^n} \frac{1}{2} x^⊤Ax - g^⊤ x + τ G(x) |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
437 | /// $$</div> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
438 | /// for $G$ depending on the trait implementation. |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
439 | /// |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
440 | /// The parameter `mA` is $A$. An estimate for its opeator norm should be provided in |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
441 | /// `mA_normest`. The initial iterate and output is `x`. The current main tolerance is `ε`. |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
442 | /// |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
443 | /// Returns the number of iterations taken. |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
444 | fn solve_findim( |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
445 | &self, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
446 | mA : &DMatrix<F::MixedType>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
447 | g : &DVector<F::MixedType>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
448 | τ : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
449 | x : &mut DVector<F::MixedType>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
450 | mA_normest : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
451 | ε : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
452 | config : &FBGenericConfig<F> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
453 | ) -> usize; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
454 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
455 | /// Find a point where `d` may violate the tolerance `ε`. |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
456 | /// |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
457 | /// If `skip_by_rough_check` is set, do not find the point if a rough check indicates that we |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
458 | /// are in bounds. `ε` is the current main tolerance and `τ` a scaling factor for the |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
459 | /// regulariser. |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
460 | /// |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
461 | /// Returns `None` if `d` is in bounds either based on the rough check, or a more precise check |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
462 | /// terminating early. Otherwise returns a possibly violating point, the value of `d` there, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
463 | /// and a boolean indicating whether the found point is in bounds. |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
464 | fn find_tolerance_violation<G, BT>( |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
465 | &self, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
466 | d : &mut BTFN<F, G, BT, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
467 | τ : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
468 | ε : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
469 | skip_by_rough_check : bool, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
470 | config : &FBGenericConfig<F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
471 | ) -> Option<(Loc<F, N>, F, bool)> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
472 | where BT : BTSearch<F, N, Agg=Bounds<F>>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
473 | G : SupportGenerator<F, N, Id=BT::Data>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
474 | G::SupportType : Mapping<Loc<F, N>,Codomain=F> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
475 | + LocalAnalysis<F, Bounds<F>, N>; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
476 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
477 | /// Verify that `d` is in bounds `ε` for a merge candidate `μ` |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
478 | /// |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
479 | /// `ε` is the current main tolerance and `τ` a scaling factor for the regulariser. |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
480 | fn verify_merge_candidate<G, BT>( |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
481 | &self, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
482 | d : &mut BTFN<F, G, BT, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
483 | μ : &DiscreteMeasure<Loc<F, N>, F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
484 | τ : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
485 | ε : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
486 | config : &FBGenericConfig<F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
487 | ) -> bool |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
488 | where BT : BTSearch<F, N, Agg=Bounds<F>>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
489 | G : SupportGenerator<F, N, Id=BT::Data>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
490 | G::SupportType : Mapping<Loc<F, N>,Codomain=F> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
491 | + LocalAnalysis<F, Bounds<F>, N>; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
492 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
493 | fn target_bounds(&self, τ : F, ε : F) -> Option<Bounds<F>>; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
494 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
495 | /// Returns a scaling factor for the tolerance sequence. |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
496 | /// |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
497 | /// Typically this is the regularisation parameter. |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
498 | fn tolerance_scaling(&self) -> F; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
499 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
500 | |
0 | 501 | #[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
|
502 | impl<F : Float + ToNalgebraRealField, const N : usize> RegTerm<F, N> for NonnegRadonRegTerm<F> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
503 | where Cube<F, N> : P2Minimise<Loc<F, N>, F> { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
504 | fn solve_findim( |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
505 | &self, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
506 | mA : &DMatrix<F::MixedType>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
507 | g : &DVector<F::MixedType>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
508 | τ : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
509 | x : &mut DVector<F::MixedType>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
510 | mA_normest : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
511 | ε : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
512 | config : &FBGenericConfig<F> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
513 | ) -> usize { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
514 | let inner_tolerance = ε * config.inner.tolerance_mult; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
515 | let inner_it = config.inner.iterator_options.stop_target(inner_tolerance); |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
516 | let inner_τ = config.inner.τ0 / mA_normest; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
517 | quadratic_nonneg(config.inner.method, mA, g, τ * self.α(), x, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
518 | inner_τ, inner_it) |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
519 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
520 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
521 | #[inline] |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
522 | fn find_tolerance_violation<G, BT>( |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
523 | &self, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
524 | d : &mut BTFN<F, G, BT, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
525 | τ : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
526 | ε : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
527 | skip_by_rough_check : bool, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
528 | config : &FBGenericConfig<F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
529 | ) -> Option<(Loc<F, N>, F, bool)> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
530 | where BT : BTSearch<F, N, Agg=Bounds<F>>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
531 | G : SupportGenerator<F, N, Id=BT::Data>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
532 | G::SupportType : Mapping<Loc<F, N>,Codomain=F> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
533 | + LocalAnalysis<F, Bounds<F>, N> { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
534 | let τα = τ * self.α(); |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
535 | let keep_below = τα + ε; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
536 | let maximise_above = τα + ε * config.insertion_cutoff_factor; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
537 | let refinement_tolerance = ε * config.refinement.tolerance_mult; |
0 | 538 | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
539 | // If preliminary check indicates that we are in bonds, and if it otherwise matches |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
540 | // the insertion strategy, skip insertion. |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
541 | if skip_by_rough_check && d.bounds().upper() <= keep_below { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
542 | None |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
543 | } else { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
544 | // If the rough check didn't indicate no insertion needed, find maximising point. |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
545 | d.maximise_above(maximise_above, refinement_tolerance, config.refinement.max_steps) |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
546 | .map(|(ξ, v_ξ)| (ξ, v_ξ, v_ξ <= keep_below)) |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
547 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
548 | } |
0 | 549 | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
550 | fn verify_merge_candidate<G, BT>( |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
551 | &self, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
552 | d : &mut BTFN<F, G, BT, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
553 | μ : &DiscreteMeasure<Loc<F, N>, F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
554 | τ : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
555 | ε : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
556 | config : &FBGenericConfig<F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
557 | ) -> bool |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
558 | where BT : BTSearch<F, N, Agg=Bounds<F>>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
559 | G : SupportGenerator<F, N, Id=BT::Data>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
560 | G::SupportType : Mapping<Loc<F, N>,Codomain=F> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
561 | + LocalAnalysis<F, Bounds<F>, N> { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
562 | let τα = τ * self.α(); |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
563 | let refinement_tolerance = ε * config.refinement.tolerance_mult; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
564 | let merge_tolerance = config.merge_tolerance_mult * ε; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
565 | let keep_below = τα + merge_tolerance; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
566 | let keep_supp_above = τα - merge_tolerance; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
567 | let bnd = d.bounds(); |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
568 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
569 | return ( |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
570 | bnd.lower() >= keep_supp_above |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
571 | || |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
572 | μ.iter_spikes().map(|&DeltaMeasure{ α : β, ref x }| { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
573 | (β == 0.0) || d.apply(x) >= keep_supp_above |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
574 | }).all(std::convert::identity) |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
575 | ) && ( |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
576 | bnd.upper() <= keep_below |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
577 | || |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
578 | d.has_upper_bound(keep_below, refinement_tolerance, config.refinement.max_steps) |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
579 | ) |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
580 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
581 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
582 | fn target_bounds(&self, τ : F, ε : F) -> Option<Bounds<F>> { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
583 | let τα = τ * self.α(); |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
584 | Some(Bounds(τα - ε, τα + ε)) |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
585 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
586 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
587 | fn tolerance_scaling(&self) -> F { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
588 | self.α() |
0 | 589 | } |
590 | } | |
591 | ||
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
592 | #[replace_float_literals(F::cast_from(literal))] |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
593 | impl<F : Float + ToNalgebraRealField, const N : usize> RegTerm<F, N> for RadonRegTerm<F> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
594 | where Cube<F, N> : P2Minimise<Loc<F, N>, F> { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
595 | fn solve_findim( |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
596 | &self, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
597 | mA : &DMatrix<F::MixedType>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
598 | g : &DVector<F::MixedType>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
599 | τ : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
600 | x : &mut DVector<F::MixedType>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
601 | mA_normest: F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
602 | ε : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
603 | config : &FBGenericConfig<F> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
604 | ) -> usize { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
605 | let inner_tolerance = ε * config.inner.tolerance_mult; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
606 | let inner_it = config.inner.iterator_options.stop_target(inner_tolerance); |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
607 | let inner_τ = config.inner.τ0 / mA_normest; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
608 | quadratic_unconstrained(config.inner.method, mA, g, τ * self.α(), x, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
609 | inner_τ, inner_it) |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
610 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
611 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
612 | fn find_tolerance_violation<G, BT>( |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
613 | &self, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
614 | d : &mut BTFN<F, G, BT, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
615 | τ : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
616 | ε : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
617 | skip_by_rough_check : bool, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
618 | config : &FBGenericConfig<F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
619 | ) -> Option<(Loc<F, N>, F, bool)> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
620 | where BT : BTSearch<F, N, Agg=Bounds<F>>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
621 | G : SupportGenerator<F, N, Id=BT::Data>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
622 | G::SupportType : Mapping<Loc<F, N>,Codomain=F> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
623 | + LocalAnalysis<F, Bounds<F>, N> { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
624 | let τα = τ * self.α(); |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
625 | let keep_below = τα + ε; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
626 | let keep_above = -τα - ε; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
627 | let maximise_above = τα + ε * config.insertion_cutoff_factor; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
628 | let minimise_below = -τα - ε * config.insertion_cutoff_factor; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
629 | let refinement_tolerance = ε * config.refinement.tolerance_mult; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
630 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
631 | // If preliminary check indicates that we are in bonds, and if it otherwise matches |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
632 | // the insertion strategy, skip insertion. |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
633 | if skip_by_rough_check && Bounds(keep_above, keep_below).superset(&d.bounds()) { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
634 | None |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
635 | } else { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
636 | // If the rough check didn't indicate no insertion needed, find maximising point. |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
637 | let mx = d.maximise_above(maximise_above, refinement_tolerance, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
638 | config.refinement.max_steps); |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
639 | let mi = d.minimise_below(minimise_below, refinement_tolerance, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
640 | config.refinement.max_steps); |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
641 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
642 | match (mx, mi) { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
643 | (None, None) => None, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
644 | (Some((ξ, v_ξ)), None) => Some((ξ, v_ξ, keep_below >= v_ξ)), |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
645 | (None, Some((ζ, v_ζ))) => Some((ζ, v_ζ, keep_above <= v_ζ)), |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
646 | (Some((ξ, v_ξ)), Some((ζ, v_ζ))) => { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
647 | if v_ξ - τα > τα - v_ζ { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
648 | Some((ξ, v_ξ, keep_below >= v_ξ)) |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
649 | } else { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
650 | Some((ζ, v_ζ, keep_above <= v_ζ)) |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
651 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
652 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
653 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
654 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
655 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
656 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
657 | fn verify_merge_candidate<G, BT>( |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
658 | &self, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
659 | d : &mut BTFN<F, G, BT, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
660 | μ : &DiscreteMeasure<Loc<F, N>, F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
661 | τ : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
662 | ε : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
663 | config : &FBGenericConfig<F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
664 | ) -> bool |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
665 | where BT : BTSearch<F, N, Agg=Bounds<F>>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
666 | G : SupportGenerator<F, N, Id=BT::Data>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
667 | G::SupportType : Mapping<Loc<F, N>,Codomain=F> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
668 | + LocalAnalysis<F, Bounds<F>, N> { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
669 | let τα = τ * self.α(); |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
670 | let refinement_tolerance = ε * config.refinement.tolerance_mult; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
671 | let merge_tolerance = config.merge_tolerance_mult * ε; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
672 | let keep_below = τα + merge_tolerance; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
673 | let keep_above = -τα - merge_tolerance; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
674 | let keep_supp_pos_above = τα - merge_tolerance; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
675 | let keep_supp_neg_below = -τα + merge_tolerance; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
676 | let bnd = d.bounds(); |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
677 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
678 | return ( |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
679 | (bnd.lower() >= keep_supp_pos_above && bnd.upper() <= keep_supp_neg_below) |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
680 | || |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
681 | μ.iter_spikes().map(|&DeltaMeasure{ α : β, ref x }| { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
682 | use std::cmp::Ordering::*; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
683 | match β.partial_cmp(&0.0) { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
684 | Some(Greater) => d.apply(x) >= keep_supp_pos_above, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
685 | Some(Less) => d.apply(x) <= keep_supp_neg_below, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
686 | _ => true, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
687 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
688 | }).all(std::convert::identity) |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
689 | ) && ( |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
690 | bnd.upper() <= keep_below |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
691 | || |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
692 | d.has_upper_bound(keep_below, refinement_tolerance, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
693 | config.refinement.max_steps) |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
694 | ) && ( |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
695 | bnd.lower() >= keep_above |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
696 | || |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
697 | d.has_lower_bound(keep_above, refinement_tolerance, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
698 | config.refinement.max_steps) |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
699 | ) |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
700 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
701 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
702 | fn target_bounds(&self, τ : F, ε : F) -> Option<Bounds<F>> { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
703 | let τα = τ * self.α(); |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
704 | Some(Bounds(-τα - ε, τα + ε)) |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
705 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
706 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
707 | fn tolerance_scaling(&self) -> F { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
708 | self.α() |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
709 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
710 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
711 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
712 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
713 | /// Generic implementation of [`pointsource_fb_reg`]. |
0 | 714 | /// |
715 | /// The method can be specialised to even primal-dual proximal splitting through the | |
716 | /// [`FBSpecialisation`] parameter `specialisation`. | |
717 | /// The settings in `config` have their [respective documentation](FBGenericConfig). `opA` is the | |
718 | /// forward operator $A$, $b$ the observable, and $\lambda$ the regularisation weight. | |
719 | /// The operator `op𝒟` is used for forming the proximal term. Typically it is a convolution | |
720 | /// operator. Finally, the `iterator` is an outer loop verbosity and iteration count control | |
721 | /// as documented in [`alg_tools::iterate`]. | |
722 | /// | |
723 | /// The implementation relies on [`alg_tools::bisection_tree::BTFN`] presentations of | |
724 | /// sums of simple functions usign bisection trees, and the related | |
725 | /// [`alg_tools::bisection_tree::Aggregator`]s, to efficiently search for component functions | |
726 | /// active at a specific points, and to maximise their sums. Through the implementation of the | |
727 | /// [`alg_tools::bisection_tree::BT`] bisection trees, it also relies on the copy-on-write features | |
728 | /// of [`std::sync::Arc`] to only update relevant parts of the bisection tree when adding functions. | |
729 | /// | |
730 | /// Returns the final iterate. | |
731 | #[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
|
732 | pub fn generic_pointsource_fb_reg< |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
733 | 'a, F, I, A, GA, 𝒟, BTA, G𝒟, S, K, Spec, Reg, const N : usize |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
734 | >( |
0 | 735 | opA : &'a A, |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
736 | reg : Reg, |
0 | 737 | op𝒟 : &'a 𝒟, |
738 | mut τ : F, | |
739 | config : &FBGenericConfig<F>, | |
740 | iterator : I, | |
741 | mut plotter : SeqPlotter<F, N>, | |
742 | mut residual : A::Observable, | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
743 | mut specialisation : Spec |
0 | 744 | ) -> DiscreteMeasure<Loc<F, N>, F> |
745 | where F : Float + ToNalgebraRealField, | |
746 | I : AlgIteratorFactory<IterInfo<F, N>>, | |
747 | Spec : FBSpecialisation<F, A::Observable, N>, | |
748 | A::Observable : std::ops::MulAssign<F>, | |
749 | GA : SupportGenerator<F, N, SupportType = S, Id = usize> + Clone, | |
750 | A : ForwardModel<Loc<F, N>, F, PreadjointCodomain = BTFN<F, GA, BTA, N>> | |
751 | + Lipschitz<𝒟, FloatType=F>, | |
752 | BTA : BTSearch<F, N, Data=usize, Agg=Bounds<F>>, | |
753 | G𝒟 : SupportGenerator<F, N, SupportType = K, Id = usize> + Clone, | |
754 | 𝒟 : DiscreteMeasureOp<Loc<F, N>, F, PreCodomain = PreBTFN<F, G𝒟, N>>, | |
755 | 𝒟::Codomain : RealMapping<F, N>, | |
756 | S: RealMapping<F, N> + LocalAnalysis<F, Bounds<F>, N>, | |
757 | K: RealMapping<F, N> + LocalAnalysis<F, Bounds<F>, N>, | |
758 | BTNodeLookup: BTNode<F, usize, Bounds<F>, N>, | |
759 | PlotLookup : Plotting<N>, | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
760 | DiscreteMeasure<Loc<F, N>, F> : SpikeMerging<F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
761 | Reg : RegTerm<F, N> { |
0 | 762 | |
763 | // Set up parameters | |
764 | let quiet = iterator.is_quiet(); | |
765 | let op𝒟norm = op𝒟.opnorm_bound(); | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
766 | // We multiply tolerance by τ for FB since our subproblems depending on tolerances are scaled |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
767 | // by τ compared to the conditional gradient approach. |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
768 | let tolerance = config.tolerance * τ * reg.tolerance_scaling(); |
0 | 769 | let mut ε = tolerance.initial(); |
770 | ||
771 | // Initialise operators | |
772 | let preadjA = opA.preadjoint(); | |
773 | ||
774 | // Initialise iterates | |
775 | let mut μ = DiscreteMeasure::new(); | |
776 | ||
777 | let mut inner_iters = 0; | |
778 | let mut this_iters = 0; | |
779 | let mut pruned = 0; | |
780 | let mut merged = 0; | |
781 | ||
782 | let μ_diff = |μ_new : &DiscreteMeasure<Loc<F, N>, F>, | |
783 | μ_base : &DiscreteMeasure<Loc<F, N>, F>| { | |
784 | let mut ν : DiscreteMeasure<Loc<F, N>, F> = match config.insertion_style { | |
785 | InsertionStyle::Reuse => { | |
786 | μ_new.iter_spikes() | |
787 | .zip(μ_base.iter_masses().chain(std::iter::repeat(0.0))) | |
788 | .map(|(δ, α_base)| (δ.x, α_base - δ.α)) | |
789 | .collect() | |
790 | }, | |
791 | InsertionStyle::Zero => { | |
792 | μ_new.iter_spikes() | |
793 | .map(|δ| -δ) | |
794 | .chain(μ_base.iter_spikes().copied()) | |
795 | .collect() | |
796 | } | |
797 | }; | |
798 | ν.prune(); // Potential small performance improvement | |
799 | ν | |
800 | }; | |
801 | ||
802 | // Run the algorithm | |
803 | iterator.iterate(|state| { | |
804 | // Maximum insertion count and measure difference calculation depend on insertion style. | |
805 | let (m, warn_insertions) = match (state.iteration(), config.bootstrap_insertions) { | |
806 | (i, Some((l, k))) if i <= l => (k, false), | |
807 | _ => (config.max_insertions, !quiet), | |
808 | }; | |
809 | let max_insertions = match config.insertion_style { | |
810 | InsertionStyle::Zero => { | |
811 | todo!("InsertionStyle::Zero does not currently work with FISTA, so diabled."); | |
812 | // let n = μ.len(); | |
813 | // μ = DiscreteMeasure::new(); | |
814 | // n + m | |
815 | }, | |
816 | InsertionStyle::Reuse => m, | |
817 | }; | |
818 | ||
819 | // Calculate smooth part of surrogate model. | |
820 | // Using `std::mem::replace` here is not ideal, and expects that `empty_observable` | |
821 | // has no significant overhead. For some reosn Rust doesn't allow us simply moving | |
822 | // the residual and replacing it below before the end of this closure. | |
7
c32171f7cce5
Remove ergodic tolerance; it's not useful.
Tuomo Valkonen <tuomov@iki.fi>
parents:
0
diff
changeset
|
823 | residual *= -τ; |
0 | 824 | let r = std::mem::replace(&mut residual, opA.empty_observable()); |
825 | let minus_τv = preadjA.apply(r); // minus_τv = -τA^*(Aμ^k-b) | |
826 | // TODO: should avoid a second copy of μ here; μ_base already stores a copy. | |
827 | let ω0 = op𝒟.apply(μ.clone()); // 𝒟μ^k | |
828 | //let g = &minus_τv + ω0; // Linear term of surrogate model | |
829 | ||
830 | // Save current base point | |
831 | let μ_base = μ.clone(); | |
832 | ||
833 | // Add points to support until within error tolerance or maximum insertion count reached. | |
834 | let mut count = 0; | |
835 | let (within_tolerances, d) = 'insertion: loop { | |
836 | if μ.len() > 0 { | |
837 | // Form finite-dimensional subproblem. The subproblem references to the original μ^k | |
838 | // from the beginning of the iteration are all contained in the immutable c and g. | |
839 | let à = op𝒟.findim_matrix(μ.iter_locations()); | |
840 | let g̃ = DVector::from_iterator(μ.len(), | |
841 | μ.iter_locations() | |
842 | .map(|ζ| minus_τv.apply(ζ) + ω0.apply(ζ)) | |
843 | .map(F::to_nalgebra_mixed)); | |
844 | let mut x = μ.masses_dvector(); | |
845 | ||
846 | // The gradient of the forward component of the inner objective is C^*𝒟Cx - g̃. | |
847 | // We have |C^*𝒟Cx|_2 = sup_{|z|_2 ≤ 1} ⟨z, C^*𝒟Cx⟩ = sup_{|z|_2 ≤ 1} ⟨Cz|𝒟Cx⟩ | |
848 | // ≤ sup_{|z|_2 ≤ 1} |Cz|_ℳ |𝒟Cx|_∞ ≤ sup_{|z|_2 ≤ 1} |Cz|_ℳ |𝒟| |Cx|_ℳ | |
849 | // ≤ sup_{|z|_2 ≤ 1} |z|_1 |𝒟| |x|_1 ≤ sup_{|z|_2 ≤ 1} n |z|_2 |𝒟| |x|_2 | |
850 | // = n |𝒟| |x|_2, where n is the number of points. Therefore | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
851 | let Ã_normest = op𝒟norm * F::cast_from(μ.len()); |
0 | 852 | |
853 | // Solve finite-dimensional subproblem. | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
854 | inner_iters += reg.solve_findim(&Ã, &g̃, τ, &mut x, Ã_normest, ε, config); |
0 | 855 | |
856 | // Update masses of μ based on solution of finite-dimensional subproblem. | |
857 | μ.set_masses_dvector(&x); | |
858 | } | |
859 | ||
860 | // Form d = ω0 - τv - 𝒟μ = -𝒟(μ - μ^k) - τv for checking the proximate optimality | |
861 | // conditions in the predual space, and finding new points for insertion, if necessary. | |
862 | let mut d = &minus_τv + op𝒟.preapply(μ_diff(&μ, &μ_base)); | |
863 | ||
864 | // If no merging heuristic is used, let's be more conservative about spike insertion, | |
865 | // and skip it after first round. If merging is done, being more greedy about spike | |
866 | // insertion also seems to improve performance. | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
867 | let skip_by_rough_check = if let SpikeMergingMethod::None = config.merging { |
0 | 868 | false |
869 | } else { | |
870 | count > 0 | |
871 | }; | |
872 | ||
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
873 | // Find a spike to insert, if needed |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
874 | let (ξ, _v_ξ, in_bounds) = match reg.find_tolerance_violation( |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
875 | &mut d, τ, ε, skip_by_rough_check, config |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
876 | ) { |
8
ea3ca78873e8
Clean up / remove various unused FB algorithm family hacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
7
diff
changeset
|
877 | None => break 'insertion (true, d), |
ea3ca78873e8
Clean up / remove various unused FB algorithm family hacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
7
diff
changeset
|
878 | Some(res) => res, |
0 | 879 | }; |
880 | ||
881 | // Break if maximum insertion count reached | |
882 | if count >= max_insertions { | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
883 | break 'insertion (in_bounds, d) |
0 | 884 | } |
885 | ||
886 | // No point in optimising the weight here; the finite-dimensional algorithm is fast. | |
887 | μ += DeltaMeasure { x : ξ, α : 0.0 }; | |
888 | count += 1; | |
889 | }; | |
890 | ||
891 | if !within_tolerances && warn_insertions { | |
892 | // Complain (but continue) if we failed to get within tolerances | |
893 | // by inserting more points. | |
894 | let err = format!("Maximum insertions reached without achieving \ | |
895 | subproblem solution tolerance"); | |
896 | println!("{}", err.red()); | |
897 | } | |
898 | ||
899 | // Merge spikes | |
900 | if state.iteration() % config.merge_every == 0 { | |
901 | let n_before_merge = μ.len(); | |
902 | μ.merge_spikes(config.merging, |μ_candidate| { | |
903 | let mut d = &minus_τv + op𝒟.preapply(μ_diff(&μ_candidate, &μ_base)); | |
904 | ||
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
905 | reg.verify_merge_candidate(&mut d, μ_candidate, τ, ε, &config) |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
906 | .then_some(()) |
0 | 907 | }); |
908 | debug_assert!(μ.len() >= n_before_merge); | |
909 | merged += μ.len() - n_before_merge; | |
910 | } | |
911 | ||
912 | let n_before_prune = μ.len(); | |
913 | (residual, τ) = match specialisation.update(&mut μ, &μ_base) { | |
914 | (r, None) => (r, τ), | |
915 | (r, Some(new_τ)) => (r, new_τ) | |
916 | }; | |
917 | debug_assert!(μ.len() <= n_before_prune); | |
918 | pruned += n_before_prune - μ.len(); | |
919 | ||
920 | this_iters += 1; | |
921 | ||
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
922 | // Update main tolerance for next iteration |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
923 | let ε_prev = ε; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
924 | ε = tolerance.update(ε, state.iteration()); |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
925 | |
0 | 926 | // Give function value if needed |
927 | state.if_verbose(|| { | |
928 | let value_μ = specialisation.value_μ(&μ); | |
929 | // Plot if so requested | |
930 | plotter.plot_spikes( | |
931 | format!("iter {} end; {}", state.iteration(), within_tolerances), &d, | |
932 | "start".to_string(), Some(&minus_τv), | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
933 | reg.target_bounds(τ, ε_prev), value_μ, |
0 | 934 | ); |
8
ea3ca78873e8
Clean up / remove various unused FB algorithm family hacks.
Tuomo Valkonen <tuomov@iki.fi>
parents:
7
diff
changeset
|
935 | // Calculate mean inner iterations and reset relevant counters. |
0 | 936 | // Return the statistics |
937 | let res = IterInfo { | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
938 | value : specialisation.calculate_fit(&μ, &residual) + reg.apply(value_μ), |
0 | 939 | n_spikes : value_μ.len(), |
940 | inner_iters, | |
941 | this_iters, | |
942 | merged, | |
943 | pruned, | |
944 | ε : ε_prev, | |
945 | postprocessing: config.postprocessing.then(|| value_μ.clone()), | |
946 | }; | |
947 | inner_iters = 0; | |
948 | this_iters = 0; | |
949 | merged = 0; | |
950 | pruned = 0; | |
951 | res | |
952 | }) | |
953 | }); | |
954 | ||
955 | specialisation.postprocess(μ, config.final_merging) | |
956 | } | |
957 | ||
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
958 | /// Iteratively solve the pointsource localisation problem using forward-backward splitting |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
959 | /// |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
960 | /// The settings in `config` have their [respective documentation](FBConfig). `opA` is the |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
961 | /// forward operator $A$, $b$ the observable, and $\lambda$ the regularisation weight. |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
962 | /// The operator `op𝒟` is used for forming the proximal term. Typically it is a convolution |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
963 | /// operator. Finally, the `iterator` is an outer loop verbosity and iteration count control |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
964 | /// as documented in [`alg_tools::iterate`]. |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
965 | /// |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
966 | /// For details on the mathematical formulation, see the [module level](self) documentation. |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
967 | /// |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
968 | /// Returns the final iterate. |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
969 | #[replace_float_literals(F::cast_from(literal))] |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
970 | pub fn pointsource_fb_reg<'a, F, I, A, GA, 𝒟, BTA, G𝒟, S, K, Reg, const N : usize>( |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
971 | opA : &'a A, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
972 | b : &A::Observable, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
973 | reg : Reg, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
974 | op𝒟 : &'a 𝒟, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
975 | config : &FBConfig<F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
976 | iterator : I, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
977 | plotter : SeqPlotter<F, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
978 | ) -> DiscreteMeasure<Loc<F, N>, F> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
979 | where F : Float + ToNalgebraRealField, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
980 | I : AlgIteratorFactory<IterInfo<F, N>>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
981 | for<'b> &'b A::Observable : std::ops::Neg<Output=A::Observable>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
982 | //+ std::ops::Mul<F, Output=A::Observable>, <-- FIXME: compiler overflow |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
983 | A::Observable : std::ops::MulAssign<F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
984 | GA : SupportGenerator<F, N, SupportType = S, Id = usize> + Clone, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
985 | A : ForwardModel<Loc<F, N>, F, PreadjointCodomain = BTFN<F, GA, BTA, N>> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
986 | + Lipschitz<𝒟, FloatType=F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
987 | BTA : BTSearch<F, N, Data=usize, Agg=Bounds<F>>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
988 | G𝒟 : SupportGenerator<F, N, SupportType = K, Id = usize> + Clone, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
989 | 𝒟 : DiscreteMeasureOp<Loc<F, N>, F, PreCodomain = PreBTFN<F, G𝒟, N>>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
990 | 𝒟::Codomain : RealMapping<F, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
991 | S: RealMapping<F, N> + LocalAnalysis<F, Bounds<F>, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
992 | K: RealMapping<F, N> + LocalAnalysis<F, Bounds<F>, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
993 | BTNodeLookup: BTNode<F, usize, Bounds<F>, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
994 | Cube<F, N>: P2Minimise<Loc<F, N>, F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
995 | PlotLookup : Plotting<N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
996 | DiscreteMeasure<Loc<F, N>, F> : SpikeMerging<F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
997 | Reg : RegTerm<F, N> { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
998 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
999 | let initial_residual = -b; |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1000 | let τ = config.τ0/opA.lipschitz_factor(&op𝒟).unwrap(); |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1001 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1002 | match config.meta { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1003 | FBMetaAlgorithm::None => generic_pointsource_fb_reg( |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1004 | opA, reg, op𝒟, τ, &config.insertion, iterator, plotter, initial_residual, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1005 | BasicFB{ b, opA }, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1006 | ), |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1007 | FBMetaAlgorithm::InertiaFISTA => generic_pointsource_fb_reg( |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1008 | opA, reg, op𝒟, τ, &config.insertion, iterator, plotter, initial_residual, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1009 | FISTA{ b, opA, λ : 1.0, μ_prev : DiscreteMeasure::new() }, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1010 | ), |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1011 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1012 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1013 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1014 | // |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1015 | // Deprecated interfaces |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1016 | // |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1017 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1018 | #[deprecated(note = "Use `pointsource_fb_reg`")] |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1019 | pub fn pointsource_fb<'a, F, I, A, GA, 𝒟, BTA, G𝒟, S, K, const N : usize>( |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1020 | opA : &'a A, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1021 | b : &A::Observable, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1022 | α : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1023 | op𝒟 : &'a 𝒟, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1024 | config : &FBConfig<F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1025 | iterator : I, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1026 | plotter : SeqPlotter<F, N> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1027 | ) -> DiscreteMeasure<Loc<F, N>, F> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1028 | where F : Float + ToNalgebraRealField, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1029 | I : AlgIteratorFactory<IterInfo<F, N>>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1030 | for<'b> &'b A::Observable : std::ops::Neg<Output=A::Observable>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1031 | A::Observable : std::ops::MulAssign<F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1032 | GA : SupportGenerator<F, N, SupportType = S, Id = usize> + Clone, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1033 | A : ForwardModel<Loc<F, N>, F, PreadjointCodomain = BTFN<F, GA, BTA, N>> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1034 | + Lipschitz<𝒟, FloatType=F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1035 | BTA : BTSearch<F, N, Data=usize, Agg=Bounds<F>>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1036 | G𝒟 : SupportGenerator<F, N, SupportType = K, Id = usize> + Clone, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1037 | 𝒟 : DiscreteMeasureOp<Loc<F, N>, F, PreCodomain = PreBTFN<F, G𝒟, N>>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1038 | 𝒟::Codomain : RealMapping<F, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1039 | S: RealMapping<F, N> + LocalAnalysis<F, Bounds<F>, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1040 | K: RealMapping<F, N> + LocalAnalysis<F, Bounds<F>, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1041 | BTNodeLookup: BTNode<F, usize, Bounds<F>, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1042 | Cube<F, N>: P2Minimise<Loc<F, N>, F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1043 | PlotLookup : Plotting<N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1044 | DiscreteMeasure<Loc<F, N>, F> : SpikeMerging<F> { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1045 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1046 | pointsource_fb_reg(opA, b, NonnegRadonRegTerm(α), op𝒟, config, iterator, plotter) |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1047 | } |
0 | 1048 | |
1049 | ||
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1050 | #[deprecated(note = "Use `generic_pointsource_fb_reg`")] |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1051 | pub fn generic_pointsource_fb<'a, F, I, A, GA, 𝒟, BTA, G𝒟, S, K, Spec, const N : usize>( |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1052 | opA : &'a A, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1053 | α : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1054 | op𝒟 : &'a 𝒟, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1055 | τ : F, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1056 | config : &FBGenericConfig<F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1057 | iterator : I, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1058 | plotter : SeqPlotter<F, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1059 | residual : A::Observable, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1060 | specialisation : Spec, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1061 | ) -> DiscreteMeasure<Loc<F, N>, F> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1062 | where F : Float + ToNalgebraRealField, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1063 | I : AlgIteratorFactory<IterInfo<F, N>>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1064 | Spec : FBSpecialisation<F, A::Observable, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1065 | A::Observable : std::ops::MulAssign<F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1066 | GA : SupportGenerator<F, N, SupportType = S, Id = usize> + Clone, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1067 | A : ForwardModel<Loc<F, N>, F, PreadjointCodomain = BTFN<F, GA, BTA, N>> |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1068 | + Lipschitz<𝒟, FloatType=F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1069 | BTA : BTSearch<F, N, Data=usize, Agg=Bounds<F>>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1070 | G𝒟 : SupportGenerator<F, N, SupportType = K, Id = usize> + Clone, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1071 | 𝒟 : DiscreteMeasureOp<Loc<F, N>, F, PreCodomain = PreBTFN<F, G𝒟, N>>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1072 | 𝒟::Codomain : RealMapping<F, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1073 | S: RealMapping<F, N> + LocalAnalysis<F, Bounds<F>, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1074 | K: RealMapping<F, N> + LocalAnalysis<F, Bounds<F>, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1075 | BTNodeLookup: BTNode<F, usize, Bounds<F>, N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1076 | Cube<F, N>: P2Minimise<Loc<F, N>, F>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1077 | PlotLookup : Plotting<N>, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1078 | DiscreteMeasure<Loc<F, N>, F> : SpikeMerging<F> { |
0 | 1079 | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1080 | generic_pointsource_fb_reg(opA, NonnegRadonRegTerm(α), op𝒟, τ, config, iterator, plotter, |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1081 | residual, specialisation) |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
1082 | } |