src/forward_pdps.rs

Tue, 04 Aug 2026 14:12:18 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Tue, 04 Aug 2026 14:12:18 -0500
changeset 89
8d1c959432c8
parent 84
edb5de5d5bd6
child 91
47d495348e38
permissions
-rw-r--r--

Add AdmissibleDomain

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

mercurial