src/forward_pdps.rs

Fri, 16 Jan 2026 19:39:22 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Fri, 16 Jan 2026 19:39:22 -0500
branch
dev
changeset 62
32328a74c790
parent 61
4f468d35fa29
permissions
-rw-r--r--

Lipschitz estimation attempt (incomplete, not implemented for sliding. Doesn't work anyway for basic FB either.)

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
62
32328a74c790 Lipschitz estimation attempt (incomplete, not implemented for sliding. Doesn't work anyway for basic FB either.)
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
179 dbg!(τ, σ_p);
32328a74c790 Lipschitz estimation attempt (incomplete, not implemented for sliding. Doesn't work anyway for basic FB either.)
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
180
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
181 // 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
182 // by τ compared to the conditional gradient approach.
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
183 let tolerance = config.insertion.tolerance * τ * reg.tolerance_scaling();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
184 let mut ε = tolerance.initial();
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 let starH = fnH.conjugate();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
187
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
188 // 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
189 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
190 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
191 + 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
192 + 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
193 + 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
194 n_spikes: μ.len(),
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
195 ε,
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
196 // 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
197 ..stats
35
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 let mut stats = IterInfo::new();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
200
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
201 // 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
202 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
203 // 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
204 let Pair(mut τv, τz) = f.differential(Pair(&μ, &z));
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
205 let μ_base = μ.clone();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
206
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
207 // 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
208 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
209 &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
210 &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
211 &μ_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
212 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
213 τ,
4f468d35fa29 General forward operators, separation 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 ε,
4f468d35fa29 General forward operators, separation 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 &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
216 &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
217 &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
218 &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
219 )?;
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
220
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
221 // Merge spikes.
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
222 // 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
223 // 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
224 // Merge spikes.
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
225 // 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
226 // 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
227 let ins = &config.insertion;
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
228 if ins.merge_now(&state) {
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
229 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
230 &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
231 &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
232 //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
233 );
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
234 }
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
235
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
236 // Prune spikes with zero weight.
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
237 stats.pruned += prune_with_stats(&mut μ);
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
238
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
239 // Do z variable primal update
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
240 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
241 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
242 z_new = fnR.prox(σ_p, z_new + &z);
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
243 // Do dual update
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
244 // 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
245 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
246 // 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
247 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
248 y = starH.prox(σ_d, y);
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
249 z = z_new;
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
250
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
251 // Update step length parameters
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
252 // let ω = pdpsconfig.acceleration.accelerate(&mut τ, &mut σ, γ);
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
253
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
254 // Give statistics if requested
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
255 let iter = state.iteration();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
256 stats.this_iters += 1;
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
257
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
258 state.if_verbose(|| {
37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
259 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
260 full_stats(&μ, &z, ε, std::mem::replace(&mut stats, IterInfo::new()))
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
261 });
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
262
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
263 // Update main tolerance for next iteration
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
264 ε = tolerance.update(ε, iter);
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
265 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
266
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
267 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
268 f.apply(Pair(μ̃, &z)) /*+ fnR.apply(z) + reg.apply(μ)*/
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
269 + fnH.apply(/* opKμ.apply(&μ̃) + */ opKz.apply(&z))
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
270 };
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
271
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
272 μ.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
273 μ.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
274 Ok(Pair(μ, z))
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
275 }
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
276
4f468d35fa29 General forward operators, separation 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 /// 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
278 /// 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
279 ///
4f468d35fa29 General forward operators, separation 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 /// 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
281 /// 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
282 #[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
283 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
284 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
285 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
286 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
287 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
288 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
289 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
290 (μ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
291 //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
292 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
293 ) -> 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
294 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
295 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
296 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
297 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
298 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
299 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
300 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
301 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
302 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
303 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
304 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
305 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
306 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
307 // 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
308 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
309 {
4f468d35fa29 General forward operators, separation 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 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
311 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
312 // 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
313 // needs to be chosen in a general case; for the problem of this fucntion, anything is valid.
62
32328a74c790 Lipschitz estimation attempt (incomplete, not implemented for sliding. Doesn't work anyway for basic FB either.)
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
314 let &FBConfig { τ0, σp0, insertion, .. } = config;
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 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
316
4f468d35fa29 General forward operators, separation 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 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
318 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
319 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
320 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
321 &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
322 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
323 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
324 (μ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
325 &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
326 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
327 &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
328 )
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
329 }

mercurial