Thu, 06 Aug 2026 11:14:15 -0500
Generalise algorithms to arbitrary domains
| 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 | ||
| 89 | 80 | use crate::domain::{AdmissibleDomain, FullSpace}; |
|
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
|
81 | use crate::measures::merging::SpikeMerging; |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
82 | use crate::measures::DiscreteMeasure; |
|
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
|
83 | 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
|
84 | 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
|
85 | 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
|
86 | 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
|
87 | 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
|
88 | 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
|
89 | use alg_tools::iterate::AlgIteratorFactory; |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
90 | use alg_tools::linops::Space; |
|
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
|
91 | 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
|
92 | use alg_tools::nalgebra_support::ToNalgebraRealField; |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
93 | use colored::Colorize; |
| 89 | 94 | use measures::DeltaMeasure; |
| 0 | 95 | use numeric_literals::replace_float_literals; |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
96 | use serde::{Deserialize, Serialize}; |
| 0 | 97 | |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
98 | /// Settings for [`pointsource_fb_reg`]. |
| 0 | 99 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] |
| 100 | #[serde(default)] | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
101 | pub struct FBConfig<F: Float> { |
| 0 | 102 | /// Step length scaling |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
103 | 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
|
104 | // 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
|
105 | pub σp0: F, |
| 0 | 106 | /// 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
|
107 | pub insertion: InsertionConfig<F>, |
| 0 | 108 | } |
| 109 | ||
| 110 | #[replace_float_literals(F::cast_from(literal))] | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
111 | impl<F: Float> Default for FBConfig<F> { |
| 0 | 112 | fn default() -> Self { |
|
63
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
113 | FBConfig { τ0: 0.99, σp0: 0.99, insertion: Default::default() } |
| 0 | 114 | } |
| 115 | } | |
| 116 | ||
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
117 | pub(crate) fn prune_with_stats<U: Space, F: Float>( |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
118 | μ: &mut DiscreteMeasure<U, F>, |
|
91
47d495348e38
Do not prune new insertions on first round
Tuomo Valkonen <tuomov@iki.fi>
parents:
89
diff
changeset
|
119 | until: usize, |
|
47d495348e38
Do not prune new insertions on first round
Tuomo Valkonen <tuomov@iki.fi>
parents:
89
diff
changeset
|
120 | ) -> usize { |
| 32 | 121 | let n_before_prune = μ.len(); |
|
91
47d495348e38
Do not prune new insertions on first round
Tuomo Valkonen <tuomov@iki.fi>
parents:
89
diff
changeset
|
122 | μ.prune_until(until); |
| 32 | 123 | debug_assert!(μ.len() <= n_before_prune); |
| 35 | 124 | n_before_prune - μ.len() |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
125 | } |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
126 | |
| 32 | 127 | #[replace_float_literals(F::cast_from(literal))] |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
128 | pub(crate) fn postprocess<F: Float, U, Dat>( |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
129 | mut μ: DiscreteMeasure<U, 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
|
130 | 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
|
131 | f: Dat, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
132 | ) -> DynResult<DiscreteMeasure<U, F>> |
| 35 | 133 | where |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
134 | Dat: Fn(&DiscreteMeasure<U, F>) -> F, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
135 | U: Space + Clone, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
136 | DiscreteMeasure<U, F>: SpikeMerging<F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
137 | for<'a> &'a DiscreteMeasure<U, F>: Instance<DiscreteMeasure<U, F>>, |
| 35 | 138 | { |
|
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
|
139 | //μ.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
|
140 | μ.merge_spikes_fitness(config.final_merging_method(), f, |&v| v); |
| 32 | 141 | μ.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
|
142 | Ok(μ) |
| 32 | 143 | } |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
144 | |
| 32 | 145 | /// Iteratively solve the pointsource localisation problem using forward-backward splitting. |
| 0 | 146 | /// |
| 32 | 147 | /// The settings in `config` have their [respective documentation](FBConfig). `opA` is the |
| 0 | 148 | /// forward operator $A$, $b$ the observable, and $\lambda$ the regularisation weight. |
| 149 | /// The operator `op𝒟` is used for forming the proximal term. Typically it is a convolution | |
| 150 | /// operator. Finally, the `iterator` is an outer loop verbosity and iteration count control | |
| 151 | /// as documented in [`alg_tools::iterate`]. | |
| 152 | /// | |
| 32 | 153 | /// For details on the mathematical formulation, see the [module level](self) documentation. |
| 154 | /// | |
| 0 | 155 | /// Returns the final iterate. |
| 156 | #[replace_float_literals(F::cast_from(literal))] | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
157 | pub fn pointsource_fb_dom<F, I, Dat, Reg, P, Plot, U>( |
|
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
|
158 | 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
|
159 | reg: &Reg, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
160 | prox_penalty: &P, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
161 | fbconfig: &FBConfig<F>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
162 | 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
|
163 | mut plotter: Plot, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
164 | μ0: Option<DiscreteMeasure<U, F>>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
165 | domain: &mut impl AdmissibleDomain<U>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
166 | ) -> DynResult<DiscreteMeasure<U, F>> |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
167 | where |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
168 | U: Space + Clone, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
169 | 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
|
170 | I: AlgIteratorFactory<IterInfo<F>>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
171 | DiscreteMeasure<U, F>: SpikeMerging<F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
172 | Dat: DifferentiableMapping<DiscreteMeasure<U, F>, Codomain = 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
|
173 | Dat::DerivativeDomain: ClosedMul<F>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
174 | Reg: RegTerm<U, F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
175 | P: ProxPenalty<U, Dat::DerivativeDomain, Reg, F> + StepLengthBound<F, Dat>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
176 | Plot: Plotter<P::ReturnMapping, Dat::DerivativeDomain, DiscreteMeasure<U, F>>, |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
177 | { |
| 32 | 178 | // 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
|
179 | 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
|
180 | let τ = fbconfig.τ0 / prox_penalty.step_length_bound(&f)?; |
| 32 | 181 | // We multiply tolerance by τ for FB since our subproblems depending on tolerances are scaled |
| 182 | // by τ compared to the conditional gradient approach. | |
| 183 | let tolerance = config.tolerance * τ * reg.tolerance_scaling(); | |
| 184 | let mut ε = tolerance.initial(); | |
| 185 | ||
| 186 | // 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
|
187 | let mut μ = μ0.unwrap_or_else(|| DiscreteMeasure::new()); |
| 35 | 188 | |
| 189 | // Statistics | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
190 | let full_stats = |μ: &DiscreteMeasure<U, F>, ε, stats| IterInfo { |
|
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
|
191 | value: f.apply(μ) + reg.apply(μ), |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
192 | n_spikes: μ.len(), |
| 35 | 193 | ε, |
| 194 | //postprocessing: config.postprocessing.then(|| μ.clone()), | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
195 | ..stats |
| 35 | 196 | }; |
| 32 | 197 | let mut stats = IterInfo::new(); |
| 198 | ||
| 199 | // 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
|
200 | for state in iterator.iter_init(|| full_stats(&μ, ε, stats.clone())) { |
| 89 | 201 | let maybe_μ_base = config.if_merge_now_check(&state, || μ.clone()); |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
202 | let μ_base_len = μ.len(); |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
203 | |
| 32 | 204 | // 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
|
205 | let mut τv = f.differential(&μ) * τ; |
| 32 | 206 | |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
207 | // Do spike insertiona nd finite-dimensional weight optimisation |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
208 | prox_penalty.insert_and_reweigh(&mut μ, &mut τv, τ, ε, config, ®, &state, &mut stats)?; |
|
63
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
209 | |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
210 | stats.inserted += μ.len() - μ_base_len; |
| 32 | 211 | |
| 212 | // Prune and possibly merge spikes | |
| 89 | 213 | let did_merge = if let Some(μ_base) = maybe_μ_base { |
| 214 | // Merge spikes. | |
| 215 | // This crucially expects the merge routine to be stable with respect to spike locations, | |
| 216 | // and not to performing any pruning. That is be to done below simultaneously for γ. | |
|
78
2a122736e91c
Add maximum iteration setting for scaling heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
217 | config.if_merge_now(&state, |ins| { |
|
2a122736e91c
Add maximum iteration setting for scaling heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
218 | stats.merged += prox_penalty.merge_spikes( |
|
2a122736e91c
Add maximum iteration setting for scaling heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
219 | &mut μ, |
|
2a122736e91c
Add maximum iteration setting for scaling heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
220 | &mut τv, |
|
2a122736e91c
Add maximum iteration setting for scaling heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
221 | &μ_base, |
|
2a122736e91c
Add maximum iteration setting for scaling heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
222 | τ, |
|
2a122736e91c
Add maximum iteration setting for scaling heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
223 | ε, |
|
2a122736e91c
Add maximum iteration setting for scaling heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
224 | ins, |
|
2a122736e91c
Add maximum iteration setting for scaling heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
225 | ®, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
226 | Some(|μ̃: &DiscreteMeasure<U, F>| f.apply(μ̃) + reg.apply(μ̃)), |
| 89 | 227 | ); |
|
91
47d495348e38
Do not prune new insertions on first round
Tuomo Valkonen <tuomov@iki.fi>
parents:
89
diff
changeset
|
228 | |
|
47d495348e38
Do not prune new insertions on first round
Tuomo Valkonen <tuomov@iki.fi>
parents:
89
diff
changeset
|
229 | // Prune. Do not prune new insertions on first round. |
|
47d495348e38
Do not prune new insertions on first round
Tuomo Valkonen <tuomov@iki.fi>
parents:
89
diff
changeset
|
230 | stats.pruned += prune_with_stats(&mut μ, μ_base_len); |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
231 | |
| 89 | 232 | if config.random_insertions { |
| 233 | if let Some(x) = domain.random_point() { | |
| 234 | μ += DeltaMeasure { x, α: 0.0 }; | |
| 235 | stats.inserted += 1; | |
| 236 | } | |
| 237 | } | |
| 32 | 238 | |
| 89 | 239 | // Do extra weight optimisation step heuristic |
| 240 | for _ in 1..config.extra_weight_optimisation_steps { | |
| 241 | τv = f.differential(&μ) * τ; | |
| 242 | prox_penalty | |
| 243 | .reweigh(&mut μ, &mut τv, τ, ε, &config, ®, &state, &mut stats)?; | |
| 244 | } | |
| 245 | Ok(()) | |
| 246 | })? | |
| 247 | } else { | |
| 248 | None | |
| 249 | }; | |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
250 | |
| 89 | 251 | if did_merge.is_none() { |
|
91
47d495348e38
Do not prune new insertions on first round
Tuomo Valkonen <tuomov@iki.fi>
parents:
89
diff
changeset
|
252 | // Prune. Do not prune new insertions on first round. |
|
47d495348e38
Do not prune new insertions on first round
Tuomo Valkonen <tuomov@iki.fi>
parents:
89
diff
changeset
|
253 | stats.pruned += prune_with_stats(&mut μ, μ_base_len); |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
254 | } |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
255 | |
| 35 | 256 | let iter = state.iteration(); |
| 32 | 257 | stats.this_iters += 1; |
| 258 | ||
| 35 | 259 | // Give statistics if needed |
| 32 | 260 | state.if_verbose(|| { |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
261 | plotter.plot_spikes(iter, None, 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
|
262 | full_stats(&μ, ε, std::mem::replace(&mut stats, IterInfo::new())) |
| 35 | 263 | }); |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
264 | |
| 35 | 265 | // Update main tolerance for next iteration |
| 266 | ε = tolerance.update(ε, iter); | |
| 267 | } | |
| 32 | 268 | |
|
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
|
269 | //postprocess(μ_prev, config, f) |
| 84 | 270 | postprocess(μ, config, |μ̃| f.apply(μ̃) + reg.apply(μ̃)) |
| 32 | 271 | } |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
13
diff
changeset
|
272 | |
| 89 | 273 | #[deprecated] |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
274 | pub fn pointsource_fb_reg<F, U, I, Dat, Reg, P, Plot>( |
| 89 | 275 | f: &Dat, |
| 276 | reg: &Reg, | |
| 277 | prox_penalty: &P, | |
| 278 | fbconfig: &FBConfig<F>, | |
| 279 | iterator: I, | |
| 280 | plotter: Plot, | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
281 | μ0: Option<DiscreteMeasure<U, F>>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
282 | ) -> DynResult<DiscreteMeasure<U, F>> |
| 89 | 283 | where |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
284 | U: Space + Clone, |
| 89 | 285 | F: Float + ToNalgebraRealField, |
| 286 | I: AlgIteratorFactory<IterInfo<F>>, | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
287 | DiscreteMeasure<U, F>: SpikeMerging<F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
288 | Dat: DifferentiableMapping<DiscreteMeasure<U, F>, Codomain = F>, |
| 89 | 289 | Dat::DerivativeDomain: ClosedMul<F>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
290 | Reg: RegTerm<U, F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
291 | P: ProxPenalty<U, Dat::DerivativeDomain, Reg, F> + StepLengthBound<F, Dat>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
292 | Plot: Plotter<P::ReturnMapping, Dat::DerivativeDomain, DiscreteMeasure<U, F>>, |
| 89 | 293 | { |
| 294 | pointsource_fb_dom( | |
| 295 | f, | |
| 296 | reg, | |
| 297 | prox_penalty, | |
| 298 | fbconfig, | |
| 299 | iterator, | |
| 300 | plotter, | |
| 301 | μ0, | |
| 302 | &mut FullSpace, | |
| 303 | ) | |
| 304 | } | |
| 305 | ||
| 32 | 306 | /// Iteratively solve the pointsource localisation problem using inertial forward-backward splitting. |
| 307 | /// | |
| 308 | /// The settings in `config` have their [respective documentation](FBConfig). `opA` is the | |
| 309 | /// forward operator $A$, $b$ the observable, and $\lambda$ the regularisation weight. | |
| 310 | /// The operator `op𝒟` is used for forming the proximal term. Typically it is a convolution | |
| 311 | /// operator. Finally, the `iterator` is an outer loop verbosity and iteration count control | |
| 312 | /// as documented in [`alg_tools::iterate`]. | |
| 313 | /// | |
| 314 | /// For details on the mathematical formulation, see the [module level](self) documentation. | |
| 315 | /// | |
| 316 | /// Returns the final iterate. | |
| 317 | #[replace_float_literals(F::cast_from(literal))] | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
318 | pub fn pointsource_fista_reg<F, U, I, Dat, Reg, P, Plot>( |
|
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
|
319 | 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
|
320 | reg: &Reg, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
321 | prox_penalty: &P, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
322 | fbconfig: &FBConfig<F>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
323 | 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
|
324 | mut plotter: Plot, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
325 | μ0: Option<DiscreteMeasure<U, F>>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
326 | ) -> DynResult<DiscreteMeasure<U, F>> |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
327 | where |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
328 | U: Space + Clone, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
329 | 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
|
330 | I: AlgIteratorFactory<IterInfo<F>>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
331 | DiscreteMeasure<U, F>: SpikeMerging<F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
332 | Dat: DifferentiableMapping<DiscreteMeasure<U, F>, Codomain = 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
|
333 | Dat::DerivativeDomain: ClosedMul<F>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
334 | Reg: RegTerm<U, F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
335 | P: ProxPenalty<U, Dat::DerivativeDomain, Reg, F> + StepLengthBound<F, Dat>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
336 | Plot: Plotter<P::ReturnMapping, Dat::DerivativeDomain, DiscreteMeasure<U, F>>, |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
337 | { |
| 32 | 338 | // 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
|
339 | 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
|
340 | let τ = fbconfig.τ0 / prox_penalty.step_length_bound(&f)?; |
| 32 | 341 | let mut λ = 1.0; |
| 342 | // We multiply tolerance by τ for FB since our subproblems depending on tolerances are scaled | |
| 343 | // by τ compared to the conditional gradient approach. | |
| 344 | let tolerance = config.tolerance * τ * reg.tolerance_scaling(); | |
| 345 | let mut ε = tolerance.initial(); | |
| 346 | ||
| 347 | // 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
|
348 | 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
|
349 | let mut μ_prev = μ.clone(); |
| 35 | 350 | let mut warned_merging = false; |
| 351 | ||
| 352 | // Statistics | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
353 | let full_stats = |ν: &DiscreteMeasure<U, F>, ε, stats| IterInfo { |
|
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
|
354 | value: f.apply(ν) + reg.apply(ν), |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
355 | n_spikes: ν.len(), |
| 35 | 356 | ε, |
| 357 | // postprocessing: config.postprocessing.then(|| ν.clone()), | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
358 | ..stats |
| 35 | 359 | }; |
| 32 | 360 | let mut stats = IterInfo::new(); |
| 361 | ||
| 362 | // Run the algorithm | |
| 35 | 363 | for state in iterator.iter_init(|| full_stats(&μ, ε, stats.clone())) { |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
364 | let μ_base_len = μ.len(); |
| 32 | 365 | // 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
|
366 | let mut τv = f.differential(&μ) * τ; |
| 32 | 367 | |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
368 | // Do spike insertiona nd finite-dimensional weight optimisation |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
369 | prox_penalty.insert_and_reweigh(&mut μ, &mut τv, τ, ε, config, ®, &state, &mut stats)?; |
|
63
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
370 | |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
371 | stats.inserted += μ.len() - μ_base_len; |
| 32 | 372 | |
| 373 | // (Do not) merge spikes. | |
|
78
2a122736e91c
Add maximum iteration setting for scaling heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
374 | if !warned_merging { |
| 89 | 375 | config.if_merge_now_check(&state, || { |
|
78
2a122736e91c
Add maximum iteration setting for scaling heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
376 | let err = format!("Merging not supported for μFISTA"); |
|
2a122736e91c
Add maximum iteration setting for scaling heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
377 | println!("{}", err.red()); |
|
2a122736e91c
Add maximum iteration setting for scaling heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
378 | warned_merging = true; |
|
2a122736e91c
Add maximum iteration setting for scaling heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
75
diff
changeset
|
379 | }); |
| 32 | 380 | } |
| 381 | ||
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
382 | // Do extra weight optimisation step heuristic |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
383 | for _ in 0..config.extra_weight_optimisation_steps { |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
384 | τv = f.differential(&μ) * τ; |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
385 | prox_penalty.reweigh(&mut μ, &mut τv, τ, ε, config, ®, &state, &mut stats)?; |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
386 | } |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
387 | |
| 32 | 388 | // Update inertial prameters |
| 389 | let λ_prev = λ; | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
390 | λ = 2.0 * λ_prev / (λ_prev + (4.0 + λ_prev * λ_prev).sqrt()); |
| 32 | 391 | let θ = λ / λ_prev - λ; |
| 392 | ||
| 393 | // Perform inertial update on μ. | |
| 394 | // This computes μ ← (1 + θ) * μ - θ * μ_prev, pruning spikes where both μ | |
| 395 | // and μ_prev have zero weight. Since both have weights from the finite-dimensional | |
| 396 | // subproblem with a proximal projection step, this is likely to happen when the | |
| 397 | // spike is not needed. A copy of the pruned μ without artithmetic performed is | |
| 398 | // stored in μ_prev. | |
| 399 | let n_before_prune = μ.len(); | |
| 400 | μ.pruning_sub(1.0 + θ, θ, &mut μ_prev); | |
|
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
401 | //let μ_new = (&μ * (1.0 + θ)).sub_matching(&(&μ_prev * θ)); |
|
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
402 | // μ_prev = μ; |
|
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
403 | // μ = μ_new; |
| 32 | 404 | debug_assert!(μ.len() <= n_before_prune); |
| 405 | stats.pruned += n_before_prune - μ.len(); | |
| 406 | ||
| 35 | 407 | let iter = state.iteration(); |
| 32 | 408 | stats.this_iters += 1; |
| 409 | ||
| 35 | 410 | // Give statistics if needed |
| 32 | 411 | state.if_verbose(|| { |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
412 | plotter.plot_spikes(iter, None, Some(&τv), &μ_prev); |
| 35 | 413 | full_stats(&μ_prev, ε, std::mem::replace(&mut stats, IterInfo::new())) |
| 414 | }); | |
| 415 | ||
| 416 | // Update main tolerance for next iteration | |
| 417 | ε = tolerance.update(ε, iter); | |
| 418 | } | |
| 32 | 419 | |
|
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
|
420 | //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
|
421 | 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
|
422 | } |