src/sliding_pdps.rs

Mon, 03 Aug 2026 19:28:07 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Mon, 03 Aug 2026 19:28:07 -0500
changeset 86
1c74bb0439a8
parent 84
edb5de5d5bd6
child 89
8d1c959432c8
permissions
-rw-r--r--

alg_tools version bump

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 sliding
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
3 primal-dual proximal splitting method.
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
4 */
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
5
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
6 use crate::fb::*;
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
7 use crate::forward_model::{BoundedCurvature, BoundedCurvatureGuess};
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
8 use crate::measures::merging::SpikeMerging;
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
9 use crate::measures::{DiscreteMeasure, RNDM};
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: 49
diff changeset
10 use crate::plot::Plotter;
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: 68
diff changeset
11 use crate::prox_penalty::StepLengthBoundPair;
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: 49
diff changeset
12 use crate::regularisation::SlidingRegTerm;
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: 68
diff changeset
13 use crate::sliding_fb::{SlidingFBConfig, Transport, TransportConfig, TransportProxPenalty};
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: 49
diff changeset
14 use crate::types::*;
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: 68
diff changeset
15 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: 49
diff changeset
16 use alg_tools::convex::{Conjugable, Prox, Zero};
81
642141008293 Add regularisation term to merge fitness for scaling heuristic to be justified
Tuomo Valkonen <tuomov@iki.fi>
parents: 78
diff changeset
17 use alg_tools::norms::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: 49
diff changeset
18 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: 49
diff changeset
19 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: 49
diff changeset
20 use alg_tools::euclidean::ClosedEuclidean;
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
21 use alg_tools::iterate::AlgIteratorFactory;
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
22 use alg_tools::linops::{
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
23 BoundedLinear, IdOp, SimplyAdjointable, StaticEuclideanOriginGenerator, 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: 49
diff changeset
24 };
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
25 use alg_tools::mapping::{DifferentiableMapping, DifferentiableRealMapping, Instance};
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
26 use alg_tools::nalgebra_support::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: 49
diff changeset
27 use anyhow::ensure;
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
28 use numeric_literals::replace_float_literals;
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
29 use serde::{Deserialize, Serialize};
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
30
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
31 /// Settings for [`pointsource_sliding_pdps_pair`].
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
32 #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)]
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
33 #[serde(default)]
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
34 pub struct SlidingPDPSConfig<F: Float> {
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: 49
diff changeset
35 /// Overall primal step length scaling.
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
36 pub τ0: 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: 49
diff changeset
37 /// Primal step length scaling for additional variable.
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
38 pub σp0: 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: 49
diff changeset
39 /// 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: 49
diff changeset
40 ///
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
41 /// Taken zero for [`pointsource_sliding_fb_pair`].
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
42 pub σd0: F,
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
43 /// Transport parameters
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
44 pub transport: TransportConfig<F>,
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
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: 49
diff changeset
46 pub insertion: InsertionConfig<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: 49
diff changeset
47 /// Guess for curvature bound calculations.
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
48 pub guess: BoundedCurvatureGuess,
35
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
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
51 #[replace_float_literals(F::cast_from(literal))]
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
52 impl<F: Float> Default for SlidingPDPSConfig<F> {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
53 fn default() -> Self {
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
54 SlidingPDPSConfig {
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
55 τ0: 0.99,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
56 σd0: 0.05,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
57 σp0: 0.99,
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: 49
diff changeset
58 transport: TransportConfig { θ0: 0.9, ..Default::default() },
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
59 insertion: Default::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: 49
diff changeset
60 guess: BoundedCurvatureGuess::BetterThanZero,
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
61 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
62 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
63 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
64
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: 49
diff changeset
65 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
66
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
67 /// Iteratively solve the pointsource localisation with an additional variable
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
68 /// using sliding primal-dual proximal splitting
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
69 ///
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
70 /// The parametrisation is as for [`crate::forward_pdps::pointsource_forward_pdps_pair`],
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
71 /// except an additional domain restriction may be given.
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
72 #[replace_float_literals(F::cast_from(literal))]
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
73 pub fn pointsource_sliding_pdps_pair_dom<
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
74 F,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
75 I,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
76 S,
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: 49
diff changeset
77 Dat,
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
78 Reg,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
79 P,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
80 Z,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
81 R,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
82 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: 49
diff changeset
83 Plot,
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
84 /*KOpM, */ KOpZ,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
85 H,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
86 const N: usize,
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
87 >(
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: 49
diff changeset
88 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: 49
diff changeset
89 reg: &Reg,
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
90 prox_penalty: &P,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
91 config: &SlidingPDPSConfig<F>,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
92 iterator: I,
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: 49
diff changeset
93 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: 49
diff changeset
94 (μ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
95 //opKμ : KOpM,
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
96 opKz: &KOpZ,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
97 fnR: &R,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
98 fnH: &H,
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
99 domain: Option<&P::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: 49
diff changeset
100 ) -> DynResult<MeasureZ<F, Z, N>>
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
101 where
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
102 F: Float + 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: 49
diff changeset
103 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: 49
diff changeset
104 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: 49
diff changeset
105 + BoundedCurvature<F>,
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: 68
diff changeset
106 S: DifferentiableRealMapping<N, F> + ClosedMul<F> + MinMaxMapping<Loc<N, F>, 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: 49
diff changeset
107 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: 49
diff changeset
108 //Pair<S, Z>: 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: 49
diff changeset
109 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: 49
diff changeset
110 Reg: SlidingRegTerm<Loc<N, F>, F>,
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: 68
diff changeset
111 P: TransportProxPenalty<Loc<N, F>, 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: 49
diff changeset
112 // KOpM : Linear<RNDM<N, 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: 49
diff changeset
113 // + GEMV<F, RNDM<N, F>>
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
114 // + Preadjointable<
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: 49
diff changeset
115 // RNDM<N, F>, Y,
37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents: 36
diff changeset
116 // PreadjointCodomain = S,
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
117 // >
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
118 // + TransportLipschitz<L2Squared, FloatType=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: 49
diff changeset
119 // + AdjointProductBoundedBy<RNDM<N, F>, 𝒟, FloatType=F>,
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
120 // for<'b> KOpM::Preadjoint<'b> : GEMV<F, Y>,
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
121 // Since Z is Hilbert, we may just as well use adjoints for K_z.
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
122 KOpZ: BoundedLinear<Z, L2, L2, F, Codomain = Y>
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
123 + GEMV<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: 49
diff changeset
124 + SimplyAdjointable<Z, 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: 49
diff changeset
125 KOpZ::SimpleAdjoint: GEMV<F, 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: 49
diff changeset
126 Y: ClosedEuclidean<F>,
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
127 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: 68
diff changeset
128 Z: ClosedEuclidean<F> + AXPY,
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
129 for<'b> &'b Z: Instance<Z>,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
130 R: Prox<Z, Codomain = F>,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
131 H: Conjugable<Y, F, Codomain = F>,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
132 for<'b> H::Conjugate<'b>: Prox<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: 49
diff changeset
133 Plot: Plotter<P::ReturnMapping, S, RNDM<N, F>>,
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
134 {
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
135 // Check parameters
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
136 /*ensure!(
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
137 config.τ0 > 0.0
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
138 && config.τ0 < 1.0
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
139 && config.σp0 > 0.0
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
140 && config.σp0 < 1.0
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
141 && config.σd0 > 0.0
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
142 && config.σp0 * config.σd0 <= 1.0,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
143 "Invalid step length 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: 49
diff changeset
144 );*/
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
145 config.transport.check()?;
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
146
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
147 // 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: 49
diff changeset
148 let mut μ = μ0.unwrap_or_else(|| DiscreteMeasure::new());
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
149 let mut γ = Transport::new();
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: 49
diff changeset
150 //let zero_z = z.similar_origin();
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
151
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
152 // Set up parameters
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
153 // TODO: maybe this PairNorm doesn't make sense here?
41
b6bdb6cb4d44 Remove initial transport adaptation—it is not needed, after all
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
154 // let opAnorm = opA.opnorm_bound(PairNorm(Radon, L2, L2), L2);
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
155 let bigθ = 0.0; //opKμ.transport_lipschitz_factor(L2Squared);
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
156 let bigM = 0.0; //opKμ.adjoint_product_bound(&op𝒟).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: 49
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: 63
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: 49
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: 49
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: 49
diff changeset
161 let (l, l_z) = Pair(prox_penalty, &idOpZ).step_length_bound_pair(&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: 49
diff changeset
162
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
163 // We need to satisfy
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
164 //
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
165 // τσ_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
166 // ^^^^^^^^^^^^^^^^^^^^^^^^^
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
167 // with 1 > σ_p L_z and 1 > τ L.
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
168 //
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
169 // 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
170 // ^^^^^ < 1. then we solve τ from the rest.
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
171 // If opKZ is the zero operator, then we set σ_d = 0 for τ to be calculated correctly below.
66
fe47ad484deb Allow fitness merge when forward_pdps and sliding_pdps are used as forward-backward with aux variable.
Tuomo Valkonen <tuomov@iki.fi>
parents: 63
diff changeset
172 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
173 let σ_p = config.σp0 / (l_z + config.σd0 * nKz);
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
174 // Observe that = 1 - ^^^^^^^^^^^^^^^^^^^^^ = 1 - σ_{p,0}
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
175 // 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
176 // ⟺ τ [ σ_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
177 let φ = 1.0 - config.σp0;
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
178 let a = 1.0 - σ_p * l_z;
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
179 let τ = config.τ0 * φ / (σ_d * bigM * a + φ * l);
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
180 let ψ = 1.0 - τ * l;
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
181 let β = σ_p * config.σd0 * nKz / a; // σ_p * σ_d * (nKz * nK_z) / a;
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: 49
diff changeset
182 ensure!(β < 1.0);
44
03251c546744 curvature controls
Tuomo Valkonen <tuomov@iki.fi>
parents: 41
diff changeset
183 // Now we need κ‖K_μ(π_♯^1 - π_♯^0)γ‖^2 ≤ (1/θ - τ[ℓ_F + ℓ]) ∫ c_2 dγ for κ defined as:
36
fb911f72e698 Factor fix
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
184 let κ = τ * σ_d * ψ / ((1.0 - β) * ψ - τ * σ_d * bigM);
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
185 // The factor two in the manuscript disappears due to the definition of 𝚹 being
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
186 // for ‖x-y‖₂² instead of c_2(x, y)=‖x-y‖₂²/2.
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
187
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: 68
diff changeset
188 let mut τθ_or_adaptive = prox_penalty.get_transport_steplength(
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: 68
diff changeset
189 f.curvature_bound_components(config.guess),
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: 68
diff changeset
190 &config.transport,
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: 68
diff changeset
191 0.0,
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: 68
diff changeset
192 κ * bigθ / τ, // = 0 currently
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: 68
diff changeset
193 );
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: 68
diff changeset
194
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
195 // Acceleration is not currently supported
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
196 // let γ = dataterm.factor_of_strong_convexity();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
197 let ω = 1.0;
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
198
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
199 // 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
200 // by τ compared to the conditional gradient approach.
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
201 let tolerance = config.insertion.tolerance * τ * reg.tolerance_scaling();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
202 let mut ε = tolerance.initial();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
203
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
204 let starH = fnH.conjugate();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
205
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
206 // 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: 49
diff changeset
207 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: 49
diff changeset
208 value: f.apply(Pair(μ, z))
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
209 + fnR.apply(z)
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
210 + reg.apply(μ)
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
211 + fnH.apply(/* opKμ.apply(μ) + */ opKz.apply(z)),
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
212 n_spikes: μ.len(),
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
213 ε,
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
214 // postprocessing: config.insertion.postprocessing.then(|| μ.clone()),
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
215 ..stats
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
216 };
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
217 let mut stats = IterInfo::new();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
218
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
219 // 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: 49
diff changeset
220 for state in iterator.iter_init(|| full_stats(&μ, &z, ε, stats.clone())) {
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: 68
diff changeset
221 let Pair(mut v, _) = f.differential(Pair(&μ, &z));
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: 68
diff changeset
222
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
223 //opKμ.preadjoint().apply_add(&mut v, y);
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
224 // We want to proceed as in Example 4.12 but with v and v̆ as in §5.
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
225 // With A(ν, z) = A_μ ν + A_z z, following Example 5.1, we have
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
226 // P_ℳ[F'(ν, z) + Ξ(ν, z, y)]= A_ν^*[A_ν ν + A_z z] + K_μ ν = A_ν^*A(ν, z) + K_μ ν,
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
227 // where A_ν^* becomes a multiplier.
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
228 // This is much easier with K_μ = 0, which is the only reason why are enforcing it.
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
229 // TODO: Write a version of initial_transport that can deal with K_μ ≠ 0.
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
230
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: 49
diff changeset
231 //dbg!(&μ);
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
232
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: 68
diff changeset
233 prox_penalty.initial_transport(
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: 68
diff changeset
234 &mut γ,
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: 68
diff changeset
235 &μ,
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: 68
diff changeset
236 ε,
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: 68
diff changeset
237 τ,
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: 68
diff changeset
238 &mut τθ_or_adaptive,
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: 68
diff changeset
239 &v,
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: 68
diff changeset
240 &config.transport,
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
241 domain,
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: 68
diff changeset
242 );
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
243
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
244 let mut attempts = 0;
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
245
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
246 // Solve finite-dimensional subproblem several times until the dual variable for the
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
247 // regularisation term conforms to the assumptions made for the transport above.
75
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
248 let (mut τv̆, z_new, μ̆) = 'adapt_transport: loop {
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
249 // Set initial guess for μ=μ^{k+1}.
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
250 γ.μ̆_into(&mut μ);
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
251 let μ̆ = μ.clone();
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
252
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
253 // Calculate τv̆ = τA_*(A[μ_transported + μ_transported_base]-b)
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: 68
diff changeset
254 let Pair(v̆, mut z̆) = f.differential(Pair(&μ̆, &z));
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: 68
diff changeset
255 let mut τv̆ = v̆ * τ;
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
256 // opKμ.preadjoint().gemv(&mut τv̆, τ, y, 1.0);
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
257
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
258 // 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
259 prox_penalty.insert_and_reweigh(
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
260 &mut μ,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
261 &mut τv̆,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
262 τ,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
263 ε,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
264 &config.insertion,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
265 &reg,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
266 &state,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
267 &mut stats,
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: 49
diff changeset
268 )?;
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
269
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
270 // Do z variable primal update here to able to estimate B_{v̆^k-v^{k+1}}
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: 68
diff changeset
271 opKz_adj.apply_add(&mut z̆, &y);
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: 68
diff changeset
272 z̆.axpy(1.0, &z, -σ_p);
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: 68
diff changeset
273 let z_new = fnR.prox(σ_p, z̆);
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: 68
diff changeset
274 //let z_new = fnR.prox(σ_p, z̆ * (-σ_p) + &z);
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
275
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
276 // A posteriori transport adaptation.
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: 68
diff changeset
277 if prox_penalty.aposteriori_transport(
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: 68
diff changeset
278 &mut γ,
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
279 &μ,
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
280 &μ̆,
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
281 &mut τv̆,
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: 68
diff changeset
282 &mut v,
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: 68
diff changeset
283 None, //Some(z_new.dist2(&z)),
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
284 ε,
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: 68
diff changeset
285 τ,
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: 68
diff changeset
286 &τθ_or_adaptive,
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: 68
diff changeset
287 reg,
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
288 &config.transport,
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: 68
diff changeset
289 &config.insertion.refinement,
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
290 &mut attempts,
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
291 ) {
75
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
292 break 'adapt_transport (τv̆, z_new, μ̆);
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 };
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
295
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
296 γ.get_transport_stats(&mut stats, &μ);
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
297
75
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
298 // Do dual update
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
299 // opKμ.gemv(&mut y, σ_d*(1.0 + ω), &μ, 1.0); // y = y + σ_d K[(1+ω)(μ,z)^{k+1}]
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
300 z.axpy(1.0 + ω, &z_new, -ω);
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
301 //z = (z - &z_new) * (-ω) + &z_new;
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
302 opKz.gemv(&mut y, σ_d, z, 1.0);
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
303 y = starH.prox(σ_d, y);
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
304 z = z_new;
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
305
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
306 // Merge spikes.
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
307 // 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
308 // and not to performing any pruning. That is be to done below simultaneously for γ.
78
2a122736e91c Add maximum iteration setting for scaling heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
309 config.insertion.if_merge_now(&state, |ins| {
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: 68
diff changeset
310 let m = prox_penalty.merge_spikes(
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
311 &mut μ,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
312 &mut τv̆,
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
313 &μ̆,
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
314 τ,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
315 ε,
78
2a122736e91c Add maximum iteration setting for scaling heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
316 ins,
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 45
diff changeset
317 &reg,
81
642141008293 Add regularisation term to merge fitness for scaling heuristic to be justified
Tuomo Valkonen <tuomov@iki.fi>
parents: 78
diff changeset
318 Some(|μ̃: &RNDM<N, F>| f.apply(Pair(μ̃, &z)) + reg.apply(μ̃)),
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
319 );
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: 68
diff changeset
320 if m > 0 {
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: 68
diff changeset
321 stats.merged += m;
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: 68
diff changeset
322 }
78
2a122736e91c Add maximum iteration setting for scaling heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
323 });
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
324
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
325 γ.prune_compat(&mut μ, &mut stats);
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
326
75
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
327 for _ in 0..config.insertion.extra_weight_optimisation_steps {
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
328 // Do extra weight optimisation step heuristic
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
329 let Pair(v, mut _z_tmp) = f.differential(Pair(&μ, &z));
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
330 τv̆ = v * τ;
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
331 prox_penalty.reweigh(
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
332 &mut μ,
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
333 &mut τv̆,
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
334 τ,
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
335 ε,
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
336 &config.insertion,
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
337 &reg,
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
338 &state,
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
339 &mut stats,
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
340 )?;
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
341
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
342 // opKz_adj.apply_add(&mut z_tmp, &y);
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
343 // z_tmp.axpy(1.0, &z, -σ_p);
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
344 // let z_new = fnR.prox(σ_p, z_tmp);
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
345 // z.axpy(1.0 + ω, &z_new, -ω);
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
346 // //z = (z - &z_new) * (-ω) + &z_new;
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
347 // opKz.gemv(&mut y, σ_d, z, 1.0);
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
348 // y = starH.prox(σ_d, y);
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
349 // z = z_new;
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
350 }
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
351
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
352 if config.insertion.extra_weight_optimisation_steps > 0 {
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
353 γ.prune_compat(&mut μ, &mut stats);
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
354 }
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
355
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
356 // Update step length parameters
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
357 // let ω = pdpsconfig.acceleration.accelerate(&mut τ, &mut σ, γ);
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
358
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
359 // Give statistics if requested
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
360 let iter = state.iteration();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
361 stats.this_iters += 1;
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
362
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
363 state.if_verbose(|| {
75
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
364 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: 49
diff changeset
365 full_stats(&μ, &z, ε, std::mem::replace(&mut stats, IterInfo::new()))
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
366 });
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
367
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
368 // Update main tolerance for next iteration
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
369 ε = tolerance.update(ε, iter);
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
370 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
371
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: 49
diff changeset
372 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: 49
diff changeset
373 f.apply(Pair(μ̃, &z)) /*+ fnR.apply(z) + reg.apply(μ)*/
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
374 + fnH.apply(/* opKμ.apply(&μ̃) + */ opKz.apply(&z))
84
edb5de5d5bd6 Minor merging adjustments
Tuomo Valkonen <tuomov@iki.fi>
parents: 83
diff changeset
375 + reg.apply(μ̃)
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
376 };
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
377
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
378 μ.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
379 μ.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: 49
diff changeset
380 Ok(Pair(μ, z))
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
381 }
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: 49
diff changeset
382
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
383 /// 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: 49
diff changeset
384 /// using sliding 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: 49
diff changeset
385 ///
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
386 /// The implementation uses [`pointsource_sliding_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: 49
diff changeset
387 /// 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: 49
diff changeset
388 #[replace_float_literals(F::cast_from(literal))]
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
389 pub fn pointsource_sliding_fb_pair_dom<F, I, S, Dat, Reg, P, Z, R, Plot, const N: usize>(
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
390 f: &Dat,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
391 reg: &Reg,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
392 prox_penalty: &P,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
393 config: &SlidingFBConfig<F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
394 iterator: I,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
395 plotter: Plot,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
396 (μ0, z): (Option<RNDM<N, F>>, Z),
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
397 //opKμ : KOpM,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
398 fnR: &R,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
399 domain: Option<&P::Dom>
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
400 ) -> DynResult<MeasureZ<F, Z, N>>
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
401 where
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
402 F: Float + ToNalgebraRealField,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
403 I: AlgIteratorFactory<IterInfo<F>>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
404 Dat: DifferentiableMapping<MeasureZ<F, Z, N>, Codomain = F, DerivativeDomain = Pair<S, Z>>
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
405 + BoundedCurvature<F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
406 S: DifferentiableRealMapping<N, F> + ClosedMul<F> + MinMaxMapping<Loc<N, F>, F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
407 RNDM<N, F>: SpikeMerging<F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
408 Reg: SlidingRegTerm<Loc<N, F>, F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
409 P: TransportProxPenalty<Loc<N, F>, S, Reg, F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
410 for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
411 Z: ClosedEuclidean<F> + AXPY + Clone,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
412 for<'b> &'b Z: Instance<Z>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
413 R: Prox<Z, Codomain = F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
414 Plot: Plotter<P::ReturnMapping, S, RNDM<N, F>>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
415 // We should not need to explicitly require this:
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
416 for<'b> &'b Loc<0, F>: Instance<Loc<0, F>>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
417 // Loc<0, F>: StaticEuclidean<Field = F, PrincipalE = Loc<0, F>>
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
418 // + Instance<Loc<0, F>>
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
419 // + VectorSpace<Field = F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
420 {
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
421 let opKz: ZeroOp<Z, Loc<0, F>, _, _, F> =
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
422 ZeroOp::new_dualisable(StaticEuclideanOriginGenerator, z.dual_origin());
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
423 let fnH = Zero::new();
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
424 // Convert config. We don't implement From (that could be done with the o2o crate), as σd0
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
425 // needs to be chosen in a general case; for the problem of this fucntion, anything is valid.
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
426 let &SlidingFBConfig { τ0, σp0, insertion, transport, guess } = config;
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
427 let pdps_config = SlidingPDPSConfig { τ0, σp0, insertion, transport, guess, σd0: 0.0 };
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
428
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
429 pointsource_sliding_pdps_pair_dom(
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
430 f,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
431 reg,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
432 prox_penalty,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
433 &pdps_config,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
434 iterator,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
435 plotter,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
436 (μ0, z, Loc([])),
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
437 &opKz,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
438 fnR,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
439 &fnH,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
440 domain
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
441 )
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
442 }
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
443
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
444
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
445 #[deprecated]
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
446 /// Version of [`pointsource_sliding_pdps_pair`] without domain specification.
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
447 #[replace_float_literals(F::cast_from(literal))]
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
448 pub fn pointsource_sliding_pdps_pair<
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
449 F,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
450 I,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
451 S,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
452 Dat,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
453 Reg,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
454 P,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
455 Z,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
456 R,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
457 Y,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
458 Plot,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
459 /*KOpM, */ KOpZ,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
460 H,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
461 const N: usize,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
462 >(
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
463 f: &Dat,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
464 reg: &Reg,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
465 prox_penalty: &P,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
466 config: &SlidingPDPSConfig<F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
467 iterator: I,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
468 plotter: Plot,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
469 init: (Option<RNDM<N, F>>, Z, Y),
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
470 //opKμ : KOpM,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
471 opKz: &KOpZ,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
472 fnR: &R,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
473 fnH: &H,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
474 ) -> DynResult<MeasureZ<F, Z, N>>
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
475 where
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
476 F: Float + ToNalgebraRealField,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
477 I: AlgIteratorFactory<IterInfo<F>>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
478 Dat: DifferentiableMapping<MeasureZ<F, Z, N>, Codomain = F, DerivativeDomain = Pair<S, Z>>
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
479 + BoundedCurvature<F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
480 S: DifferentiableRealMapping<N, F> + ClosedMul<F> + MinMaxMapping<Loc<N, F>, F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
481 for<'a> Pair<&'a P, &'a IdOp<Z>>: StepLengthBoundPair<F, Dat>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
482 //Pair<S, Z>: ClosedMul<F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
483 RNDM<N, F>: SpikeMerging<F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
484 Reg: SlidingRegTerm<Loc<N, F>, F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
485 P: TransportProxPenalty<Loc<N, F>, S, Reg, F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
486 // KOpM : Linear<RNDM<N, F>, Codomain=Y>
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
487 // + GEMV<F, RNDM<N, F>>
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
488 // + Preadjointable<
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
489 // RNDM<N, F>, Y,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
490 // PreadjointCodomain = S,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
491 // >
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
492 // + TransportLipschitz<L2Squared, FloatType=F>
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
493 // + AdjointProductBoundedBy<RNDM<N, F>, 𝒟, FloatType=F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
494 // for<'b> KOpM::Preadjoint<'b> : GEMV<F, Y>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
495 // Since Z is Hilbert, we may just as well use adjoints for K_z.
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
496 KOpZ: BoundedLinear<Z, L2, L2, F, Codomain = Y>
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
497 + GEMV<F, Z>
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
498 + SimplyAdjointable<Z, Y, AdjointCodomain = Z>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
499 KOpZ::SimpleAdjoint: GEMV<F, Y>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
500 Y: ClosedEuclidean<F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
501 for<'b> &'b Y: Instance<Y>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
502 Z: ClosedEuclidean<F> + AXPY,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
503 for<'b> &'b Z: Instance<Z>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
504 R: Prox<Z, Codomain = F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
505 H: Conjugable<Y, F, Codomain = F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
506 for<'b> H::Conjugate<'b>: Prox<Y>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
507 Plot: Plotter<P::ReturnMapping, S, RNDM<N, F>>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
508 {
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
509 pointsource_sliding_pdps_pair_dom(
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
510 f,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
511 reg,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
512 prox_penalty,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
513 config,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
514 iterator,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
515 plotter,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
516 init,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
517 opKz,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
518 fnR,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
519 fnH,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
520 None,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
521 )
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
522 }
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
523
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
524 #[deprecated]
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
525 /// Version of [`pointsource_sliding_fb_pair_dom`] without domain specification
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
526 #[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: 49
diff changeset
527 pub fn pointsource_sliding_fb_pair<F, I, S, Dat, Reg, P, Z, R, Plot, const N: usize>(
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
528 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: 49
diff changeset
529 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: 49
diff changeset
530 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: 49
diff changeset
531 config: &SlidingFBConfig<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: 49
diff changeset
532 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: 49
diff changeset
533 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: 49
diff changeset
534 (μ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: 49
diff changeset
535 //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: 49
diff changeset
536 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: 49
diff changeset
537 ) -> 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: 49
diff changeset
538 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: 49
diff changeset
539 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: 49
diff changeset
540 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: 49
diff changeset
541 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: 49
diff changeset
542 + BoundedCurvature<F>,
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: 68
diff changeset
543 S: DifferentiableRealMapping<N, F> + ClosedMul<F> + MinMaxMapping<Loc<N, F>, 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: 49
diff changeset
544 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: 49
diff changeset
545 Reg: SlidingRegTerm<Loc<N, F>, F>,
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: 68
diff changeset
546 P: TransportProxPenalty<Loc<N, F>, 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: 49
diff changeset
547 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: 49
diff changeset
548 Z: ClosedEuclidean<F> + AXPY + 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: 49
diff changeset
549 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: 49
diff changeset
550 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: 49
diff changeset
551 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: 49
diff changeset
552 // 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: 49
diff changeset
553 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: 49
diff changeset
554 // Loc<0, F>: StaticEuclidean<Field = F, PrincipalE = 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: 49
diff changeset
555 // + 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: 49
diff changeset
556 // + VectorSpace<Field = 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: 49
diff changeset
557 {
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
558 let opKz: ZeroOp<Z, Loc<0, 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: 49
diff changeset
559 ZeroOp::new_dualisable(StaticEuclideanOriginGenerator, 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: 49
diff changeset
560 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: 49
diff changeset
561 // 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: 49
diff changeset
562 // 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: 49
diff changeset
563 let &SlidingFBConfig { τ0, σp0, insertion, transport, guess } = 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: 49
diff changeset
564 let pdps_config = SlidingPDPSConfig { τ0, σp0, insertion, transport, guess, σ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: 49
diff changeset
565
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
566 pointsource_sliding_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: 49
diff changeset
567 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: 49
diff changeset
568 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: 49
diff changeset
569 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: 49
diff changeset
570 &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: 49
diff changeset
571 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: 49
diff changeset
572 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: 49
diff changeset
573 (μ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: 49
diff changeset
574 &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: 49
diff changeset
575 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: 49
diff changeset
576 &fnH,
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
577 None
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: 49
diff changeset
578 )
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
579 }

mercurial