Thu, 06 Aug 2026 11:14:15 -0500
Generalise algorithms to arbitrary domains
| 35 | 1 | /*! |
| 2 | Solver for the point source localisation problem using a | |
| 3 | primal-dual proximal splitting with a forward step. | |
| 4 | */ | |
| 5 | ||
| 89 | 6 | 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:
39
diff
changeset
|
7 | use crate::fb::*; |
|
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
|
8 | use crate::measures::merging::SpikeMerging; |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
9 | 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:
39
diff
changeset
|
10 | 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
|
11 | use crate::prox_penalty::{ProxPenalty, StepLengthBoundPair}; |
|
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
|
12 | 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:
39
diff
changeset
|
13 | 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
|
14 | use alg_tools::convex::{Conjugable, Prox, Zero}; |
|
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
|
15 | use alg_tools::direct_product::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:
39
diff
changeset
|
16 | 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
|
17 | use alg_tools::euclidean::ClosedEuclidean; |
| 35 | 18 | use alg_tools::iterate::AlgIteratorFactory; |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
19 | use alg_tools::linops::{BoundedLinear, IdOp, SimplyAdjointable, Space, ZeroOp, AXPY, GEMV}; |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
20 | use alg_tools::mapping::{DifferentiableMapping, Instance}; |
| 35 | 21 | use alg_tools::nalgebra_support::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:
39
diff
changeset
|
22 | use alg_tools::norms::L2; |
|
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
|
23 | use anyhow::ensure; |
| 89 | 24 | use measures::DeltaMeasure; |
|
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
|
25 | 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
|
26 | use serde::{Deserialize, Serialize}; |
| 35 | 27 | |
| 28 | /// Settings for [`pointsource_forward_pdps_pair`]. | |
| 29 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] | |
| 30 | #[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
|
31 | pub struct ForwardPDPSConfig<F: Float> { |
|
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
|
32 | /// Overall primal step length scaling. |
|
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
|
33 | pub τ0: 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
|
34 | /// Primal step length scaling for additional variable. |
|
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
|
35 | pub σp0: 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
|
36 | /// Dual step length scaling for additional variable. |
|
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
|
37 | /// |
|
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
|
38 | /// Taken zero for [`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:
39
diff
changeset
|
39 | pub σd0: F, |
| 35 | 40 | /// 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
|
41 | pub insertion: InsertionConfig<F>, |
| 35 | 42 | } |
| 43 | ||
| 44 | #[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
|
45 | impl<F: Float> Default for ForwardPDPSConfig<F> { |
| 35 | 46 | fn default() -> Self { |
|
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
|
47 | ForwardPDPSConfig { τ0: 0.99, σd0: 0.05, σp0: 0.99, insertion: Default::default() } |
| 35 | 48 | } |
| 49 | } | |
| 50 | ||
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
51 | type MeasureZ<F, Z, U> = Pair<DiscreteMeasure<U, F>, Z>; |
| 35 | 52 | |
| 53 | /// Iteratively solve the pointsource localisation with an additional variable | |
| 54 | /// using primal-dual proximal splitting with a forward step. | |
|
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
|
55 | /// |
|
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 | /// The problem is |
|
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 | /// $$ |
|
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 | /// \min_{μ, z}~ F(μ, z) + R(z) + H(K_z z) + Q(μ), |
|
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 | /// $$ |
|
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
|
60 | /// where |
|
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
|
61 | /// * The data term $F$ is given in `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
|
62 | /// * the measure (Radon or positivity-constrained Radon) regulariser in $Q$ is given in `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
|
63 | /// * the functions $R$ and $H$ are given in `fnR` and `fnH`, and |
|
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
|
64 | /// * the operator $K_z$ in `opKz`. |
|
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
|
65 | /// |
|
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
|
66 | /// This is dualised to |
|
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
|
67 | /// $$ |
|
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
|
68 | /// \min_{μ, z}\max_y~ F(μ, z) + R(z) + ⟨K_z z, y⟩ + Q(μ) - H^*(y). |
|
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
|
69 | /// $$ |
|
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
|
70 | /// |
|
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 | /// The algorithm is controlled by: |
|
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 | /// * the proximal penalty in `prox_penalty`. |
|
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 | /// * the initial iterates in `z`, `y` |
|
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 | /// * The configuration in `config`. |
|
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 | /// * The `iterator` that controls stopping and reporting. |
|
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
|
76 | /// Moreover, plotting is performed by `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
|
77 | /// |
|
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
|
78 | /// The step lengths need to satisfy |
|
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
|
79 | /// $$ |
|
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
|
80 | /// τσ_dM(1-σ_p L_z)/(1 - τ L) + [σ_p L_z + σ_pσ_d‖K_z‖^2] < 1 |
|
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
|
81 | /// $$ ^^^^^^^^^^^^^^^^^^^^^^^^^ |
|
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 | /// with $1 > σ_p L_z$ and $1 > τ L$. |
|
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
|
83 | /// Since we are given “scalings” $τ_0$, $σ_{p,0}$, and $σ_{d,0}$ in `config`, we take |
|
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
|
84 | /// $σ_d=σ_{d,0}/‖K_z‖$, and $σ_p = σ_{p,0} / (L_z σ_d‖K_z‖)$. This satisfies the |
|
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
|
85 | /// part $[σ_p L_z + σ_pσ_d‖K_z‖^2] < 1$. Then with these cohices, we solve |
|
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
|
86 | /// $$ |
|
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
|
87 | /// τ = τ_0 \frac{1 - σ_{p,0}}{(σ_d M (1-σ_p L_z) + (1 - σ_{p,0} L)}. |
|
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
|
88 | /// $$ |
| 35 | 89 | #[replace_float_literals(F::cast_from(literal))] |
| 89 | 90 | pub fn pointsource_forward_pdps_pair_dom< |
|
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
|
91 | F, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
92 | 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:
39
diff
changeset
|
93 | 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
|
94 | S, |
|
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
|
95 | 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:
39
diff
changeset
|
96 | 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
|
97 | 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
|
98 | Z, |
|
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
|
99 | R, |
|
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
|
100 | Y, |
|
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
|
101 | /*KOpM, */ KOpZ, |
|
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
|
102 | H, |
|
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
|
103 | Plot, |
| 35 | 104 | >( |
|
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
|
105 | 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:
39
diff
changeset
|
106 | 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
|
107 | 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
|
108 | config: &ForwardPDPSConfig<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
|
109 | 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
|
110 | mut plotter: Plot, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
111 | (μ0, mut z, mut y): (Option<DiscreteMeasure<U, F>>, Z, Y), |
| 35 | 112 | //opKμ : KOpM, |
|
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
|
113 | opKz: &KOpZ, |
|
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
|
114 | fnR: &R, |
|
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
|
115 | fnH: &H, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
116 | domain: &mut impl AdmissibleDomain<U>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
117 | ) -> DynResult<MeasureZ<F, Z, U>> |
| 35 | 118 | where |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
119 | U: Space + 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
|
120 | 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
|
121 | I: AlgIteratorFactory<IterInfo<F>>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
122 | Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>, |
|
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
|
123 | //Pair<S, Z>: ClosedMul<F>, // Doesn't really need to be closed, if make this signature more complex… |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
124 | S: ClosedMul<F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
125 | DiscreteMeasure<U, F>: SpikeMerging<F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
126 | Reg: RegTerm<U, F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
127 | P: ProxPenalty<U, S, Reg, 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
|
128 | for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<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:
39
diff
changeset
|
129 | KOpZ: BoundedLinear<Z, L2, L2, F, Codomain = Y> |
|
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
|
130 | + GEMV<F, Z, Y> |
|
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
|
131 | + SimplyAdjointable<Z, Y, Codomain = Y, AdjointCodomain = Z>, |
|
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
|
132 | KOpZ::SimpleAdjoint: GEMV<F, Y, Z>, |
|
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
|
133 | Y: ClosedEuclidean<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
|
134 | for<'b> &'b Y: Instance<Y>, |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
66
diff
changeset
|
135 | Z: ClosedEuclidean<F> + AXPY, |
|
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
|
136 | for<'b> &'b Z: Instance<Z>, |
|
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
|
137 | R: Prox<Z, 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:
39
diff
changeset
|
138 | H: Conjugable<Y, 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:
39
diff
changeset
|
139 | for<'b> H::Conjugate<'b>: Prox<Y>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
140 | Plot: Plotter<P::ReturnMapping, S, DiscreteMeasure<U, F>>, |
| 35 | 141 | { |
| 142 | // Check parameters | |
|
63
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
143 | ensure!( |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
144 | config.τ0 > 0.0 |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
145 | && config.τ0 < 1.0 |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
146 | && config.σp0 > 0.0 |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
147 | && config.σp0 < 1.0 |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
148 | && config.σd0 >= 0.0 |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
149 | && config.σp0 * config.σd0 <= 1.0, |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
150 | "Invalid step length parameters" |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
151 | ); |
| 35 | 152 | |
| 153 | // 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
|
154 | let mut μ = μ0.unwrap_or_else(|| DiscreteMeasure::new()); |
| 35 | 155 | |
| 156 | // Set up parameters | |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
157 | let bigM = 0.0; //opKμ.adjoint_product_bound(prox_penalty).unwrap().sqrt(); |
|
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
|
158 | let nKz = opKz.opnorm_bound(L2, L2)?; |
|
66
fe47ad484deb
Allow fitness merge when forward_pdps and sliding_pdps are used as forward-backward with aux variable.
Tuomo Valkonen <tuomov@iki.fi>
parents:
65
diff
changeset
|
159 | let is_fb = nKz == 0.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
|
160 | let idOpZ = IdOp::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
|
161 | let opKz_adj = opKz.adjoint(); |
|
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 | let (l, l_z) = Pair(prox_penalty, &idOpZ).step_length_bound_pair(&f)?; |
| 35 | 163 | // We need to satisfy |
| 164 | // | |
| 165 | // τσ_dM(1-σ_p L_z)/(1 - τ L) + [σ_p L_z + σ_pσ_d‖K_z‖^2] < 1 | |
| 166 | // ^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 167 | // with 1 > σ_p L_z and 1 > τ L. | |
| 168 | // | |
| 169 | // To do so, we first solve σ_p and σ_d from standard PDPS step length condition | |
| 170 | // ^^^^^ < 1. then we solve τ from the rest. | |
|
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 | // If opKZ is the zero operator, then we set σ_d = 0 for τ to be calculated correctly below. |
|
66
fe47ad484deb
Allow fitness merge when forward_pdps and sliding_pdps are used as forward-backward with aux variable.
Tuomo Valkonen <tuomov@iki.fi>
parents:
65
diff
changeset
|
172 | let σ_d = if is_fb { 0.0 } else { config.σd0 / nKz }; |
| 35 | 173 | let σ_p = config.σp0 / (l_z + config.σd0 * nKz); |
| 174 | // Observe that = 1 - ^^^^^^^^^^^^^^^^^^^^^ = 1 - σ_{p,0} | |
| 175 | // We get the condition τσ_d M (1-σ_p L_z) < (1-σ_{p,0})*(1-τ L) | |
| 176 | // ⟺ τ [ σ_d M (1-σ_p L_z) + (1-σ_{p,0}) L ] < (1-σ_{p,0}) | |
| 177 | let φ = 1.0 - config.σp0; | |
| 178 | let a = 1.0 - σ_p * l_z; | |
|
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
|
179 | let τ = config.τ0 * φ / (σ_d * bigM * a + φ * l); |
| 35 | 180 | // Acceleration is not currently supported |
| 181 | // let γ = dataterm.factor_of_strong_convexity(); | |
| 182 | let ω = 1.0; | |
| 183 | ||
| 184 | // We multiply tolerance by τ for FB since our subproblems depending on tolerances are scaled | |
| 185 | // by τ compared to the conditional gradient approach. | |
| 186 | let tolerance = config.insertion.tolerance * τ * reg.tolerance_scaling(); | |
| 187 | let mut ε = tolerance.initial(); | |
| 188 | ||
| 189 | let starH = fnH.conjugate(); | |
| 190 | ||
| 191 | // Statistics | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
192 | let full_stats = |μ: &DiscreteMeasure<U, F>, z: &Z, ε, 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:
39
diff
changeset
|
193 | value: f.apply(Pair(μ, z)) |
|
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
|
194 | + fnR.apply(z) |
|
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 | + 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
|
196 | + fnH.apply(/* opKμ.apply(μ) + */ opKz.apply(z)), |
|
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
|
197 | n_spikes: μ.len(), |
| 35 | 198 | ε, |
| 199 | // postprocessing: config.insertion.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
|
200 | ..stats |
| 35 | 201 | }; |
| 202 | let mut stats = IterInfo::new(); | |
| 203 | ||
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
204 | let zy_step = |mut z, mut y, mut z_tmp| { |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
205 | // Do z variable primal update |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
206 | opKz_adj.apply_add(&mut z_tmp, &y); |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
207 | z_tmp.axpy(1.0, &z, -σ_p); |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
208 | let z_new = fnR.prox(σ_p, z_tmp); |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
209 | //let z_new = fnR.prox(σ_p, z_tmp * (-σ_p) + &z); |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
210 | // Do dual update |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
211 | z.axpy(1.0 + ω, &z_new, -ω); |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
212 | //z = (z - &z_new) * (-ω) + &z_new; |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
213 | opKz.gemv(&mut y, σ_d, z, 1.0); |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
214 | let y = starH.prox(σ_d, y); |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
215 | (z_new, y) |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
216 | }; |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
217 | |
| 35 | 218 | // 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:
39
diff
changeset
|
219 | for state in iterator.iter_init(|| full_stats(&μ, &z, ε, stats.clone())) { |
| 35 | 220 | // Calculate initial transport |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
221 | let Pair(v, z_tmp) = f.differential(Pair(&μ, &z)); |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
66
diff
changeset
|
222 | let mut τv = v * τ; |
| 35 | 223 | let μ_base = μ.clone(); |
|
91
47d495348e38
Do not prune new insertions on first round
Tuomo Valkonen <tuomov@iki.fi>
parents:
89
diff
changeset
|
224 | let μ_base_len = μ_base.len(); |
| 35 | 225 | |
| 226 | // Construct μ^{k+1} by solving finite-dimensional subproblems and insert new spikes. | |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
227 | prox_penalty.insert_and_reweigh( |
|
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
|
228 | &mut μ, |
|
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 | &mut τ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:
39
diff
changeset
|
230 | τ, |
|
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
|
231 | ε, |
|
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
|
232 | &config.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:
39
diff
changeset
|
233 | ®, |
|
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
|
234 | &state, |
|
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
|
235 | &mut 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
|
236 | )?; |
| 35 | 237 | |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
238 | (z, y) = zy_step(z, y, z_tmp); |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
239 | |
|
63
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
240 | stats.inserted += μ.len() - μ_base.len(); |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
241 | |
|
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
242 | // Merge spikes. |
|
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
243 | // This crucially expects the merge routine to be stable with respect to spike locations, |
|
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
244 | // and not to performing any pruning. That is be to done below simultaneously for γ. |
| 89 | 245 | let did_merge = config.insertion.if_merge_now(&state, |ins| { |
|
66
fe47ad484deb
Allow fitness merge when forward_pdps and sliding_pdps are used as forward-backward with aux variable.
Tuomo Valkonen <tuomov@iki.fi>
parents:
65
diff
changeset
|
246 | stats.merged += prox_penalty.merge_spikes( |
|
fe47ad484deb
Allow fitness merge when forward_pdps and sliding_pdps are used as forward-backward with aux variable.
Tuomo Valkonen <tuomov@iki.fi>
parents:
65
diff
changeset
|
247 | &mut μ, |
|
fe47ad484deb
Allow fitness merge when forward_pdps and sliding_pdps are used as forward-backward with aux variable.
Tuomo Valkonen <tuomov@iki.fi>
parents:
65
diff
changeset
|
248 | &mut τv, |
|
fe47ad484deb
Allow fitness merge when forward_pdps and sliding_pdps are used as forward-backward with aux variable.
Tuomo Valkonen <tuomov@iki.fi>
parents:
65
diff
changeset
|
249 | &μ_base, |
|
fe47ad484deb
Allow fitness merge when forward_pdps and sliding_pdps are used as forward-backward with aux variable.
Tuomo Valkonen <tuomov@iki.fi>
parents:
65
diff
changeset
|
250 | τ, |
|
fe47ad484deb
Allow fitness merge when forward_pdps and sliding_pdps are used as forward-backward with aux variable.
Tuomo Valkonen <tuomov@iki.fi>
parents:
65
diff
changeset
|
251 | ε, |
|
fe47ad484deb
Allow fitness merge when forward_pdps and sliding_pdps are used as forward-backward with aux variable.
Tuomo Valkonen <tuomov@iki.fi>
parents:
65
diff
changeset
|
252 | ins, |
|
fe47ad484deb
Allow fitness merge when forward_pdps and sliding_pdps are used as forward-backward with aux variable.
Tuomo Valkonen <tuomov@iki.fi>
parents:
65
diff
changeset
|
253 | ®, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
254 | Some(|μ̃: &DiscreteMeasure<U, F>| f.apply(Pair(μ̃, &z)) + reg.apply(μ̃)), |
|
66
fe47ad484deb
Allow fitness merge when forward_pdps and sliding_pdps are used as forward-backward with aux variable.
Tuomo Valkonen <tuomov@iki.fi>
parents:
65
diff
changeset
|
255 | ); |
|
91
47d495348e38
Do not prune new insertions on first round
Tuomo Valkonen <tuomov@iki.fi>
parents:
89
diff
changeset
|
256 | // 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
|
257 | stats.pruned += prune_with_stats(&mut μ, μ_base_len); |
| 35 | 258 | |
| 89 | 259 | if config.insertion.random_insertions { |
| 260 | if let Some(x) = domain.random_point() { | |
| 261 | μ += DeltaMeasure { x, α: 0.0 }; | |
| 262 | stats.inserted += 1; | |
| 263 | } | |
| 264 | } | |
| 35 | 265 | |
| 89 | 266 | for _ in 0..config.insertion.extra_weight_optimisation_steps { |
| 267 | // Do extra weight optimisation step heuristic | |
| 268 | let Pair(v, mut _z_tmp) = f.differential(Pair(&μ, &z)); | |
| 269 | τv = v * τ; | |
| 270 | prox_penalty.reweigh( | |
| 271 | &mut μ, | |
| 272 | &mut τv, | |
| 273 | τ, | |
| 274 | ε, | |
| 275 | &config.insertion, | |
| 276 | ®, | |
| 277 | &state, | |
| 278 | &mut stats, | |
| 279 | )?; | |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
280 | |
| 89 | 281 | // opKz_adj.apply_add(&mut z_tmp, &y); |
| 282 | // z_tmp.axpy(1.0, &z, -σ_p); | |
| 283 | // let z_new = fnR.prox(σ_p, z_tmp); | |
| 284 | // z.axpy(1.0 + ω, &z_new, -ω); | |
| 285 | // //z = (z - &z_new) * (-ω) + &z_new; | |
| 286 | // opKz.gemv(&mut y, σ_d, z, 1.0); | |
| 287 | // y = starH.prox(σ_d, y); | |
| 288 | // z = z_new; | |
| 289 | } | |
| 290 | Ok(()) | |
| 291 | })?; | |
| 292 | ||
| 293 | if did_merge.is_none() { | |
|
91
47d495348e38
Do not prune new insertions on first round
Tuomo Valkonen <tuomov@iki.fi>
parents:
89
diff
changeset
|
294 | // 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
|
295 | stats.pruned += prune_with_stats(&mut μ, μ_base_len); |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
296 | } |
| 35 | 297 | |
| 298 | // Update step length parameters | |
| 299 | // let ω = pdpsconfig.acceleration.accelerate(&mut τ, &mut σ, γ); | |
| 300 | ||
| 301 | // Give statistics if requested | |
| 302 | let iter = state.iteration(); | |
| 303 | stats.this_iters += 1; | |
| 304 | ||
| 305 | state.if_verbose(|| { | |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
306 | 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:
39
diff
changeset
|
307 | full_stats(&μ, &z, ε, std::mem::replace(&mut stats, IterInfo::new())) |
| 35 | 308 | }); |
| 309 | ||
| 310 | // Update main tolerance for next iteration | |
| 311 | ε = tolerance.update(ε, iter); | |
| 312 | } | |
| 313 | ||
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
314 | let fit = |μ̃: &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:
39
diff
changeset
|
315 | f.apply(Pair(μ̃, &z)) /*+ fnR.apply(z) + reg.apply(μ)*/ |
| 35 | 316 | + fnH.apply(/* opKμ.apply(&μ̃) + */ opKz.apply(&z)) |
| 84 | 317 | + reg.apply(μ̃) |
| 35 | 318 | }; |
| 319 | ||
|
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
320 | μ.merge_spikes_fitness(config.insertion.final_merging_method(), fit, |&v| v); |
| 35 | 321 | μ.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:
39
diff
changeset
|
322 | Ok(Pair(μ, z)) |
| 35 | 323 | } |
|
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
|
324 | |
| 89 | 325 | #[deprecated] |
| 326 | pub fn pointsource_forward_pdps_pair< | |
| 327 | F, | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
328 | U, |
| 89 | 329 | I, |
| 330 | S, | |
| 331 | Dat, | |
| 332 | Reg, | |
| 333 | P, | |
| 334 | Z, | |
| 335 | R, | |
| 336 | Y, | |
| 337 | /*KOpM, */ KOpZ, | |
| 338 | H, | |
| 339 | Plot, | |
| 340 | >( | |
| 341 | f: &Dat, | |
| 342 | reg: &Reg, | |
| 343 | prox_penalty: &P, | |
| 344 | config: &ForwardPDPSConfig<F>, | |
| 345 | iterator: I, | |
| 346 | plotter: Plot, | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
347 | init: (Option<DiscreteMeasure<U, F>>, Z, Y), |
| 89 | 348 | //opKμ : KOpM, |
| 349 | opKz: &KOpZ, | |
| 350 | fnR: &R, | |
| 351 | fnH: &H, | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
352 | ) -> DynResult<MeasureZ<F, Z, U>> |
| 89 | 353 | where |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
354 | U: Space + Clone, |
| 89 | 355 | F: Float + ToNalgebraRealField, |
| 356 | I: AlgIteratorFactory<IterInfo<F>>, | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
357 | Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>, |
| 89 | 358 | //Pair<S, Z>: ClosedMul<F>, // Doesn't really need to be closed, if make this signature more complex… |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
359 | S: ClosedMul<F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
360 | DiscreteMeasure<U, F>: SpikeMerging<F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
361 | Reg: RegTerm<U, F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
362 | P: ProxPenalty<U, S, Reg, F>, |
| 89 | 363 | for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>, |
| 364 | KOpZ: BoundedLinear<Z, L2, L2, F, Codomain = Y> | |
| 365 | + GEMV<F, Z, Y> | |
| 366 | + SimplyAdjointable<Z, Y, Codomain = Y, AdjointCodomain = Z>, | |
| 367 | KOpZ::SimpleAdjoint: GEMV<F, Y, Z>, | |
| 368 | Y: ClosedEuclidean<F>, | |
| 369 | for<'b> &'b Y: Instance<Y>, | |
| 370 | Z: ClosedEuclidean<F> + AXPY, | |
| 371 | for<'b> &'b Z: Instance<Z>, | |
| 372 | R: Prox<Z, Codomain = F>, | |
| 373 | H: Conjugable<Y, F, Codomain = F>, | |
| 374 | for<'b> H::Conjugate<'b>: Prox<Y>, | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
375 | Plot: Plotter<P::ReturnMapping, S, DiscreteMeasure<U, F>>, |
| 89 | 376 | { |
| 377 | pointsource_forward_pdps_pair_dom( | |
| 378 | f, | |
| 379 | reg, | |
| 380 | prox_penalty, | |
| 381 | config, | |
| 382 | iterator, | |
| 383 | plotter, | |
| 384 | init, | |
| 385 | opKz, | |
| 386 | fnR, | |
| 387 | fnH, | |
| 388 | &mut FullSpace, | |
| 389 | ) | |
| 390 | } | |
| 391 | ||
|
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
|
392 | /// Iteratively solve the pointsource localisation with an additional variable |
|
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
|
393 | /// using forward-backward splitting. |
|
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
|
394 | /// |
|
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
|
395 | /// The implementation uses [`pointsource_forward_pdps_pair`] with appropriate dummy |
|
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
|
396 | /// variables, operators, and functions. |
|
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
|
397 | #[replace_float_literals(F::cast_from(literal))] |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
398 | pub fn pointsource_fb_pair_dom<F, U, I, S, Dat, Reg, P, Z, R, 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:
39
diff
changeset
|
399 | 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:
39
diff
changeset
|
400 | 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
|
401 | 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
|
402 | config: &FBConfig<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
|
403 | 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
|
404 | plotter: Plot, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
405 | (μ0, z): (Option<DiscreteMeasure<U, F>>, Z), |
|
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
|
406 | //opKμ : KOpM, |
|
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
|
407 | fnR: &R, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
408 | domain: &mut impl AdmissibleDomain<U>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
409 | ) -> DynResult<MeasureZ<F, Z, 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:
39
diff
changeset
|
410 | where |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
411 | U: Space + 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
|
412 | 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
|
413 | I: AlgIteratorFactory<IterInfo<F>>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
414 | Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
415 | S: ClosedMul<F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
416 | DiscreteMeasure<U, F>: SpikeMerging<F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
417 | Reg: RegTerm<U, F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
418 | P: ProxPenalty<U, S, Reg, 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
|
419 | for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<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:
39
diff
changeset
|
420 | Z: ClosedEuclidean<F> + AXPY<Field = F> + Clone, |
|
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
|
421 | for<'b> &'b Z: Instance<Z>, |
|
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
|
422 | R: Prox<Z, Codomain = F>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
423 | Plot: Plotter<P::ReturnMapping, S, 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:
39
diff
changeset
|
424 | // We should not need to explicitly require this: |
|
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
|
425 | for<'b> &'b Loc<0, F>: Instance<Loc<0, 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
|
426 | { |
|
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
|
427 | let opKz = ZeroOp::new_dualisable(Loc([]), z.dual_origin()); |
|
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
|
428 | let fnH = Zero::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
|
429 | // Convert config. We don't implement From (that could be done with the o2o crate), as σd0 |
|
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
|
430 | // needs to be chosen in a general case; for the problem of this fucntion, anything is valid. |
|
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
|
431 | let &FBConfig { τ0, σp0, insertion } = config; |
|
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
|
432 | let pdps_config = ForwardPDPSConfig { τ0, σp0, insertion, σd0: 0.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
|
433 | |
| 89 | 434 | pointsource_forward_pdps_pair_dom( |
|
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
|
435 | 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
|
436 | 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
|
437 | prox_penalty, |
|
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
|
438 | &pdps_config, |
|
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
|
439 | iterator, |
|
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
|
440 | 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
|
441 | (μ0, z, Loc([])), |
|
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
|
442 | &opKz, |
|
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
|
443 | fnR, |
|
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
|
444 | &fnH, |
| 89 | 445 | domain, |
|
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
|
446 | ) |
|
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
|
447 | } |
| 89 | 448 | |
| 449 | #[deprecated] | |
| 450 | #[replace_float_literals(F::cast_from(literal))] | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
451 | pub fn pointsource_fb_pair<F, U, I, S, Dat, Reg, P, Z, R, Plot>( |
| 89 | 452 | f: &Dat, |
| 453 | reg: &Reg, | |
| 454 | prox_penalty: &P, | |
| 455 | config: &FBConfig<F>, | |
| 456 | iterator: I, | |
| 457 | plotter: Plot, | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
458 | init: (Option<DiscreteMeasure<U, F>>, Z), |
| 89 | 459 | //opKμ : KOpM, |
| 460 | fnR: &R, | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
461 | ) -> DynResult<MeasureZ<F, Z, U>> |
| 89 | 462 | where |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
463 | U: Space + Clone, |
| 89 | 464 | F: Float + ToNalgebraRealField, |
| 465 | I: AlgIteratorFactory<IterInfo<F>>, | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
466 | Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
467 | S: DifferentiableMapping<U, Codomain = F> + ClosedMul<F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
468 | DiscreteMeasure<U, F>: SpikeMerging<F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
469 | Reg: RegTerm<U, F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
470 | P: ProxPenalty<U, S, Reg, F>, |
| 89 | 471 | for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>, |
| 472 | Z: ClosedEuclidean<F> + AXPY<Field = F> + Clone, | |
| 473 | for<'b> &'b Z: Instance<Z>, | |
| 474 | R: Prox<Z, Codomain = F>, | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
475 | Plot: Plotter<P::ReturnMapping, S, DiscreteMeasure<U, F>>, |
| 89 | 476 | // We should not need to explicitly require this: |
| 477 | for<'b> &'b Loc<0, F>: Instance<Loc<0, F>>, | |
| 478 | { | |
| 479 | pointsource_fb_pair_dom( | |
| 480 | f, | |
| 481 | reg, | |
| 482 | prox_penalty, | |
| 483 | config, | |
| 484 | iterator, | |
| 485 | plotter, | |
| 486 | init, | |
| 487 | fnR, | |
| 488 | &mut FullSpace, | |
| 489 | ) | |
| 490 | } |