src/forward_pdps.rs

Thu, 26 Feb 2026 11:38:43 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Thu, 26 Feb 2026 11:38:43 -0500
branch
dev
changeset 61
4f468d35fa29
parent 39
6316d68b58af
child 62
32328a74c790
child 63
7a8a55fd41c0
permissions
-rw-r--r--

General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.

35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1 /*!
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
2 Solver for the point source localisation problem using a
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
3 primal-dual proximal splitting with a forward step.
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
4 */
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
5
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
6 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
7 use crate::measures::merging::SpikeMerging;
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
8 use crate::measures::{DiscreteMeasure, RNDM};
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
9 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
10 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
11 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
12 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
13 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
14 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
15 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
16 use alg_tools::euclidean::ClosedEuclidean;
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
17 use alg_tools::iterate::AlgIteratorFactory;
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
18 use alg_tools::linops::{BoundedLinear, IdOp, SimplyAdjointable, ZeroOp, AXPY, GEMV};
4f468d35fa29 General 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
19 use alg_tools::mapping::{DifferentiableMapping, DifferentiableRealMapping, Instance};
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
20 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
21 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
22 use anyhow::ensure;
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
23 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
24 use serde::{Deserialize, Serialize};
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
25
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
26 /// Settings for [`pointsource_forward_pdps_pair`].
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
27 #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)]
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
28 #[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
29 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
30 /// 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
31 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
32 /// 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
33 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
34 /// 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
35 ///
4f468d35fa29 General 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 /// 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
37 pub σd0: F,
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
38 /// 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
39 pub insertion: InsertionConfig<F>,
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
40 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
41
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
42 #[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
43 impl<F: Float> Default for ForwardPDPSConfig<F> {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
44 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
45 ForwardPDPSConfig { τ0: 0.99, σd0: 0.05, σp0: 0.99, insertion: Default::default() }
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
46 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
47 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
48
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
49 type MeasureZ<F, Z, const N: usize> = Pair<RNDM<N, F>, Z>;
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
50
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
51 /// Iteratively solve the pointsource localisation with an additional variable
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
52 /// 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
53 ///
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
54 /// 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
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 /// \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
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 /// 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
59 /// * 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
60 /// * 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
61 /// * 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
62 /// * 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
63 ///
4f468d35fa29 General 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 /// 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
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 /// \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
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 ///
4f468d35fa29 General 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 /// 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
70 /// * 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
71 /// * 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
72 /// * 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
73 /// * 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
74 /// 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
75 ///
4f468d35fa29 General 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 /// 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
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 /// τσ_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
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 /// 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
81 /// 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
82 /// $σ_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
83 /// 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
84 /// $$
4f468d35fa29 General 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 /// τ = τ_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
86 /// $$
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
87 #[replace_float_literals(F::cast_from(literal))]
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
88 pub fn pointsource_forward_pdps_pair<
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
89 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
90 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
91 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
92 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
93 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
94 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
95 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
96 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
97 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
98 /*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
99 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
100 Plot,
4f468d35fa29 General 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 const N: usize,
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
102 >(
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
103 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
104 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
105 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
106 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
107 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
108 mut plotter: Plot,
4f468d35fa29 General 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 (μ0, mut z, mut y): (Option<RNDM<N, F>>, Z, Y),
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
110 //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
111 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
112 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
113 fnH: &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
114 ) -> DynResult<MeasureZ<F, Z, N>>
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
115 where
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
116 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
117 I: AlgIteratorFactory<IterInfo<F>>,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
118 Dat: DifferentiableMapping<MeasureZ<F, Z, N>, Codomain = F, DerivativeDomain = Pair<S, 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
119 //Pair<S, Z>: ClosedMul<F>, // Doesn't really need to be closed, if make this signature more complex…
4f468d35fa29 General 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 S: DifferentiableRealMapping<N, F> + ClosedMul<F>,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
121 RNDM<N, F>: SpikeMerging<F>,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
122 Reg: RegTerm<Loc<N, F>, F>,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
123 P: ProxPenalty<Loc<N, F>, S, Reg, 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
124 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
125 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
126 + 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
127 + 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
128 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
129 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
130 for<'b> &'b Y: Instance<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 Z: 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
132 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
133 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
134 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
135 for<'b> H::Conjugate<'b>: Prox<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
136 Plot: Plotter<P::ReturnMapping, S, RNDM<N, F>>,
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
137 {
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
138 // Check 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
139 // ensure!(
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
140 // config.τ0 > 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
141 // && config.τ0 < 1.0
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
142 // && config.σp0 > 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
143 // && config.σp0 < 1.0
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
144 // && config.σ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
145 // && config.σp0 * config.σd0 <= 1.0,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
146 // "Invalid step length parameters"
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
147 // );
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
148
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
149 // 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
150 let mut μ = μ0.unwrap_or_else(|| DiscreteMeasure::new());
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
151
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
152 // Set up parameters
37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
153 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
154 let nKz = opKz.opnorm_bound(L2, 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
155 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
156 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
157 let (l, l_z) = Pair(prox_penalty, &idOpZ).step_length_bound_pair(&f)?;
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
158 // We need to satisfy
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
159 //
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
160 // τσ_dM(1-σ_p L_z)/(1 - τ L) + [σ_p L_z + σ_pσ_d‖K_z‖^2] < 1
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
161 // ^^^^^^^^^^^^^^^^^^^^^^^^^
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
162 // with 1 > σ_p L_z and 1 > τ L.
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
163 //
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
164 // To do so, we first solve σ_p and σ_d from standard PDPS step length condition
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
165 // ^^^^^ < 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
166 // If opKZ is the zero operator, then we set σ_d = 0 for τ to be calculated correctly below.
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
167 let σ_d = if nKz == 0.0 { 0.0 } else { config.σd0 / nKz };
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
168 let σ_p = config.σp0 / (l_z + config.σd0 * nKz);
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
169 // Observe that = 1 - ^^^^^^^^^^^^^^^^^^^^^ = 1 - σ_{p,0}
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
170 // We get the condition τσ_d M (1-σ_p L_z) < (1-σ_{p,0})*(1-τ L)
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
171 // ⟺ τ [ σ_d M (1-σ_p L_z) + (1-σ_{p,0}) L ] < (1-σ_{p,0})
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
172 let φ = 1.0 - config.σp0;
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
173 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
174 let τ = config.τ0 * φ / (σ_d * bigM * a + φ * l);
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
175 // Acceleration is not currently supported
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
176 // let γ = dataterm.factor_of_strong_convexity();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
177 let ω = 1.0;
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
178
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
179 // We multiply tolerance by τ for FB since our subproblems depending on tolerances are scaled
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
180 // by τ compared to the conditional gradient approach.
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
181 let tolerance = config.insertion.tolerance * τ * reg.tolerance_scaling();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
182 let mut ε = tolerance.initial();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
183
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
184 let starH = fnH.conjugate();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
185
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
186 // Statistics
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
187 let full_stats = |μ: &RNDM<N, F>, z: &Z, ε, stats| IterInfo {
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
188 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
189 + 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
190 + 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
191 + 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
192 n_spikes: μ.len(),
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
193 ε,
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
194 // 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
195 ..stats
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
196 };
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
197 let mut stats = IterInfo::new();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
198
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
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: 39
diff changeset
200 for state in iterator.iter_init(|| full_stats(&μ, &z, ε, stats.clone())) {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
201 // Calculate initial transport
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
202 let Pair(mut τv, τz) = f.differential(Pair(&μ, &z));
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
203 let μ_base = μ.clone();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
204
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
205 // Construct μ^{k+1} by solving finite-dimensional subproblems and insert new spikes.
37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
206 let (maybe_d, _within_tolerances) = 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
207 &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
208 &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
209 &μ_base,
4f468d35fa29 General 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
210 None,
4f468d35fa29 General 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
211 τ,
4f468d35fa29 General 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
212 ε,
4f468d35fa29 General 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
213 &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
214 &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
215 &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
216 &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
217 )?;
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
218
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
219 // Merge spikes.
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
220 // 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
221 // and not to performing any pruning. That is be to done below simultaneously for γ.
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
222 // Merge spikes.
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
223 // 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
224 // and not to performing any pruning. That is be to done below simultaneously for γ.
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
225 let ins = &config.insertion;
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
226 if ins.merge_now(&state) {
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
227 stats.merged += prox_penalty.merge_spikes_no_fitness(
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 μ, &mut τv, &μ_base, None, τ, ε, ins,
4f468d35fa29 General 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 &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
230 //Some(|μ̃ : &RNDM<N, F>| calculate_residual(Pair(μ̃, &z), opA, b).norm2_squared_div2()),
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
231 );
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
232 }
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
233
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
234 // Prune spikes with zero weight.
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
235 stats.pruned += prune_with_stats(&mut μ);
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
236
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
237 // Do z variable primal update
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
238 let mut z_new = τ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
239 opKz_adj.gemv(&mut z_new, -σ_p, &y, -σ_p / τ);
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
240 z_new = fnR.prox(σ_p, z_new + &z);
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
241 // Do dual update
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
242 // opKμ.gemv(&mut y, σ_d*(1.0 + ω), &μ, 1.0); // y = y + σ_d K[(1+ω)(μ,z)^{k+1}]
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
243 opKz.gemv(&mut y, σ_d * (1.0 + ω), &z_new, 1.0);
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
244 // opKμ.gemv(&mut y, -σ_d*ω, μ_base, 1.0);// y = y + σ_d K[(1+ω)(μ,z)^{k+1} - ω (μ,z)^k]-b
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
245 opKz.gemv(&mut y, -σ_d * ω, z, 1.0); // y = y + σ_d K[(1+ω)(μ,z)^{k+1} - ω (μ,z)^k]-b
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
246 y = starH.prox(σ_d, y);
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
247 z = z_new;
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
248
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
249 // Update step length parameters
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
250 // let ω = pdpsconfig.acceleration.accelerate(&mut τ, &mut σ, γ);
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
251
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
252 // Give statistics if requested
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
253 let iter = state.iteration();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
254 stats.this_iters += 1;
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
255
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
256 state.if_verbose(|| {
37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
257 plotter.plot_spikes(iter, maybe_d.as_ref(), Some(&τv), &μ);
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
258 full_stats(&μ, &z, ε, std::mem::replace(&mut stats, IterInfo::new()))
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
259 });
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
260
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
261 // Update main tolerance for next iteration
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
262 ε = tolerance.update(ε, iter);
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
263 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
264
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
265 let fit = |μ̃: &RNDM<N, F>| {
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
266 f.apply(Pair(μ̃, &z)) /*+ fnR.apply(z) + reg.apply(μ)*/
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
267 + fnH.apply(/* opKμ.apply(&μ̃) + */ opKz.apply(&z))
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
268 };
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
269
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
270 μ.merge_spikes_fitness(config.insertion.final_merging_method(), fit, |&v| v);
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
271 μ.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
272 Ok(Pair(μ, z))
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
273 }
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
274
4f468d35fa29 General 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
275 /// 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
276 /// 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
277 ///
4f468d35fa29 General 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
278 /// 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
279 /// 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
280 #[replace_float_literals(F::cast_from(literal))]
4f468d35fa29 General 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
281 pub fn pointsource_fb_pair<F, I, S, Dat, Reg, P, Z, R, Plot, const N: usize>(
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
282 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
283 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
284 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
285 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
286 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
287 plotter: Plot,
4f468d35fa29 General 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
288 (μ0, z): (Option<RNDM<N, F>>, 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
289 //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
290 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
291 ) -> DynResult<MeasureZ<F, Z, N>>
4f468d35fa29 General 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
292 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
293 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
294 I: AlgIteratorFactory<IterInfo<F>>,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
295 Dat: DifferentiableMapping<MeasureZ<F, Z, N>, Codomain = F, DerivativeDomain = Pair<S, 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
296 S: DifferentiableRealMapping<N, F> + ClosedMul<F>,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
297 RNDM<N, F>: SpikeMerging<F>,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
298 Reg: RegTerm<Loc<N, F>, F>,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
299 P: ProxPenalty<Loc<N, F>, S, Reg, 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
300 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
301 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
302 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
303 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
304 Plot: Plotter<P::ReturnMapping, S, RNDM<N, F>>,
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
305 // 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
306 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
307 {
4f468d35fa29 General 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
308 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
309 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
310 // 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
311 // 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
312 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
313 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
314
4f468d35fa29 General 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 pointsource_forward_pdps_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
316 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
317 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
318 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
319 &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
320 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
321 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
322 (μ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
323 &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
324 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
325 &fnH,
4f468d35fa29 General 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
326 )
4f468d35fa29 General 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
327 }

mercurial