Thu, 19 Mar 2026 18:21:17 -0500
Remove apparently now unused dec2flt feature request
| 0 | 1 | /*! |
| 2 | Solver for the point source localisation problem using a forward-backward splitting method. | |
| 3 | ||
| 4 | This corresponds to the manuscript | |
| 5 | ||
|
13
bdc57366d4f5
arXiv links, README beautification
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
6 | * Valkonen T. - _Proximal methods for point source localisation_, |
|
bdc57366d4f5
arXiv links, README beautification
Tuomo Valkonen <tuomov@iki.fi>
parents:
8
diff
changeset
|
7 | [arXiv:2212.02991](https://arxiv.org/abs/2212.02991). |
| 0 | 8 | |
| 35 | 9 | The main routine is [`pointsource_fb_reg`]. |
| 0 | 10 | |
| 11 | ## Problem | |
| 12 | ||
| 13 | <p> | |
| 14 | Our objective is to solve | |
| 15 | $$ | |
| 16 | \min_{μ ∈ ℳ(Ω)}~ F_0(Aμ-b) + α \|μ\|_{ℳ(Ω)} + δ_{≥ 0}(μ), | |
| 17 | $$ | |
| 18 | where $F_0(y)=\frac{1}{2}\|y\|_2^2$ and the forward operator $A \in 𝕃(ℳ(Ω); ℝ^n)$. | |
| 19 | </p> | |
| 20 | ||
| 21 | ## Approach | |
| 22 | ||
| 23 | <p> | |
| 24 | As documented in more detail in the paper, on each step we approximately solve | |
| 25 | $$ | |
| 26 | \min_{μ ∈ ℳ(Ω)}~ F(x) + α \|μ\|_{ℳ(Ω)} + δ_{≥ 0}(x) + \frac{1}{2}\|μ-μ^k|_𝒟^2, | |
| 27 | $$ | |
| 28 | where $𝒟: 𝕃(ℳ(Ω); C_c(Ω))$ is typically a convolution operator. | |
| 29 | </p> | |
| 30 | ||
| 31 | ## Finite-dimensional subproblems. | |
| 32 | ||
| 33 | With $C$ a projection from [`DiscreteMeasure`] to the weights, and $x^k$ such that $x^k=Cμ^k$, we | |
| 34 | form the discretised linearised inner problem | |
| 35 | <p> | |
| 36 | $$ | |
| 37 | \min_{x ∈ ℝ^n}~ τ\bigl(F(Cx^k) + [C^*∇F(Cx^k)]^⊤(x-x^k) + α {\vec 1}^⊤ x\bigr) | |
| 38 | + δ_{≥ 0}(x) + \frac{1}{2}\|x-x^k\|_{C^*𝒟C}^2, | |
| 39 | $$ | |
| 40 | equivalently | |
| 41 | $$ | |
| 42 | \begin{aligned} | |
| 43 | \min_x~ & τF(Cx^k) - τ[C^*∇F(Cx^k)]^⊤x^k + \frac{1}{2} (x^k)^⊤ C^*𝒟C x^k | |
| 44 | \\ | |
| 45 | & | |
| 46 | - [C^*𝒟C x^k - τC^*∇F(Cx^k)]^⊤ x | |
| 47 | \\ | |
| 48 | & | |
| 49 | + \frac{1}{2} x^⊤ C^*𝒟C x | |
| 50 | + τα {\vec 1}^⊤ x + δ_{≥ 0}(x), | |
| 51 | \end{aligned} | |
| 52 | $$ | |
| 53 | In other words, we obtain the quadratic non-negativity constrained problem | |
| 54 | $$ | |
| 55 | \min_{x ∈ ℝ^n}~ \frac{1}{2} x^⊤ Ã x - b̃^⊤ x + c + τα {\vec 1}^⊤ x + δ_{≥ 0}(x). | |
| 56 | $$ | |
| 57 | where | |
| 58 | $$ | |
| 59 | \begin{aligned} | |
| 60 | Ã & = C^*𝒟C, | |
| 61 | \\ | |
| 62 | g̃ & = C^*𝒟C x^k - τ C^*∇F(Cx^k) | |
| 63 | = C^* 𝒟 μ^k - τ C^*A^*(Aμ^k - b) | |
| 64 | \\ | |
| 65 | c & = τ F(Cx^k) - τ[C^*∇F(Cx^k)]^⊤x^k + \frac{1}{2} (x^k)^⊤ C^*𝒟C x^k | |
| 66 | \\ | |
| 67 | & | |
| 68 | = \frac{τ}{2} \|Aμ^k-b\|^2 - τ[Aμ^k-b]^⊤Aμ^k + \frac{1}{2} \|μ_k\|_{𝒟}^2 | |
| 69 | \\ | |
| 70 | & | |
| 71 | = -\frac{τ}{2} \|Aμ^k-b\|^2 + τ[Aμ^k-b]^⊤ b + \frac{1}{2} \|μ_k\|_{𝒟}^2. | |
| 72 | \end{aligned} | |
| 73 | $$ | |
| 74 | </p> | |
| 75 | ||
| 35 | 76 | We solve this with either SSN or FB as determined by |
|
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:
51
diff
changeset
|
77 | [`crate::subproblem::InnerSettings`] in [`InsertionConfig::inner`]. |
| 0 | 78 | */ |
| 79 | ||
|
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:
51
diff
changeset
|
80 | use crate::measures::merging::SpikeMerging; |
|
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:
51
diff
changeset
|
81 | 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:
51
diff
changeset
|
82 | 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:
51
diff
changeset
|
83 | pub use crate::prox_penalty::{InsertionConfig, ProxPenalty, StepLengthBound}; |
|
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:
51
diff
changeset
|
84 | use crate::regularisation::RegTerm; |
|
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:
51
diff
changeset
|
85 | 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:
51
diff
changeset
|
86 | 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:
51
diff
changeset
|
87 | use alg_tools::instance::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:
51
diff
changeset
|
88 | 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:
51
diff
changeset
|
89 | use alg_tools::mapping::DifferentiableMapping; |
|
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:
51
diff
changeset
|
90 | use alg_tools::nalgebra_support::ToNalgebraRealField; |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
91 | use colored::Colorize; |
| 0 | 92 | use numeric_literals::replace_float_literals; |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
93 | use serde::{Deserialize, Serialize}; |
| 0 | 94 | |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
95 | /// Settings for [`pointsource_fb_reg`]. |
| 0 | 96 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] |
| 97 | #[serde(default)] | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
98 | pub struct FBConfig<F: Float> { |
| 0 | 99 | /// Step length scaling |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
100 | pub τ0: 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:
51
diff
changeset
|
101 | // Auxiliary variable step length scaling for [`crate::forward_pdps::pointsource_fb_pair`] |
|
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:
51
diff
changeset
|
102 | pub σp0: F, |
| 0 | 103 | /// 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:
51
diff
changeset
|
104 | pub insertion: InsertionConfig<F>, |
| 0 | 105 | } |
| 106 | ||
| 107 | #[replace_float_literals(F::cast_from(literal))] | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
108 | impl<F: Float> Default for FBConfig<F> { |
| 0 | 109 | fn default() -> Self { |
|
63
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
110 | FBConfig { τ0: 0.99, σp0: 0.99, insertion: Default::default() } |
| 0 | 111 | } |
| 112 | } | |
| 113 | ||
|
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:
51
diff
changeset
|
114 | pub(crate) fn prune_with_stats<F: Float, const N: usize>(μ: &mut RNDM<N, F>) -> usize { |
| 32 | 115 | let n_before_prune = μ.len(); |
| 116 | μ.prune(); | |
| 117 | debug_assert!(μ.len() <= n_before_prune); | |
| 35 | 118 | n_before_prune - μ.len() |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
119 | } |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
120 | |
| 32 | 121 | #[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:
51
diff
changeset
|
122 | pub(crate) fn postprocess<F: Float, Dat: Fn(&RNDM<N, F>) -> F, 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:
51
diff
changeset
|
123 | mut μ: 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:
51
diff
changeset
|
124 | config: &InsertionConfig<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:
51
diff
changeset
|
125 | f: Dat, |
|
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:
51
diff
changeset
|
126 | ) -> DynResult<RNDM<N, F>> |
| 35 | 127 | 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:
51
diff
changeset
|
128 | 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:
51
diff
changeset
|
129 | for<'a> &'a RNDM<N, F>: Instance<RNDM<N, F>>, |
| 35 | 130 | { |
|
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:
51
diff
changeset
|
131 | //μ.merge_spikes_fitness(config.final_merging_method(), |μ̃| f.apply(μ̃), |&v| v); |
|
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:
51
diff
changeset
|
132 | μ.merge_spikes_fitness(config.final_merging_method(), f, |&v| v); |
| 32 | 133 | μ.prune(); |
|
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:
51
diff
changeset
|
134 | Ok(μ) |
| 32 | 135 | } |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
136 | |
| 32 | 137 | /// Iteratively solve the pointsource localisation problem using forward-backward splitting. |
| 0 | 138 | /// |
| 32 | 139 | /// The settings in `config` have their [respective documentation](FBConfig). `opA` is the |
| 0 | 140 | /// forward operator $A$, $b$ the observable, and $\lambda$ the regularisation weight. |
| 141 | /// The operator `op𝒟` is used for forming the proximal term. Typically it is a convolution | |
| 142 | /// operator. Finally, the `iterator` is an outer loop verbosity and iteration count control | |
| 143 | /// as documented in [`alg_tools::iterate`]. | |
| 144 | /// | |
| 32 | 145 | /// For details on the mathematical formulation, see the [module level](self) documentation. |
| 146 | /// | |
| 0 | 147 | /// Returns the final iterate. |
| 148 | #[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:
51
diff
changeset
|
149 | pub fn pointsource_fb_reg<F, I, Dat, Reg, P, Plot, 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:
51
diff
changeset
|
150 | f: &Dat, |
|
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:
51
diff
changeset
|
151 | reg: &Reg, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
152 | prox_penalty: &P, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
153 | fbconfig: &FBConfig<F>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
154 | iterator: I, |
|
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:
51
diff
changeset
|
155 | mut plotter: Plot, |
|
63
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
156 | μ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:
51
diff
changeset
|
157 | ) -> DynResult<RNDM<N, F>> |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
158 | where |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
159 | F: Float + ToNalgebraRealField, |
|
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:
51
diff
changeset
|
160 | 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:
51
diff
changeset
|
161 | 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:
51
diff
changeset
|
162 | Dat: DifferentiableMapping<RNDM<N, F>, Codomain = 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:
51
diff
changeset
|
163 | Dat::DerivativeDomain: ClosedMul<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:
51
diff
changeset
|
164 | 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:
51
diff
changeset
|
165 | P: ProxPenalty<Loc<N, F>, Dat::DerivativeDomain, Reg, F> + StepLengthBound<F, Dat>, |
|
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:
51
diff
changeset
|
166 | Plot: Plotter<P::ReturnMapping, Dat::DerivativeDomain, RNDM<N, F>>, |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
167 | { |
| 32 | 168 | // Set up 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:
51
diff
changeset
|
169 | let config = &fbconfig.insertion; |
|
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:
51
diff
changeset
|
170 | let τ = fbconfig.τ0 / prox_penalty.step_length_bound(&f)?; |
| 32 | 171 | // We multiply tolerance by τ for FB since our subproblems depending on tolerances are scaled |
| 172 | // by τ compared to the conditional gradient approach. | |
| 173 | let tolerance = config.tolerance * τ * reg.tolerance_scaling(); | |
| 174 | let mut ε = tolerance.initial(); | |
| 175 | ||
| 176 | // 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:
51
diff
changeset
|
177 | let mut μ = μ0.unwrap_or_else(|| DiscreteMeasure::new()); |
| 35 | 178 | |
| 179 | // Statistics | |
|
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:
51
diff
changeset
|
180 | 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:
51
diff
changeset
|
181 | value: f.apply(μ) + reg.apply(μ), |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
182 | n_spikes: μ.len(), |
| 35 | 183 | ε, |
| 184 | //postprocessing: config.postprocessing.then(|| μ.clone()), | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
185 | ..stats |
| 35 | 186 | }; |
| 32 | 187 | let mut stats = IterInfo::new(); |
| 188 | ||
| 189 | // Run the algorithm | |
|
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:
51
diff
changeset
|
190 | for state in iterator.iter_init(|| full_stats(&μ, ε, stats.clone())) { |
| 32 | 191 | // 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:
51
diff
changeset
|
192 | // TODO: optimise τ to be applied to 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:
51
diff
changeset
|
193 | let mut τv = f.differential(&μ) * τ; |
| 32 | 194 | |
|
63
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
195 | // Save current base point for merge |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
196 | let μ_base_len = μ.len(); |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
197 | let maybe_μ_base = config.merge_now(&state).then(|| μ.clone()); |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
198 | |
| 32 | 199 | // Insert and reweigh |
|
63
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
200 | let (maybe_d, _within_tolerances) = prox_penalty |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
201 | .insert_and_reweigh(&mut μ, &mut τv, τ, ε, config, ®, &state, &mut stats)?; |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
202 | |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
203 | stats.inserted += μ.len() - μ_base_len; |
| 32 | 204 | |
| 205 | // Prune and possibly merge spikes | |
|
63
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
206 | if let Some(μ_base) = maybe_μ_base { |
|
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
207 | stats.merged += prox_penalty.merge_spikes( |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
208 | &mut μ, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
209 | &mut τv, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
210 | &μ_base, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
211 | τ, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
212 | ε, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
213 | config, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
214 | ®, |
|
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:
51
diff
changeset
|
215 | Some(|μ̃: &RNDM<N, F>| f.apply(μ̃)), |
|
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
216 | ); |
| 35 | 217 | } |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
218 | |
| 35 | 219 | stats.pruned += prune_with_stats(&mut μ); |
| 32 | 220 | |
| 35 | 221 | let iter = state.iteration(); |
| 32 | 222 | stats.this_iters += 1; |
| 223 | ||
| 35 | 224 | // Give statistics if needed |
| 32 | 225 | state.if_verbose(|| { |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
226 | plotter.plot_spikes(iter, maybe_d.as_ref(), Some(&τv), &μ); |
|
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:
51
diff
changeset
|
227 | full_stats(&μ, ε, std::mem::replace(&mut stats, IterInfo::new())) |
| 35 | 228 | }); |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
229 | |
| 35 | 230 | // Update main tolerance for next iteration |
| 231 | ε = tolerance.update(ε, iter); | |
| 232 | } | |
| 32 | 233 | |
|
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:
51
diff
changeset
|
234 | //postprocess(μ_prev, config, 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:
51
diff
changeset
|
235 | postprocess(μ, config, |μ̃| f.apply(μ̃)) |
| 32 | 236 | } |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
237 | |
| 32 | 238 | /// Iteratively solve the pointsource localisation problem using inertial forward-backward splitting. |
| 239 | /// | |
| 240 | /// The settings in `config` have their [respective documentation](FBConfig). `opA` is the | |
| 241 | /// forward operator $A$, $b$ the observable, and $\lambda$ the regularisation weight. | |
| 242 | /// The operator `op𝒟` is used for forming the proximal term. Typically it is a convolution | |
| 243 | /// operator. Finally, the `iterator` is an outer loop verbosity and iteration count control | |
| 244 | /// as documented in [`alg_tools::iterate`]. | |
| 245 | /// | |
| 246 | /// For details on the mathematical formulation, see the [module level](self) documentation. | |
| 247 | /// | |
| 248 | /// Returns the final iterate. | |
| 249 | #[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:
51
diff
changeset
|
250 | pub fn pointsource_fista_reg<F, I, Dat, Reg, P, Plot, 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:
51
diff
changeset
|
251 | f: &Dat, |
|
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:
51
diff
changeset
|
252 | reg: &Reg, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
253 | prox_penalty: &P, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
254 | fbconfig: &FBConfig<F>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
255 | iterator: I, |
|
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:
51
diff
changeset
|
256 | mut plotter: Plot, |
|
63
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
257 | μ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:
51
diff
changeset
|
258 | ) -> DynResult<RNDM<N, F>> |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
259 | where |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
260 | F: Float + ToNalgebraRealField, |
|
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:
51
diff
changeset
|
261 | 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:
51
diff
changeset
|
262 | 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:
51
diff
changeset
|
263 | Dat: DifferentiableMapping<RNDM<N, F>, Codomain = 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:
51
diff
changeset
|
264 | Dat::DerivativeDomain: ClosedMul<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:
51
diff
changeset
|
265 | 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:
51
diff
changeset
|
266 | P: ProxPenalty<Loc<N, F>, Dat::DerivativeDomain, Reg, F> + StepLengthBound<F, Dat>, |
|
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:
51
diff
changeset
|
267 | Plot: Plotter<P::ReturnMapping, Dat::DerivativeDomain, RNDM<N, F>>, |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
268 | { |
| 32 | 269 | // Set up 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:
51
diff
changeset
|
270 | let config = &fbconfig.insertion; |
|
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:
51
diff
changeset
|
271 | let τ = fbconfig.τ0 / prox_penalty.step_length_bound(&f)?; |
| 32 | 272 | let mut λ = 1.0; |
| 273 | // We multiply tolerance by τ for FB since our subproblems depending on tolerances are scaled | |
| 274 | // by τ compared to the conditional gradient approach. | |
| 275 | let tolerance = config.tolerance * τ * reg.tolerance_scaling(); | |
| 276 | let mut ε = tolerance.initial(); | |
| 277 | ||
| 278 | // 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:
51
diff
changeset
|
279 | 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:
51
diff
changeset
|
280 | let mut μ_prev = μ.clone(); |
| 35 | 281 | let mut warned_merging = false; |
| 282 | ||
| 283 | // Statistics | |
|
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:
51
diff
changeset
|
284 | 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:
51
diff
changeset
|
285 | value: f.apply(ν) + reg.apply(ν), |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
286 | n_spikes: ν.len(), |
| 35 | 287 | ε, |
| 288 | // postprocessing: config.postprocessing.then(|| ν.clone()), | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
289 | ..stats |
| 35 | 290 | }; |
| 32 | 291 | let mut stats = IterInfo::new(); |
| 292 | ||
| 293 | // Run the algorithm | |
| 35 | 294 | for state in iterator.iter_init(|| full_stats(&μ, ε, stats.clone())) { |
| 32 | 295 | // 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:
51
diff
changeset
|
296 | let mut τv = f.differential(&μ) * τ; |
| 32 | 297 | |
|
63
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
298 | let μ_base_len = μ.len(); |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
299 | |
| 32 | 300 | // Insert new spikes and reweigh |
|
63
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
301 | let (maybe_d, _within_tolerances) = prox_penalty |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
302 | .insert_and_reweigh(&mut μ, &mut τv, τ, ε, config, ®, &state, &mut stats)?; |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
303 | |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
304 | stats.inserted += μ.len() - μ_base_len; |
| 32 | 305 | |
| 306 | // (Do not) merge spikes. | |
|
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
307 | if config.merge_now(&state) && !warned_merging { |
|
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
308 | let err = format!("Merging not supported for μFISTA"); |
|
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
309 | println!("{}", err.red()); |
|
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
310 | warned_merging = true; |
| 32 | 311 | } |
| 312 | ||
| 313 | // Update inertial prameters | |
| 314 | let λ_prev = λ; | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
315 | λ = 2.0 * λ_prev / (λ_prev + (4.0 + λ_prev * λ_prev).sqrt()); |
| 32 | 316 | let θ = λ / λ_prev - λ; |
| 317 | ||
| 318 | // Perform inertial update on μ. | |
| 319 | // This computes μ ← (1 + θ) * μ - θ * μ_prev, pruning spikes where both μ | |
| 320 | // and μ_prev have zero weight. Since both have weights from the finite-dimensional | |
| 321 | // subproblem with a proximal projection step, this is likely to happen when the | |
| 322 | // spike is not needed. A copy of the pruned μ without artithmetic performed is | |
| 323 | // stored in μ_prev. | |
| 324 | let n_before_prune = μ.len(); | |
| 325 | μ.pruning_sub(1.0 + θ, θ, &mut μ_prev); | |
|
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
326 | //let μ_new = (&μ * (1.0 + θ)).sub_matching(&(&μ_prev * θ)); |
|
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
327 | // μ_prev = μ; |
|
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
328 | // μ = μ_new; |
| 32 | 329 | debug_assert!(μ.len() <= n_before_prune); |
| 330 | stats.pruned += n_before_prune - μ.len(); | |
| 331 | ||
| 35 | 332 | let iter = state.iteration(); |
| 32 | 333 | stats.this_iters += 1; |
| 334 | ||
| 35 | 335 | // Give statistics if needed |
| 32 | 336 | state.if_verbose(|| { |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
337 | plotter.plot_spikes(iter, maybe_d.as_ref(), Some(&τv), &μ_prev); |
| 35 | 338 | full_stats(&μ_prev, ε, std::mem::replace(&mut stats, IterInfo::new())) |
| 339 | }); | |
| 340 | ||
| 341 | // Update main tolerance for next iteration | |
| 342 | ε = tolerance.update(ε, iter); | |
| 343 | } | |
| 32 | 344 | |
|
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:
51
diff
changeset
|
345 | //postprocess(μ_prev, config, 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:
51
diff
changeset
|
346 | postprocess(μ_prev, config, |μ̃| f.apply(μ̃)) |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
347 | } |