Mon, 05 Oct 2026 20:20:00 -0500
Subdifferential discrepancy calculation scaling fix for sliding PDPS
| 35 | 1 | /*! |
| 2 | Solver for the point source localisation problem using a | |
| 3 | primal-dual proximal splitting with a forward step. | |
| 4 | */ | |
| 5 | ||
| 89 | 6 | use crate::domain::{AdmissibleDomain, FullSpace}; |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
7 | use crate::fb::*; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
8 | use crate::measures::merging::SpikeMerging; |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
9 | use crate::measures::DiscreteMeasure; |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
10 | use crate::plot::Plotter; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
11 | use crate::prox_penalty::{ProxPenalty, StepLengthBoundPair}; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
12 | use crate::regularisation::RegTerm; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
13 | use crate::types::*; |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
14 | use alg_tools::bounds::MinMaxMapping; |
|
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
|
15 | 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
|
16 | 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
|
17 | 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
|
18 | use alg_tools::euclidean::ClosedEuclidean; |
| 35 | 19 | use alg_tools::iterate::AlgIteratorFactory; |
|
96
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
20 | use alg_tools::linops::{ |
|
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
21 | BoundedLinear, IdOp, SimplyAdjointable, Space, StaticEuclideanOriginGenerator, ZeroOp, AXPY, |
|
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
22 | GEMV, |
|
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
23 | }; |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
24 | use alg_tools::mapping::{DifferentiableMapping, Instance}; |
| 35 | 25 | use alg_tools::nalgebra_support::ToNalgebraRealField; |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
26 | use alg_tools::norms::{Norm, L2}; |
|
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
|
27 | use anyhow::ensure; |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
28 | use measures::{DeltaMeasure, Radon}; |
|
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 | 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
|
30 | use serde::{Deserialize, Serialize}; |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
31 | //use std::ops::Mul; |
| 35 | 32 | |
| 33 | /// Settings for [`pointsource_forward_pdps_pair`]. | |
| 34 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] | |
| 35 | #[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
|
36 | 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
|
37 | /// 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
|
38 | 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
|
39 | /// 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
|
40 | 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
|
41 | /// 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
|
42 | /// |
|
4f468d35fa29
General forward operators, separation 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 | /// 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
|
44 | pub σd0: F, |
| 35 | 45 | /// 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
|
46 | pub insertion: InsertionConfig<F>, |
| 35 | 47 | } |
| 48 | ||
| 49 | #[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
|
50 | impl<F: Float> Default for ForwardPDPSConfig<F> { |
| 35 | 51 | 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
|
52 | ForwardPDPSConfig { τ0: 0.99, σd0: 0.05, σp0: 0.99, insertion: Default::default() } |
| 35 | 53 | } |
| 54 | } | |
| 55 | ||
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
56 | type MeasureZ<F, Z, U> = Pair<DiscreteMeasure<U, F>, Z>; |
| 35 | 57 | |
| 58 | /// Iteratively solve the pointsource localisation with an additional variable | |
| 59 | /// 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
|
60 | /// |
|
4f468d35fa29
General forward operators, separation 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 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
|
62 | /// $$ |
|
4f468d35fa29
General forward operators, separation 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 | /// \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
|
64 | /// $$ |
|
4f468d35fa29
General forward operators, separation 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 | /// 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
|
66 | /// * 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
|
67 | /// * 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
|
68 | /// * 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
|
69 | /// * 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
|
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 | /// 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
|
72 | /// $$ |
|
4f468d35fa29
General forward operators, separation 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 | /// \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
|
74 | /// $$ |
|
4f468d35fa29
General forward operators, separation 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 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
|
77 | /// * 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
|
78 | /// * 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
|
79 | /// * 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
|
80 | /// * 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
|
81 | /// 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
|
82 | /// |
|
4f468d35fa29
General forward operators, separation 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 | /// 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
|
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 | /// τσ_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
|
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 | /// 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
|
88 | /// 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
|
89 | /// $σ_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
|
90 | /// 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
|
91 | /// $$ |
|
4f468d35fa29
General forward operators, separation 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 | /// τ = τ_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
|
93 | /// $$ |
| 35 | 94 | #[replace_float_literals(F::cast_from(literal))] |
| 89 | 95 | 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
|
96 | F, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
97 | U, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
98 | 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
|
99 | 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
|
100 | 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
|
101 | 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
|
102 | 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
|
103 | 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
|
104 | 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
|
105 | 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
|
106 | /*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
|
107 | 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
|
108 | Plot, |
| 35 | 109 | >( |
|
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
|
110 | 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
|
111 | 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
|
112 | 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
|
113 | 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
|
114 | 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
|
115 | mut plotter: Plot, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
116 | (μ0, mut z, mut y): (Option<DiscreteMeasure<U, F>>, Z, Y), |
| 35 | 117 | //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
|
118 | 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
|
119 | 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
|
120 | fnH: &H, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
121 | domain: &mut impl AdmissibleDomain<U>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
122 | ) -> DynResult<MeasureZ<F, Z, U>> |
| 35 | 123 | where |
|
96
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
124 | F: Float + ToNalgebraRealField, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
125 | U: Space + Clone, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
126 | I: AlgIteratorFactory<IterInfo<F>>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
127 | Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>, |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
128 | S: ClosedMul<F> + MinMaxMapping<U, F>, |
|
96
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
129 | for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>, |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
130 | DiscreteMeasure<U, F>: SpikeMerging<F> + Norm<Radon, F>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
131 | Reg: RegTerm<U, F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
132 | P: ProxPenalty<U, S, Reg, F>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
133 | KOpZ: BoundedLinear<Z, L2, L2, F, Codomain = Y> |
|
96
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
134 | + GEMV<F, Z> |
|
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
135 | + SimplyAdjointable<Z, Y, AdjointCodomain = Z>, |
|
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
136 | KOpZ::SimpleAdjoint: GEMV<F, Y>, |
|
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
|
137 | 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
|
138 | for<'b> &'b Y: Instance<Y>, |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
139 | Z: ClosedEuclidean<F> + AXPY + Clone, |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
140 | for<'b> &'b Z: Instance<Z>, // compiler overflow + Mul<F, Output = 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
|
141 | 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
|
142 | 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
|
143 | for<'b> H::Conjugate<'b>: Prox<Y>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
144 | Plot: Plotter<P::ReturnMapping, S, DiscreteMeasure<U, F>>, |
| 35 | 145 | { |
| 146 | // Check parameters | |
|
63
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
147 | ensure!( |
| 95 | 148 | config.τ0 > 0.0 && config.σp0 > 0.0, |
| 149 | //&& config.τ0 < 1.0 && config.σp0 < 1.0 | |
|
63
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
150 | "Invalid step length parameters" |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
151 | ); |
| 35 | 152 | |
| 153 | // Initialise iterates | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
154 | let mut μ = μ0.unwrap_or_else(|| DiscreteMeasure::new()); |
| 35 | 155 | |
| 156 | // Set up parameters | |
|
37
c5d8bd1a7728
Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
157 | let bigM = 0.0; //opKμ.adjoint_product_bound(prox_penalty).unwrap().sqrt(); |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
158 | let nKz = opKz.opnorm_bound(L2, L2)?; |
|
66
fe47ad484deb
Allow fitness merge when forward_pdps and sliding_pdps are used as forward-backward with aux variable.
Tuomo Valkonen <tuomov@iki.fi>
parents:
65
diff
changeset
|
159 | let is_fb = nKz == 0.0; |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
160 | let idOpZ = IdOp::new(); |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
161 | let opKz_adj = opKz.adjoint(); |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
162 | let (l, l_z) = Pair(prox_penalty, &idOpZ).step_length_bound_pair(&f)?; |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
163 | let l_z_prime = if l_z == 0.0 { |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
164 | 1.0 |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
165 | } else { |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
166 | ensure!(config.σp0 < 1.0); |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
167 | l_z |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
168 | }; |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
169 | let l_prime = if l == 0.0 { |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
170 | 1.0 |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
171 | } else { |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
172 | ensure!(config.τ0 < 1.0); |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
173 | l |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
174 | }; |
| 95 | 175 | |
| 176 | let (τ, σ_p, σ_d) = if is_fb { | |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
177 | (config.τ0 / l_prime, config.σp0 / l_z_prime, 0.0) |
| 95 | 178 | } else { |
| 179 | ensure!( | |
| 180 | //config.τ0 < 1.0 && | |
| 181 | config.σp0 < 1.0 && config.σd0 > 0.0 && config.σp0 * config.σd0 <= 1.0, | |
| 182 | "Invalid step length parameters" | |
| 183 | ); | |
| 184 | let σ_d = config.σd0 / nKz; | |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
185 | let σ_p = config.σp0 / (l_z_prime + config.σd0 * nKz); |
| 95 | 186 | let φ = 1.0 - config.σp0; |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
187 | let a = 1.0 - σ_p * l_z_prime; |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
188 | let τ = config.τ0 * φ / (σ_d * bigM * a + φ * l_prime); |
| 95 | 189 | (τ, σ_p, σ_d) |
| 190 | }; | |
| 191 | ||
| 35 | 192 | // Acceleration is not currently supported |
| 193 | // let γ = dataterm.factor_of_strong_convexity(); | |
| 194 | let ω = 1.0; | |
| 195 | ||
| 196 | // We multiply tolerance by τ for FB since our subproblems depending on tolerances are scaled | |
| 197 | // by τ compared to the conditional gradient approach. | |
| 198 | let tolerance = config.insertion.tolerance * τ * reg.tolerance_scaling(); | |
| 199 | let mut ε = tolerance.initial(); | |
| 200 | ||
| 201 | let starH = fnH.conjugate(); | |
| 202 | ||
| 203 | // Statistics | |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
204 | let full_stats = |μ: &DiscreteMeasure<U, F>, v: &mut S, z: &Z, dz: &Z, ε, stats| { |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
205 | let value = f.apply(Pair(μ, 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
|
206 | + 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
|
207 | + reg.apply(μ) |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
208 | + fnH.apply(/* opKμ.apply(μ) + */ opKz.apply(z)); |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
209 | let discrepancy = reg.discrepancy(v, τ, ε, μ, &config.insertion); |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
210 | let aux_discrepancy = is_fb.then(|| z.dist2(fnR.prox(σ_p, Z::clone(dz) * (-σ_p) + z))); |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
211 | let joint_discrepancy = aux_discrepancy |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
212 | .map(|d| (discrepancy.powi(2) + τ * (2.0 / σ_p - l_z) * d.powi(2)).sqrt()); |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
213 | IterInfo { |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
214 | value, |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
215 | n_spikes: μ.len(), |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
216 | discrepancy: Some(discrepancy), |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
217 | μ_norm: μ.norm(Radon), |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
218 | // compiler overflow with the necesssary trait bounds: |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
219 | //aux_discrepancy: is_fb.then(|| z.dist2(fnR.prox(σ_p, dz * (-σ_p) + z))), |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
220 | aux_discrepancy, |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
221 | joint_discrepancy, |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
222 | ε, |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
223 | // postprocessing: config.insertion.postprocessing.then(|| μ.clone()), |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
224 | ..stats |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
225 | } |
| 35 | 226 | }; |
| 227 | let mut stats = IterInfo::new(); | |
| 228 | ||
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
229 | let zy_step = |mut z, mut y, mut dz| { |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
230 | // Do z variable primal update |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
231 | opKz_adj.apply_add(&mut dz, &y); |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
232 | dz.axpy(1.0, &z, -σ_p); |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
233 | let z_new = fnR.prox(σ_p, dz); |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
234 | //let z_new = fnR.prox(σ_p, dz * (-σ_p) + &z); |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
235 | // Do dual update |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
236 | z.axpy(1.0 + ω, &z_new, -ω); |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
237 | //z = (z - &z_new) * (-ω) + &z_new; |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
238 | opKz.gemv(&mut y, σ_d, z, 1.0); |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
239 | let y = starH.prox(σ_d, y); |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
240 | (z_new, y) |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
241 | }; |
|
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
242 | |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
243 | // Calculate differential of smooth part |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
244 | let Pair(mut v, mut dz) = f.differential(Pair(&μ, &z)); |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
245 | let mut τv = v * τ; |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
246 | |
| 35 | 247 | // Run the algorithm |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
248 | for state in iterator.iter_init(|| full_stats(&μ, &mut τv, &z, &dz, ε, stats.clone())) { |
| 35 | 249 | // Calculate initial transport |
| 250 | let μ_base = μ.clone(); | |
|
91
47d495348e38
Do not prune new insertions on first round
Tuomo Valkonen <tuomov@iki.fi>
parents:
89
diff
changeset
|
251 | let μ_base_len = μ_base.len(); |
| 35 | 252 | |
| 253 | // 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
|
254 | 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
|
255 | &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
|
256 | &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
|
257 | τ, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
258 | ε, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
259 | &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
|
260 | ®, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
261 | &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
|
262 | &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
|
263 | )?; |
| 35 | 264 | |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
265 | (z, y) = zy_step(z, y, dz); |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
266 | |
|
63
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
267 | stats.inserted += μ.len() - μ_base.len(); |
|
7a8a55fd41c0
Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
268 | |
|
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
269 | // Merge spikes. |
|
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
270 | // 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
|
271 | // and not to performing any pruning. That is be to done below simultaneously for γ. |
| 89 | 272 | 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
|
273 | 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
|
274 | &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
|
275 | &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
|
276 | &μ_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
|
277 | τ, |
|
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
|
278 | ε, |
|
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
|
279 | 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
|
280 | ®, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
281 | Some(|μ̃: &DiscreteMeasure<U, F>| f.apply(Pair(μ̃, &z)) + reg.apply(μ̃)), |
|
66
fe47ad484deb
Allow fitness merge when forward_pdps and sliding_pdps are used as forward-backward with aux variable.
Tuomo Valkonen <tuomov@iki.fi>
parents:
65
diff
changeset
|
282 | ); |
|
91
47d495348e38
Do not prune new insertions on first round
Tuomo Valkonen <tuomov@iki.fi>
parents:
89
diff
changeset
|
283 | // Prune. Do not prune new insertions on first round. |
|
47d495348e38
Do not prune new insertions on first round
Tuomo Valkonen <tuomov@iki.fi>
parents:
89
diff
changeset
|
284 | stats.pruned += prune_with_stats(&mut μ, μ_base_len); |
| 35 | 285 | |
| 89 | 286 | if config.insertion.random_insertions { |
| 287 | if let Some(x) = domain.random_point() { | |
| 288 | μ += DeltaMeasure { x, α: 0.0 }; | |
| 289 | stats.inserted += 1; | |
| 290 | } | |
| 291 | } | |
| 35 | 292 | |
| 89 | 293 | for _ in 0..config.insertion.extra_weight_optimisation_steps { |
| 294 | // Do extra weight optimisation step heuristic | |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
295 | let Pair(v, mut _dz) = f.differential(Pair(&μ, &z)); |
| 89 | 296 | τv = v * τ; |
| 297 | prox_penalty.reweigh( | |
| 298 | &mut μ, | |
| 299 | &mut τv, | |
| 300 | τ, | |
| 301 | ε, | |
| 302 | &config.insertion, | |
| 303 | ®, | |
| 304 | &state, | |
| 305 | &mut stats, | |
| 306 | )?; | |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
307 | |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
308 | // opKz_adj.apply_add(&mut dz, &y); |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
309 | // dz.axpy(1.0, &z, -σ_p); |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
310 | // let z_new = fnR.prox(σ_p, dz); |
| 89 | 311 | // z.axpy(1.0 + ω, &z_new, -ω); |
| 312 | // //z = (z - &z_new) * (-ω) + &z_new; | |
| 313 | // opKz.gemv(&mut y, σ_d, z, 1.0); | |
| 314 | // y = starH.prox(σ_d, y); | |
| 315 | // z = z_new; | |
| 316 | } | |
| 317 | Ok(()) | |
| 318 | })?; | |
| 319 | ||
| 320 | if did_merge.is_none() { | |
|
91
47d495348e38
Do not prune new insertions on first round
Tuomo Valkonen <tuomov@iki.fi>
parents:
89
diff
changeset
|
321 | // Prune. Do not prune new insertions on first round. |
|
47d495348e38
Do not prune new insertions on first round
Tuomo Valkonen <tuomov@iki.fi>
parents:
89
diff
changeset
|
322 | stats.pruned += prune_with_stats(&mut μ, μ_base_len); |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
323 | } |
| 35 | 324 | |
| 325 | // Update step length parameters | |
| 326 | // let ω = pdpsconfig.acceleration.accelerate(&mut τ, &mut σ, γ); | |
| 327 | ||
| 328 | // Give statistics if requested | |
| 329 | let iter = state.iteration(); | |
| 330 | stats.this_iters += 1; | |
| 331 | ||
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
332 | // Update differential of smooth part |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
333 | Pair(v, dz) = f.differential(Pair(&μ, &z)); |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
334 | τv = v * τ; |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
335 | |
| 35 | 336 | state.if_verbose(|| { |
|
75
677a5fd1b014
Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents:
72
diff
changeset
|
337 | plotter.plot_spikes(iter, None, Some(&τv), &μ); |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
338 | full_stats( |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
339 | &μ, |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
340 | &mut τv, |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
341 | &z, |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
342 | &dz, |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
343 | ε, |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
344 | std::mem::replace(&mut stats, IterInfo::new()), |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
345 | ) |
| 35 | 346 | }); |
| 347 | ||
| 348 | // Update main tolerance for next iteration | |
| 349 | ε = tolerance.update(ε, iter); | |
| 350 | } | |
| 351 | ||
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
352 | let fit = |μ̃: &DiscreteMeasure<U, F>| { |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
353 | f.apply(Pair(μ̃, &z)) /*+ fnR.apply(z) + reg.apply(μ)*/ |
| 35 | 354 | + fnH.apply(/* opKμ.apply(&μ̃) + */ opKz.apply(&z)) |
| 84 | 355 | + reg.apply(μ̃) |
| 35 | 356 | }; |
| 357 | ||
|
39
6316d68b58af
Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
37
diff
changeset
|
358 | μ.merge_spikes_fitness(config.insertion.final_merging_method(), fit, |&v| v); |
| 35 | 359 | μ.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
|
360 | Ok(Pair(μ, z)) |
| 35 | 361 | } |
|
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
|
362 | |
| 89 | 363 | #[deprecated] |
| 364 | pub fn pointsource_forward_pdps_pair< | |
| 365 | F, | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
366 | U, |
| 89 | 367 | I, |
| 368 | S, | |
| 369 | Dat, | |
| 370 | Reg, | |
| 371 | P, | |
| 372 | Z, | |
| 373 | R, | |
| 374 | Y, | |
| 375 | /*KOpM, */ KOpZ, | |
| 376 | H, | |
| 377 | Plot, | |
| 378 | >( | |
| 379 | f: &Dat, | |
| 380 | reg: &Reg, | |
| 381 | prox_penalty: &P, | |
| 382 | config: &ForwardPDPSConfig<F>, | |
| 383 | iterator: I, | |
| 384 | plotter: Plot, | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
385 | init: (Option<DiscreteMeasure<U, F>>, Z, Y), |
| 89 | 386 | //opKμ : KOpM, |
| 387 | opKz: &KOpZ, | |
| 388 | fnR: &R, | |
| 389 | fnH: &H, | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
390 | ) -> DynResult<MeasureZ<F, Z, U>> |
| 89 | 391 | where |
|
96
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
392 | F: Float + ToNalgebraRealField, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
393 | U: Space + Clone, |
|
96
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
394 | //for<'a> &'a U: Instance<U>, |
| 89 | 395 | I: AlgIteratorFactory<IterInfo<F>>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
396 | Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>, |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
397 | S: ClosedMul<F> + MinMaxMapping<U, F>, |
|
96
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
398 | for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>, |
|
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
399 | //Pair<S, Z>: ClosedMul<F>, |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
400 | DiscreteMeasure<U, F>: SpikeMerging<F> + Norm<Radon, F>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
401 | Reg: RegTerm<U, F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
402 | P: ProxPenalty<U, S, Reg, F>, |
| 89 | 403 | KOpZ: BoundedLinear<Z, L2, L2, F, Codomain = Y> |
|
96
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
404 | + GEMV<F, Z> |
|
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
405 | + SimplyAdjointable<Z, Y, AdjointCodomain = Z>, |
|
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
406 | KOpZ::SimpleAdjoint: GEMV<F, Y>, |
| 89 | 407 | Y: ClosedEuclidean<F>, |
| 408 | for<'b> &'b Y: Instance<Y>, | |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
409 | Z: ClosedEuclidean<F> + AXPY + Clone, // clone not neede if Mul worked below |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
410 | for<'b> &'b Z: Instance<Z>, // compiler overflow + Mul<F, Output = Z>, |
| 89 | 411 | R: Prox<Z, Codomain = F>, |
| 412 | H: Conjugable<Y, F, Codomain = F>, | |
| 413 | for<'b> H::Conjugate<'b>: Prox<Y>, | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
414 | Plot: Plotter<P::ReturnMapping, S, DiscreteMeasure<U, F>>, |
| 89 | 415 | { |
| 416 | pointsource_forward_pdps_pair_dom( | |
| 417 | f, | |
| 418 | reg, | |
| 419 | prox_penalty, | |
| 420 | config, | |
| 421 | iterator, | |
| 422 | plotter, | |
| 423 | init, | |
| 424 | opKz, | |
| 425 | fnR, | |
| 426 | fnH, | |
| 427 | &mut FullSpace, | |
| 428 | ) | |
| 429 | } | |
| 430 | ||
|
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
|
431 | /// 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
|
432 | /// 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
|
433 | /// |
|
4f468d35fa29
General forward operators, separation 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 | /// 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
|
435 | /// 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
|
436 | #[replace_float_literals(F::cast_from(literal))] |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
437 | pub fn pointsource_fb_pair_dom<F, U, I, S, Dat, Reg, P, Z, R, Plot>( |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
438 | 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
|
439 | 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
|
440 | 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
|
441 | 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
|
442 | 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
|
443 | plotter: Plot, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
444 | (μ0, z): (Option<DiscreteMeasure<U, F>>, Z), |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
445 | //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
|
446 | fnR: &R, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
447 | domain: &mut impl AdmissibleDomain<U>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
448 | ) -> DynResult<MeasureZ<F, Z, U>> |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
449 | where |
|
96
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
450 | F: Float + ToNalgebraRealField, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
451 | U: Space + Clone, |
|
96
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
452 | for<'a> &'a U: Instance<U>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
453 | I: AlgIteratorFactory<IterInfo<F>>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
454 | Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>, |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
455 | S: ClosedMul<F> + MinMaxMapping<U, F>, |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
456 | DiscreteMeasure<U, F>: SpikeMerging<F> + Norm<Radon, F>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
457 | Reg: RegTerm<U, F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
458 | P: ProxPenalty<U, S, Reg, F>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
459 | for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>, |
|
96
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
460 | Z: ClosedEuclidean<F> + AXPY + Clone, |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
461 | for<'b> &'b Z: Instance<Z>, // compiler overflow + Mul<F, Output = 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
|
462 | R: Prox<Z, Codomain = F>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
463 | Plot: Plotter<P::ReturnMapping, S, DiscreteMeasure<U, F>>, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
464 | { |
|
96
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
465 | let opKz: ZeroOp<Z, Loc<0, F>, _, _, F> = |
|
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
466 | ZeroOp::new_dualisable(StaticEuclideanOriginGenerator, z.dual_origin()); |
|
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
|
467 | 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
|
468 | // 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
|
469 | // 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
|
470 | 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
|
471 | 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
|
472 | |
| 89 | 473 | 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
|
474 | 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
|
475 | 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
|
476 | 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
|
477 | &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
|
478 | 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
|
479 | 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
|
480 | (μ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
|
481 | &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
|
482 | 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
|
483 | &fnH, |
| 89 | 484 | 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
|
485 | ) |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
39
diff
changeset
|
486 | } |
| 89 | 487 | |
| 488 | #[deprecated] | |
| 489 | #[replace_float_literals(F::cast_from(literal))] | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
490 | pub fn pointsource_fb_pair<F, U, I, S, Dat, Reg, P, Z, R, Plot>( |
| 89 | 491 | f: &Dat, |
| 492 | reg: &Reg, | |
| 493 | prox_penalty: &P, | |
| 494 | config: &FBConfig<F>, | |
| 495 | iterator: I, | |
| 496 | plotter: Plot, | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
497 | init: (Option<DiscreteMeasure<U, F>>, Z), |
| 89 | 498 | //opKμ : KOpM, |
| 499 | fnR: &R, | |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
500 | ) -> DynResult<MeasureZ<F, Z, U>> |
| 89 | 501 | where |
|
96
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
502 | F: Float + ToNalgebraRealField, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
503 | U: Space + Clone, |
|
96
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
504 | for<'a> &'a U: Instance<U>, |
| 89 | 505 | I: AlgIteratorFactory<IterInfo<F>>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
506 | Dat: DifferentiableMapping<MeasureZ<F, Z, U>, Codomain = F, DerivativeDomain = Pair<S, Z>>, |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
507 | S: ClosedMul<F> + MinMaxMapping<U, F>, |
|
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
508 | DiscreteMeasure<U, F>: SpikeMerging<F> + Norm<Radon, F>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
509 | Reg: RegTerm<U, F>, |
|
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
510 | P: ProxPenalty<U, S, Reg, F>, |
| 89 | 511 | for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>, |
|
96
5ba25d740dfc
attempt to reduce trait bounds
Tuomo Valkonen <tuomov@iki.fi>
parents:
95
diff
changeset
|
512 | Z: ClosedEuclidean<F> + AXPY + Clone, |
|
98
b9818eb24b47
Store subdifferential discrepancy in log
Tuomo Valkonen <tuomov@iki.fi>
parents:
96
diff
changeset
|
513 | for<'b> &'b Z: Instance<Z>, // compiler overflow + Mul<F, Output = Z>, |
| 89 | 514 | R: Prox<Z, Codomain = F>, |
|
93
8f1e57821d76
Generalise algorithms to arbitrary domains
Tuomo Valkonen <tuomov@iki.fi>
parents:
91
diff
changeset
|
515 | Plot: Plotter<P::ReturnMapping, S, DiscreteMeasure<U, F>>, |
| 89 | 516 | { |
| 517 | pointsource_fb_pair_dom( | |
| 518 | f, | |
| 519 | reg, | |
| 520 | prox_penalty, | |
| 521 | config, | |
| 522 | iterator, | |
| 523 | plotter, | |
| 524 | init, | |
| 525 | fnR, | |
| 526 | &mut FullSpace, | |
| 527 | ) | |
| 528 | } |