src/pdps.rs

Thu, 26 Feb 2026 11:36:22 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Thu, 26 Feb 2026 11:36:22 -0500
branch
dev
changeset 63
7a8a55fd41c0
parent 61
4f468d35fa29
permissions
-rw-r--r--

Subproblem solver and sliding adjustments/improvements

0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1 /*!
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
2 Solver for the point source localisation problem with primal-dual proximal splitting.
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
3
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
4 This corresponds to the manuscript
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
5
13
bdc57366d4f5 arXiv links, README beautification
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
6 * Valkonen T. - _Proximal methods for point source localisation_,
bdc57366d4f5 arXiv links, README beautification
Tuomo Valkonen <tuomov@iki.fi>
parents: 0
diff changeset
7 [arXiv:2212.02991](https://arxiv.org/abs/2212.02991).
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
8
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
9 The main routine is [`pointsource_pdps_reg`].
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
10 Both norm-2-squared and norm-1 data terms are supported. That is, implemented are solvers for
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
11 <div>
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
12 $$
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
13 \min_{μ ∈ ℳ(Ω)}~ F_0(Aμ - b) + α \|μ\|_{ℳ(Ω)} + δ_{≥ 0}(μ),
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
14 $$
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
15 for both $F_0(y)=\frac{1}{2}\|y\|_2^2$ and $F_0(y)=\|y\|_1$ with the forward operator
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
16 $A \in 𝕃(ℳ(Ω); ℝ^n)$.
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
17 </div>
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
18
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
19 ## Approach
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
20
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
21 <p>
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
22 The problem above can be written as
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
23 $$
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
24 \min_μ \max_y G(μ) + ⟨y, Aμ-b⟩ - F_0^*(μ),
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
25 $$
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
26 where $G(μ) = α \|μ\|_{ℳ(Ω)} + δ_{≥ 0}(μ)$.
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
27 The Fenchel–Rockafellar optimality conditions, employing the predual in $ℳ(Ω)$, are
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
28 $$
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
29 0 ∈ A_*y + ∂G(μ)
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
30 \quad\text{and}\quad
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
31 Aμ - b ∈ ∂ F_0^*(y).
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
32 $$
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
33 The solution of the first part is as for forward-backward, treated in the manuscript.
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
34 This is the task of <code>generic_pointsource_fb</code>, where we use <code>FBSpecialisation</code>
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
35 to replace the specific residual $Aμ-b$ by $y$.
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
36 For $F_0(y)=\frac{1}{2}\|y\|_2^2$ the second part reads $y = Aμ -b$.
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
37 For $F_0(y)=\|y\|_1$ the second part reads $y ∈ ∂\|·\|_1(Aμ - b)$.
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
38 </p>
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
39 */
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
40
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
41 use crate::fb::{postprocess, prune_with_stats};
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
42 use crate::forward_model::ForwardModel;
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
43 use crate::measures::merging::SpikeMerging;
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
44 use crate::measures::merging::SpikeMergingMethod;
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
45 use crate::measures::{DiscreteMeasure, RNDM};
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
46 use crate::plot::Plotter;
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
47 pub use crate::prox_penalty::{InsertionConfig, ProxPenalty, StepLengthBoundPD};
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
48 use crate::regularisation::RegTerm;
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
49 use crate::types::*;
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
50 use alg_tools::convex::{Conjugable, ConvexMapping, Prox};
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
51 use alg_tools::error::DynResult;
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
52 use alg_tools::iterate::AlgIteratorFactory;
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
53 use alg_tools::linops::{Mapping, AXPY};
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
54 use alg_tools::mapping::{DataTerm, Instance};
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
55 use alg_tools::nalgebra_support::ToNalgebraRealField;
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
56 use anyhow::ensure;
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
57 use clap::ValueEnum;
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
58 use numeric_literals::replace_float_literals;
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
59 use serde::{Deserialize, Serialize};
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
60
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
61 /// Acceleration
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
62 #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, ValueEnum, Debug)]
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
63 pub enum Acceleration {
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
64 /// No acceleration
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
65 #[clap(name = "none")]
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
66 None,
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
67 /// Partial acceleration, $ω = 1/\sqrt{1+σ}$
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
68 #[clap(name = "partial", help = "Partial acceleration, ω = 1/√(1+σ)")]
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
69 Partial,
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
70 /// Full acceleration, $ω = 1/\sqrt{1+2σ}$; no gap convergence guaranteed
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
71 #[clap(
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
72 name = "full",
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
73 help = "Full acceleration, ω = 1/√(1+2σ); no gap convergence guaranteed"
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
74 )]
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
75 Full,
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
76 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
77
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
78 #[replace_float_literals(F::cast_from(literal))]
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
79 impl Acceleration {
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
80 /// PDPS parameter acceleration. Updates τ and σ and returns ω.
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
81 /// This uses dual strong convexity, not primal.
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
82 fn accelerate<F: Float>(self, τ: &mut F, σ: &mut F, γ: F) -> F {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
83 match self {
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
84 Acceleration::None => 1.0,
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
85 Acceleration::Partial => {
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
86 let ω = 1.0 / (1.0 + γ * (*σ)).sqrt();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
87 *σ *= ω;
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
88 *τ /= ω;
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
89 ω
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
90 }
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
91 Acceleration::Full => {
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
92 let ω = 1.0 / (1.0 + 2.0 * γ * (*σ)).sqrt();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
93 *σ *= ω;
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
94 *τ /= ω;
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
95 ω
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
96 }
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
97 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
98 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
99 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
100
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
101 /// Settings for [`pointsource_pdps_reg`].
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
102 #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)]
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
103 #[serde(default)]
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
104 pub struct PDPSConfig<F: Float> {
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
105 /// Primal step length scaling. We must have `τ0 * σ0 < 1`.
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
106 pub τ0: F,
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
107 /// Dual step length scaling. We must have `τ0 * σ0 < 1`.
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
108 pub σ0: F,
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
109 /// Accelerate if available
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
110 pub acceleration: Acceleration,
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
111 /// Generic parameters
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
112 pub generic: InsertionConfig<F>,
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
113 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
114
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
115 #[replace_float_literals(F::cast_from(literal))]
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
116 impl<F: Float> Default for PDPSConfig<F> {
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
117 fn default() -> Self {
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
118 let τ0 = 5.0;
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
119 PDPSConfig {
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
120 τ0,
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
121 σ0: 0.99 / τ0,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
122 acceleration: Acceleration::Partial,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
123 generic: InsertionConfig {
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
124 merging: SpikeMergingMethod { enabled: true, ..Default::default() },
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
125 ..Default::default()
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
126 },
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
127 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
128 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
129 }
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
130
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
131 /// Iteratively solve the pointsource localisation problem using primal-dual proximal splitting.
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
132 ///
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
133 /// The settings in `config` have their [respective documentation](PDPSConfig). `opA` is the
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
134 /// forward operator $A$, $b$ the observable, and $\lambda$ the regularisation weight.
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
135 /// The operator `op𝒟` is used for forming the proximal term. Typically it is a convolution
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
136 /// operator. Finally, the `iterator` is an outer loop verbosity and iteration count control
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
137 /// as documented in [`alg_tools::iterate`].
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
138 ///
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
139 /// For the mathematical formulation, see the [module level](self) documentation and the manuscript.
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
140 ///
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
141 /// Returns the final iterate.
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
142 #[replace_float_literals(F::cast_from(literal))]
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
143 pub fn pointsource_pdps_reg<'a, F, I, A, Phi, Reg, Plot, P, const N: usize>(
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
144 f: &'a DataTerm<F, RNDM<N, F>, A, Phi>,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
145 reg: &Reg,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
146 prox_penalty: &P,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
147 pdpsconfig: &PDPSConfig<F>,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
148 iterator: I,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
149 mut plotter: Plot,
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
150 μ0: Option<RNDM<N, F>>,
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
151 ) -> DynResult<RNDM<N, F>>
37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
152 where
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
153 F: Float + ToNalgebraRealField,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
154 I: AlgIteratorFactory<IterInfo<F>>,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
155 A: ForwardModel<RNDM<N, F>, F>,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
156 for<'b> &'b A::Observable: Instance<A::Observable>,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
157 A::Observable: AXPY<Field = F>,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
158 RNDM<N, F>: SpikeMerging<F>,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
159 Reg: RegTerm<Loc<N, F>, F>,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
160 Phi: Conjugable<A::Observable, F>,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
161 for<'b> Phi::Conjugate<'b>: Prox<A::Observable>,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
162 P: ProxPenalty<Loc<N, F>, A::PreadjointCodomain, Reg, F> + StepLengthBoundPD<F, A, RNDM<N, F>>,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
163 Plot: Plotter<P::ReturnMapping, A::PreadjointCodomain, RNDM<N, F>>,
37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
164 {
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
165 // Check parameters
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
166 ensure!(
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
167 pdpsconfig.τ0 > 0.0 && pdpsconfig.σ0 > 0.0 && pdpsconfig.τ0 * pdpsconfig.σ0 <= 1.0,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
168 "Invalid step length parameters"
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
169 );
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
170
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
171 let opA = f.operator();
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
172 let b = f.data();
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
173 let phistar = f.fidelity().conjugate();
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
174
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
175 // Set up parameters
34
efa60bc4f743 Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 32
diff changeset
176 let config = &pdpsconfig.generic;
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
177 let l = prox_penalty.step_length_bound_pd(opA)?;
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
178 let mut τ = pdpsconfig.τ0 / l;
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
179 let mut σ = pdpsconfig.σ0 / l;
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
180 let γ = phistar.factor_of_strong_convexity();
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
181
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
182 // We multiply tolerance by τ for FB since our subproblems depending on tolerances are scaled
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
183 // by τ compared to the conditional gradient approach.
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
184 let tolerance = config.tolerance * τ * reg.tolerance_scaling();
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
185 let mut ε = tolerance.initial();
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
186
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
187 // Initialise iterates
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
188 let mut μ = μ0.unwrap_or_else(|| DiscreteMeasure::new());
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
189 let mut y = f.residual(&μ);
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
190 let full_stats = |μ: &RNDM<N, F>, ε, stats| IterInfo {
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
191 value: f.apply(μ) + reg.apply(μ),
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
192 n_spikes: μ.len(),
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
193 ε,
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
194 // postprocessing: config.postprocessing.then(|| μ.clone()),
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
195 ..stats
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
196 };
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
197 let mut stats = IterInfo::new();
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
198
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
199 // Run the algorithm
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
200 for state in iterator.iter_init(|| full_stats(&μ, ε, stats.clone())) {
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
201 // Calculate smooth part of surrogate model.
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
202 // FIXME: the clone is required to avoid compiler overflows with reference-Mul requirement above.
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
203 let mut τv = opA.preadjoint().apply(y.clone() * τ);
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
204
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
205 // Save current base point
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
206 let μ_base = μ.clone();
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
207
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
208 // Insert and reweigh
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
209 let (maybe_d, _within_tolerances) = prox_penalty
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
210 .insert_and_reweigh(&mut μ, &mut τv, τ, ε, config, &reg, &state, &mut stats)?;
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
211
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
212 // Prune and possibly merge spikes
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
213 if config.merge_now(&state) {
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
214 stats.merged +=
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
215 prox_penalty.merge_spikes_no_fitness(&mut μ, &mut τv, &μ_base, τ, ε, config, &reg);
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
216 }
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
217 stats.inserted += μ.len() - μ_base.len();
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
218 stats.pruned += prune_with_stats(&mut μ);
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
219
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
220 // Update step length parameters
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
221 let ω = pdpsconfig.acceleration.accelerate(&mut τ, &mut σ, γ);
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
222
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
223 // Do dual update
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
224 // y = y_prev + τb
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
225 y.axpy(τ, b, 1.0);
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
226 // y = y_prev - τ(A[(1+ω)μ^{k+1}]-b)
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
227 opA.gemv(&mut y, -τ * (1.0 + ω), &μ, 1.0);
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
228 // y = y_prev - τ(A[(1+ω)μ^{k+1} - ω μ^k]-b)
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
229 opA.gemv(&mut y, τ * ω, &μ_base, 1.0);
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
230 y = phistar.prox(τ, y);
0
eb3c7813b67a Initial version
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
231
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
232 // Give statistics if requested
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
233 let iter = state.iteration();
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
234 stats.this_iters += 1;
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
235
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
236 state.if_verbose(|| {
37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
237 plotter.plot_spikes(iter, maybe_d.as_ref(), Some(&τv), &μ);
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
238 full_stats(&μ, ε, std::mem::replace(&mut stats, IterInfo::new()))
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
239 });
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
240
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
241 ε = tolerance.update(ε, iter);
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
242 }
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents: 29
diff changeset
243
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
244 postprocess(μ, config, |μ| f.apply(μ))
24
d29d1fcf5423 Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents: 13
diff changeset
245 }

mercurial