src/sliding_fb.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

32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1 /*!
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
2 Solver for the point source localisation problem using a sliding
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
3 forward-backward splitting method.
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
4 */
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
5
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
6 use numeric_literals::replace_float_literals;
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
7 use serde::{Deserialize, Serialize};
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
8 //use colored::Colorize;
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
9 //use nalgebra::{DVector, DMatrix};
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
10 use itertools::izip;
34
efa60bc4f743 Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 32
diff changeset
11 use std::iter::Iterator;
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
12 use std::ops::MulAssign;
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
13
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::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
15 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
16 use crate::measures::merging::SpikeMerging;
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
17 use crate::measures::{DeltaMeasure, DiscreteMeasure, Radon, 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
18 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
19 use crate::prox_penalty::{ProxPenalty, RadonSquared, StepLengthBound};
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
20 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
21 use crate::seminorms::DiscreteMeasureOp;
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
22 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
23 use alg_tools::bounds::{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
24 use alg_tools::error::DynResult;
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
25 use alg_tools::euclidean::Euclidean;
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
26 use alg_tools::instance::Space;
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
27 use alg_tools::iterate::AlgIteratorFactory;
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
28 use alg_tools::mapping::{DifferentiableMapping, DifferentiableRealMapping, Mapping, RealMapping};
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
29 use alg_tools::nalgebra_support::ToNalgebraRealField;
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
30 use alg_tools::norms::Norm;
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
31 use alg_tools::sets::{Set, Cube};
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
32 use anyhow::ensure;
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
33 use std::ops::ControlFlow;
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
34
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
35 /// Transport settings for [`pointsource_sliding_fb_reg`].
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
36 #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)]
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
37 #[serde(default)]
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
38 pub struct TransportConfig<F: Float> {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
39 /// Transport step length $θ$ normalised to $(0, 1)$.
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
40 pub θ0: 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
41 /// Unnormalised transport step length $θ$. Overrides θ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
42 pub τθ: Option<F>,
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
43 /// Factor in $(0, 1)$ for decreasing transport to adapt to tolerance.
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
44 pub adaptation: 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
45 /// A posteriori transport tolerance multiplier
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
46 pub tolerance_mult: F,
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
47 /// Multiplier for rough estimate of ℓ_{∇v}. Should be ≥ 1.
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
48 /// If explicit τθ is given, ℓ_{∇v} is one divided by this number times τθ.
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
49 /// Otherwise, if τθ relative to an estimate of ℓ_{∇v}, this number multiplies that estimate.
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
50 pub ℓ_gradv_mult: F,
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
51 /// maximum number of adaptation iterations, until cancelling transport.
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
52 pub max_attempts: usize,
68
00d0881f89a6 Automatic transport disabling after sufficient failures, for efficiency
Tuomo Valkonen <tuomov@iki.fi>
parents: 63
diff changeset
53 /// Maximum number of failed transportations for a single source point
00d0881f89a6 Automatic transport disabling after sufficient failures, for efficiency
Tuomo Valkonen <tuomov@iki.fi>
parents: 63
diff changeset
54 pub max_fail: usize,
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
55 /// Allow points to be transported partially.
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
56 pub allow_partial_transport: bool,
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
57 /// Use an alternative remainder control rule.
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
58 pub alt_remainder_control: bool,
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
59 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
60
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
61 #[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: 46
diff changeset
62 impl<F: Float> TransportConfig<F> {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
63 /// Check that the parameters are ok. Panics if not.
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
64 pub fn check(&self) -> 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
65 ensure!(self.θ0 > 0.0);
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
66 ensure!(0.0 < self.adaptation && self.adaptation < 1.0);
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
67 ensure!(self.tolerance_mult > 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
68 Ok(())
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
69 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
70 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
71
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
72 #[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: 46
diff changeset
73 impl<F: Float> Default for TransportConfig<F> {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
74 fn default() -> Self {
68
00d0881f89a6 Automatic transport disabling after sufficient failures, for efficiency
Tuomo Valkonen <tuomov@iki.fi>
parents: 63
diff changeset
75 TransportConfig {
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
76 θ0: 0.99,
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
77 τθ: None,
68
00d0881f89a6 Automatic transport disabling after sufficient failures, for efficiency
Tuomo Valkonen <tuomov@iki.fi>
parents: 63
diff changeset
78 adaptation: 0.9,
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
79 allow_partial_transport: true,
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
80 alt_remainder_control: false,
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
81 tolerance_mult: 1e1,
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
82 ℓ_gradv_mult: 3.0,
68
00d0881f89a6 Automatic transport disabling after sufficient failures, for efficiency
Tuomo Valkonen <tuomov@iki.fi>
parents: 63
diff changeset
83 max_attempts: 2,
00d0881f89a6 Automatic transport disabling after sufficient failures, for efficiency
Tuomo Valkonen <tuomov@iki.fi>
parents: 63
diff changeset
84 max_fail: usize::MAX,
00d0881f89a6 Automatic transport disabling after sufficient failures, for efficiency
Tuomo Valkonen <tuomov@iki.fi>
parents: 63
diff changeset
85 }
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
86 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
87 }
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
88
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
89 /// Settings for [`pointsource_sliding_fb_reg`].
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
90 #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)]
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
91 #[serde(default)]
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
92 pub struct SlidingFBConfig<F: Float> {
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
93 /// Step length scaling
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
94 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
95 // Auxiliary variable step length scaling for [`crate::sliding_pdps::pointsource_sliding_fb_pair`]
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
96 pub σp0: F,
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
97 /// Transport parameters
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
98 pub transport: TransportConfig<F>,
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
99 /// 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
100 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
101 /// 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
102 pub guess: BoundedCurvatureGuess,
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
103 }
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
104
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
105 #[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: 46
diff changeset
106 impl<F: Float> Default for SlidingFBConfig<F> {
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
107 fn default() -> Self {
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
108 SlidingFBConfig {
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
109 τ0: 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
110 σp0: 0.99,
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
111 transport: Default::default(),
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
112 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
113 guess: BoundedCurvatureGuess::BetterThanZero,
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
114 }
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
115 }
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
116 }
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
117
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
118 /// Internal type of adaptive transport step length calculation
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
119 #[derive(Clone, Debug, Serialize, Deserialize)]
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
120 pub enum TransportStepLength<F: Float> {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
121 /// Fixed, known step length
44
03251c546744 curvature controls
Tuomo Valkonen <tuomov@iki.fi>
parents: 41
diff changeset
122 #[allow(dead_code)]
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
123 Fixed { τθ: F, ℓ_gradv: F },
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
124 /// Simple step lengths that do not depend on maximum 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
125 Simple { ℓ_gradv: F, τθ0: F, ℓ_base: F },
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
126 /// Adaptive step length, only wrt. maximum 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
127 AdaptiveMax {
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 ℓ_gradv: F,
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
129 adaptive_max_transport: F,
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
130 τθ0: F,
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
131 ℓ_base: F,
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
132 ℓ_base_max_transport: F,
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
133 },
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
134 /// Adaptive step length.
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
135 FullyAdaptive {
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
136 adaptive_ℓ_gradv: F,
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
137 adaptive_max_transport: F,
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
138 τθ0: F,
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
139 ℓ_base: F,
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
140 ℓ_base_max_transport: F,
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
141 },
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
142 }
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
143
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
144 #[replace_float_literals(F::cast_from(literal))]
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
145 impl<F: Float> TransportStepLength<F> {
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
146 fn get_ℓ_gradv(&self) -> F {
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
147 use TransportStepLength::*;
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
148 match *self {
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
149 Fixed { ℓ_gradv, .. } => ℓ_gradv,
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
150 Simple { ℓ_gradv, .. } => ℓ_gradv,
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
151 AdaptiveMax { ℓ_gradv, .. } => ℓ_gradv,
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
152 FullyAdaptive { adaptive_ℓ_gradv, .. } => adaptive_ℓ_gradv,
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
153 }
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
154 }
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
155
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
156 fn new(
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
157 maybe_ℓ_gradv_est: DynResult<F>,
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
158 tconfig: &TransportConfig<F>,
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
159 ℓ_base: F,
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
160 ℓ_base_max_transport: F,
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
161 ) -> Self {
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
162 if let Some(τθ) = tconfig.τθ {
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
163 TransportStepLength::Fixed { τθ, ℓ_gradv: 1.0 / (τθ * tconfig.ℓ_gradv_mult) }
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
164 } else {
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
165 match maybe_ℓ_gradv_est {
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
166 Ok(ℓ_gradv_est) => {
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
167 if ℓ_base_max_transport == 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
168 TransportStepLength::Simple {
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
169 ℓ_gradv: tconfig.ℓ_gradv_mult * ℓ_gradv_est,
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
170 τθ0: tconfig.θ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
171 ℓ_base,
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
172 }
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
173 } else {
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
174 TransportStepLength::AdaptiveMax {
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
175 ℓ_gradv: tconfig.ℓ_gradv_mult * ℓ_gradv_est,
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
176 adaptive_max_transport: 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
177 τθ0: tconfig.θ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
178 ℓ_base,
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
179 ℓ_base_max_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
180 }
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
181 }
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
182 }
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
183 Err(_) => TransportStepLength::FullyAdaptive {
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
184 adaptive_ℓ_gradv: 10.0 * F::EPSILON, // Start with something very small to estimate differentials
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
185 adaptive_max_transport: 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
186 τθ0: tconfig.θ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
187 ℓ_base,
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 ℓ_base_max_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
189 },
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 }
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 }
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 }
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
193 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
194
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
195 #[derive(Clone, Debug, Serialize)]
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
196 pub struct SingleTransport<Domain, F: Float> {
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
197 /// Source point
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
198 x: Domain,
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
199 /// Target point
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
200 y: Domain,
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
201 /// Original mass
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
202 α_μ_orig: F,
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
203 /// Transported mass
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
204 α_γ: F,
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
205 /// Helper for pruning
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
206 retain: bool,
68
00d0881f89a6 Automatic transport disabling after sufficient failures, for efficiency
Tuomo Valkonen <tuomov@iki.fi>
parents: 63
diff changeset
207 /// Fail count
00d0881f89a6 Automatic transport disabling after sufficient failures, for efficiency
Tuomo Valkonen <tuomov@iki.fi>
parents: 63
diff changeset
208 fail_count: usize,
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
209 /// Contribution to remainder (temporary variable)
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
210 excess: F,
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
211 }
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
212
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
213 #[derive(Clone, Debug, Serialize)]
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
214 pub struct Transport<Domain, F: Float> {
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
215 vec: Vec<SingleTransport<Domain, F>>,
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
216 }
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
217
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
218 /// Whether partially transported points are allowed.
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
219 ///
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
220 /// Partial transport can cause spike count explosion, so full or zero
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
221 /// transport is generally preferred. If this is set to `true`, different
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
222 /// transport adaptation heuristics will be used.
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
223 const MINIMAL_PARTIAL_TRANSPORT: bool = true;
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
224 const NEW_APPROACH: bool = true;
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
225
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
226 pub trait TransportProxPenalty<Domain, PreadjointCodomain, Reg, F = f64>:
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
227 ProxPenalty<Domain, PreadjointCodomain, Reg, F>
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
228 where
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
229 F: Float + ToNalgebraRealField,
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
230 Reg: SlidingRegTerm<Domain, F>,
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
231 Domain: Space + Clone,
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
232 {
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 type TransportStepLength;
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
234 type Dom : Set<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
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 /// Constrution of initial transport `γ1` from initial measure `μ` and `v=F'(μ)`
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 /// with step lengh τ and transport step length `θ_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
238 fn 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
239 &self,
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 γ: &mut Transport<Domain, F>,
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
241 μ: &DiscreteMeasure<Domain, F>,
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 ε: F,
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
243 τ: F,
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
244 τθ_or_adaptive: &mut Self::TransportStepLength,
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
245 v: &PreadjointCodomain,
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
246 tconfig: &TransportConfig<F>,
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
247 domain: Option<&Self::Dom>,
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
248 );
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
249
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
250 /// A posteriori transport adaptation.
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
251 fn 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
252 &self,
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
253 γ: &mut Transport<Domain, F>,
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 μ: &DiscreteMeasure<Domain, F>,
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 μ̆: &DiscreteMeasure<Domain, F>,
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
256 τv̆: &mut PreadjointCodomain,
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
257 v: &mut PreadjointCodomain,
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
258 extra: Option<F>,
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
259 ε: F,
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
260 τ: F,
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
261 τθ_or_adaptive: &Self::TransportStepLength,
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
262 reg: &Reg,
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
263 tconfig: &TransportConfig<F>,
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
264 rconfig: &RefinementSettings<F>,
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
265 attempts: &mut usize,
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
266 ) -> bool;
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
267
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
268 fn 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
269 &self,
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
270 lips: (DynResult<F>, DynResult<F>, DynResult<F>),
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 tconfig: &TransportConfig<F>,
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 ℓ_base: F,
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 ℓ_base_max_transport: F,
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 ) -> Self::TransportStepLength;
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
275 }
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
276
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 #[replace_float_literals(F::cast_from(literal))]
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 impl<F, M, Reg, const N: usize> TransportProxPenalty<Loc<N, F>, M, Reg, F> for RadonSquared
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
279 where
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
280 RadonSquared: ProxPenalty<Loc<N, F>, M, Reg, F>,
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
281 F: Float + ToNalgebraRealField,
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 M: MinMaxMapping<Loc<N, F>, F> + DifferentiableRealMapping<N, F>,
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 Reg: SlidingRegTerm<Loc<N, F>, F>,
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
284 RNDM<N, F>: SpikeMerging<F>,
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 type TransportStepLength = TransportStepLength<F>;
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
287 type Dom = Cube<N, 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
288
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 fn 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
290 &self,
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
291 (ℓ_F, maybe_ℓ_gradv, _maybe_transport_lip): (DynResult<F>, DynResult<F>, DynResult<F>),
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
292 tconfig: &TransportConfig<F>,
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
293 ℓ: F,
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
294 ℓ_base_max_transport: F,
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
295 ) -> Self::TransportStepLength {
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
296 TransportStepLength::new(
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
297 maybe_ℓ_gradv,
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
298 tconfig,
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
299 ℓ + ℓ_F.unwrap_or(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
300 ℓ_base_max_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
301 )
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
302 }
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
303
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
304 fn 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
305 &self,
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
306 γ: &mut Transport<Loc<N, F>, F>,
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
307 μ: &RNDM<N, F>,
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
308 _ε: F,
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
309 _τ: F,
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 τθ_or_adaptive: &mut TransportStepLength<F>,
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
311 v: &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
312 tconfig: &TransportConfig<F>,
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
313 domain: Option<&Cube<N, 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
314 ) {
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
315 γ.do_init_transport(v, μ, τθ_or_adaptive, tconfig, 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
316 }
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
317
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
318 fn 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
319 &self,
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 γ: &mut Transport<Loc<N, F>, F>,
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 μ: &RNDM<N, F>,
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 μ̆: &RNDM<N, F>,
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
323 τv̆: &mut 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
324 v: &mut 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
325 _extra: Option<F>,
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
326 ε: F,
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
327 τ: F,
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
328 τθ_or_adaptive: &TransportStepLength<F>,
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
329 reg: &Reg,
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
330 tconfig: &TransportConfig<F>,
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
331 _rconfig: &RefinementSettings<F>,
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
332 attempts: &mut usize,
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
333 ) -> bool {
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
334 *attempts += 1;
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
335
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
336 if *attempts > tconfig.max_attempts {
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
337 // Previous round has set transport to zero
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
338 return true;
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
339 }
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
340
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
341 let nΔ = μ.dist_matching(&μ̆);
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
342 let all_ok = γ.do_new_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
343 μ,
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
344 τ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
345 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
346 ε,
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
347 τ,
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
348 τθ_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
349 reg,
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
350 tconfig,
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
351 |_, mass_zero, negated| {
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
352 use std::cmp::Ordering::*;
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
353 match (mass_zero, negated) {
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
354 (Less, _) => -nΔ,
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
355 (Greater, _) => nΔ,
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
356 (Equal, false) => nΔ, // pessimistic estimated for ω
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
357 (Equal, true) => -nΔ, // pessimistic estimated for -ω
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
358 }
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
359 },
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
360 );
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
361
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
362 if !all_ok {
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
363 if *attempts >= tconfig.max_attempts {
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
364 for ρ in γ.iter_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
365 ρ.α_γ = 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
366 }
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
367 }
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
368 } else {
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
369 for ρ in γ.iter_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
370 if ρ.α_γ == 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
371 ρ.fail_count += 1;
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
372 } else {
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
373 ρ.fail_count = 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
374 }
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
375 }
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
376 }
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
377 all_ok
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
378 }
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
379 }
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
380
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
381 #[replace_float_literals(F::cast_from(literal))]
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
382 impl<F, M, Reg, 𝒟, O, const N: usize> TransportProxPenalty<Loc<N, F>, M, Reg, F> for 𝒟
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
383 where
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
384 F: Float + ToNalgebraRealField,
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
385 𝒟: DiscreteMeasureOp<Loc<N, F>, F>,
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
386 𝒟::Codomain: RealMapping<N, F>,
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
387 M: MinMaxMapping<Loc<N, F>, F> + DifferentiableRealMapping<N, F>,
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
388 for<'a> &'a M: std::ops::Add<𝒟::PreCodomain, Output = O>,
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
389 O: MinMaxMapping<Loc<N, F>, F>,
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
390 Reg: SlidingRegTerm<Loc<N, F>, F>,
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
391 Self: ProxPenalty<Loc<N, F>, M, Reg, F>,
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
392 RNDM<N, F>: SpikeMerging<F>,
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
393 {
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
394 type TransportStepLength = TransportStepLength<F>;
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
395 type Dom = Cube<N, 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
396
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
397 fn 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
398 &self,
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
399 (ℓ_F, maybe_ℓ_gradv, _maybe_transport_lip): (DynResult<F>, DynResult<F>, DynResult<F>),
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
400 tconfig: &TransportConfig<F>,
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
401 ℓ_base: F,
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
402 ℓ_base_max_transport: F,
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
403 ) -> Self::TransportStepLength {
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
404 TransportStepLength::new(
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
405 maybe_ℓ_gradv,
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
406 tconfig,
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
407 ℓ_base + ℓ_F.unwrap_or(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
408 ℓ_base_max_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
409 )
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
410 }
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
411
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
412 fn 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
413 &self,
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
414 γ: &mut Transport<Loc<N, F>, F>,
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
415 μ: &RNDM<N, F>,
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
416 _ε: F,
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
417 _τ: F,
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
418 τθ_or_adaptive: &mut TransportStepLength<F>,
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
419 v: &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
420 tconfig: &TransportConfig<F>,
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
421 domain: Option<&Cube<N, 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
422 ) {
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
423 γ.do_init_transport(v, μ, τθ_or_adaptive, tconfig, 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
424 }
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
425
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
426 fn 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
427 &self,
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
428 γ: &mut Transport<Loc<N, F>, F>,
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
429 μ: &RNDM<N, F>,
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
430 μ̆: &RNDM<N, F>,
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
431 τv̆: &mut 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
432 v: &mut 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
433 extra: Option<F>,
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
434 ε: F,
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
435 τ: F,
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
436 τθ_or_adaptive: &TransportStepLength<F>,
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
437 reg: &Reg,
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
438 tconfig: &TransportConfig<F>,
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
439 _rconfig: &RefinementSettings<F>,
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
440 attempts: &mut usize,
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
441 ) -> bool {
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
442 *attempts += 1;
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
443
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
444 if *attempts > tconfig.max_attempts {
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
445 // Previous round has set transport to zero
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
446 return true;
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
447 }
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
448
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
449 let all_ok = if NEW_APPROACH {
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
450 let ω = self.apply(μ.sub_matching(&μ̆));
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
451 γ.do_new_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
452 μ,
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
453 τ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
454 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
455 ε,
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
456 τ,
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
457 τθ_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
458 reg,
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
459 tconfig,
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
460 |x, _, _| ω.apply(x),
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
461 )
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
462 } else {
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
463 let mut all_ok0 = true;
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
464
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
465 // 1. If π_♯^1γ^{k+1} = γ1 has non-zero mass at some point y, but μ = μ^{k+1} does not,
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
466 // then the ansatz ∇w̃_x(y) = w^{k+1}(y) may not be satisfied. So set the mass of γ1
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
467 // at that point to zero, and retry.
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
468 for (δ, ρ) in izip!(μ.iter_spikes(), γ.iter_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
469 if δ.α == 0.0 && ρ.α_γ != 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
470 all_ok0 = false;
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
471 ρ.α_γ = 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
472 }
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
473 // TODO: sign
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
474 }
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
475
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
476 // 2. Through bounding ∫ B_ω(y, z) dλ(x, y, 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
477 // through the estimate ≤ C ‖Δ‖‖γ^{k+1}‖ for Δ := μ^{k+1}-μ̆^k
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
478 // which holds for some some C if the convolution kernel in 𝒟 has Lipschitz gradient.
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
479
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
480 let nγ = γ.norm(Radon);
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
481 let nΔ = μ.dist_matching(&μ̆) + extra.unwrap_or(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
482 let t = ε * tconfig.tolerance_mult;
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
483 if nγ * nΔ > t && *attempts >= tconfig.max_attempts {
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
484 all_ok0 = false;
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
485 } else if nγ * nΔ > t {
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
486 // Since t/(nγ*nΔ)<1, and the constant tconfig.adaptation < 1,
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
487 // this will guarantee that eventually ‖γ‖ decreases sufficiently that we
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
488 // will not enter here.
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
489 //*γ *= tconfig.adaptation * t / (nγ * nΔ);
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
490
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
491 // We want a consistent behaviour that has the potential to set many weights to zero.
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
492 // Therefore, we find the smallest uniform reduction `chg_one`, subtracted
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
493 // from all weights, that achieves total `adapt` adaptation.
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
494 let adapt_to = tconfig.adaptation * t / nΔ;
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
495 let reduction_target = nγ - adapt_to;
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
496 assert!(reduction_target > 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
497 if tconfig.allow_partial_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
498 if MINIMAL_PARTIAL_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
499 // This reduces weights of transport, starting from … until `adapt` is
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
500 // exhausted. It will, therefore, only ever cause one extrap point insertion
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
501 // at the sources, unlike “full” partial 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
502 //let refs = γ.vec.iter_mut().collect::<Vec<_>>();
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
503 //refs.sort_by(|ρ1, ρ2| ρ1.α_γ.abs().partial_cmp(&ρ2.α_γ.abs()).unwrap());
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
504 // let mut it = refs.into_iter();
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
505 //
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
506 // Maybe sort by differential norm
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
507 // let mut refs = γ
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
508 // .vec
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
509 // .iter_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
510 // .map(|ρ| {
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
511 // let val = v.differential(&ρ.x).norm2_squared();
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
512 // (ρ, val)
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
513 // })
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
514 // .collect::<Vec<_>>();
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
515 // refs.sort_by(|(_, v1), (_, v2)| v2.partial_cmp(&v1).unwrap());
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
516 // let mut it = refs.into_iter().map(|(ρ, _)| ρ);
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
517 let mut it = γ.vec.iter_mut().rev();
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
518 let _unused = it.try_fold(reduction_target, |left, ρ| {
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
519 let w = ρ.α_γ.abs();
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
520 if left <= w {
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
521 ρ.α_γ = ρ.α_γ.signum() * (w - left);
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
522 ControlFlow::Break(())
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
523 } else {
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
524 ρ.α_γ = 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
525 ControlFlow::Continue(left - w)
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
526 }
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
527 });
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
528 } else {
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
529 // This version equally reduces all weights. It causes partial transport, which
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
530 // has the problem that that we need to then adapt weights in both start and
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
531 // end points, in insert_and_reweigh, somtimes causing the number of spikes μ
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
532 // to explode.
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
533 let mut abs_weights = γ
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
534 .vec
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
535 .iter()
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
536 .map(|ρ| ρ.α_γ.abs())
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
537 .filter(|t| *t > F::EPSILON)
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
538 .collect::<Vec<F>>();
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
539 abs_weights.sort_by(|a, b| a.total_cmp(b));
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
540 let n = abs_weights.len();
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
541 // Cannot have partial transport; can cause spike count explosion
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
542 let chg = abs_weights.into_iter().zip((1..=n).rev()).try_fold(
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 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
544 |smaller_total, (w, 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
545 let mf = F::cast_from(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
546 let reduction = w * mf + smaller_total;
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
547 if reduction >= reduction_target {
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
548 ControlFlow::Break((reduction_target - smaller_total) / mf)
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
549 } else {
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
550 ControlFlow::Continue(smaller_total + w)
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
551 }
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
552 },
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
553 );
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
554 match chg {
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
555 ControlFlow::Continue(_) => γ.vec.iter_mut().for_each(|δ| δ.α_γ = 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
556 ControlFlow::Break(chg_one) => γ.vec.iter_mut().for_each(|ρ| {
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
557 let t = ρ.α_γ.abs();
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
558 if t > 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
559 if tconfig.allow_partial_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
560 let new = (t - chg_one).max(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
561 ρ.α_γ = ρ.α_γ.signum() * new;
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
562 }
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
563 }
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
564 }),
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
565 }
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
566 }
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
567 } else {
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
568 // This version zeroes smallest weights, avoiding partial 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
569 let mut abs_weights_idx = γ
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
570 .vec
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
571 .iter()
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
572 .map(|ρ| ρ.α_γ.abs())
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
573 .zip(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
574 .filter(|(w, _)| *w >= 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
575 .collect::<Vec<(F, usize)>>();
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
576 abs_weights_idx.sort_by(|(a, _), (b, _)| a.total_cmp(b));
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
577
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
578 let mut left = reduction_target;
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
579
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
580 for (w, i) in abs_weights_idx {
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
581 left -= w;
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
582 let ρ = &mut γ.vec[i];
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
583 ρ.α_γ = 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
584 if left < 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
585 break;
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
586 }
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
587 }
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
588 }
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
589
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
590 all_ok0 = false
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
591 }
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
592 all_ok0
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
593 };
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
594
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
595 if !all_ok {
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
596 if *attempts >= tconfig.max_attempts {
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
597 for ρ in γ.iter_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
598 ρ.α_γ = 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
599 }
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
600 }
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
601 } else {
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
602 for ρ in γ.iter_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
603 if ρ.α_γ == 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
604 ρ.fail_count += 1;
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
605 } else {
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
606 ρ.fail_count = 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
607 }
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
608 }
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
609 }
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
610 all_ok
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
611 }
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
612 }
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
613
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
614 #[replace_float_literals(F::cast_from(literal))]
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
615 impl<const N: usize, F: Float> Transport<Loc<N, F>, F> {
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
616 pub(crate) fn new() -> Self {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
617 Transport { vec: Vec::new() }
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
618 }
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
619
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
620 pub(crate) fn iter(&self) -> impl Iterator<Item = &'_ SingleTransport<Loc<N, F>, F>> {
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
621 self.vec.iter()
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
622 }
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
623
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
624 pub(crate) fn iter_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
625 &mut self,
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
626 ) -> impl Iterator<Item = &'_ mut SingleTransport<Loc<N, F>, F>> {
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
627 self.vec.iter_mut()
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
628 }
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
629
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
630 pub(crate) fn extend<I>(&mut self, it: I)
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
631 where
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
632 I: IntoIterator<Item = SingleTransport<Loc<N, F>, F>>,
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
633 {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
634 self.vec.extend(it)
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
635 }
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
636
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
637 pub(crate) fn len(&self) -> usize {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
638 self.vec.len()
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
639 }
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
640
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
641 // pub(crate) fn dist_matching(&self, μ: &RNDM<N, F>) -> F {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
642 // self.iter()
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
643 // .zip(μ.iter_spikes())
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
644 // .map(|(ρ, δ)| (ρ.α_γ - δ.α).abs())
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
645 // .sum()
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
646 // }
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
647
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
648 /// Construct `μ̆`, replacing the contents of `μ`.
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
649 pub(crate) fn μ̆_into(&self, μ: &mut RNDM<N, F>) {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
650 assert!(self.len() <= μ.len());
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
651
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
652 // First transported points
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
653 for (δ, ρ) in izip!(μ.iter_spikes_mut(), self.iter()) {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
654 if ρ.α_γ.abs() > 0.0 {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
655 // Transport – transported point
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
656 δ.α = ρ.α_γ;
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
657 δ.x = ρ.y;
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
658 } else {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
659 // No transport – original point
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
660 δ.α = ρ.α_μ_orig;
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
661 δ.x = ρ.x;
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
662 }
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
663 }
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
664
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
665 // Then source points with partial transport
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
666 let mut i = self.len();
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
667 // This can cause the number of points to explode, so cannot have partial 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
668 for ρ in self.iter() {
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
669 let α = ρ.α_μ_orig - ρ.α_γ;
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
670 if ρ.α_γ.abs() > F::EPSILON && α.abs() > F::EPSILON {
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
671 let δ = DeltaMeasure { α, x: ρ.x };
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
672 if i < μ.len() {
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
673 μ[i] = δ;
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
674 } else {
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
675 μ.push(δ)
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
676 }
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
677 i += 1;
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
678 }
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
679 }
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
680 μ.truncate(i);
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
681 }
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
682
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
683 /// Returns $‖μ\^k - π\_♯\^0γ\^{k+1}‖$
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
684 pub(crate) fn μ0_minus_γ0_radon(&self) -> F {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
685 self.vec.iter().map(|ρ| (ρ.α_μ_orig - ρ.α_γ).abs()).sum()
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
686 }
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
687
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
688 /// Returns $∫ c_2 d|γ|$
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
689 pub(crate) fn c2integral(&self) -> F {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
690 self.vec
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
691 .iter()
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
692 .map(|ρ| ρ.y.dist2_squared(&ρ.x) / 2.0 * ρ.α_γ.abs())
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
693 .sum()
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
694 }
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
695
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
696 pub(crate) fn get_transport_stats(&self, stats: &mut IterInfo<F>, μ: &RNDM<N, F>) {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
697 // TODO: This doesn't take into account μ[i].α becoming zero in the latest tranport
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
698 // attempt, for i < self.len(), when a corresponding source term also exists with index
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
699 // j ≥ self.len(). For now, we let that be reflected in the prune count.
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
700 stats.inserted += μ.len() - self.len();
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
701
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
702 let transp = stats.get_transport_mut();
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
703
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
704 transp.dist = {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
705 let (a, b) = transp.dist;
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
706 (a + self.c2integral(), b + self.norm(Radon))
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
707 };
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
708 transp.untransported_fraction = {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
709 let (a, b) = transp.untransported_fraction;
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
710 let source = self.iter().map(|ρ| ρ.α_μ_orig.abs()).sum();
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
711 (a + self.μ0_minus_γ0_radon(), b + source)
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
712 };
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
713 transp.transport_error = {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
714 let (a, b) = transp.transport_error;
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
715 //(a + self.dist_matching(&μ), b + self.norm(Radon))
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
716
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
717 // This ignores points that have been not transported at all, to only calculate
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
718 // destnation error; untransported_fraction accounts for not being able to transport
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
719 // at all.
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
720 self.iter()
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
721 .zip(μ.iter_spikes())
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
722 .fold((a, b), |(a, b), (ρ, δ)| {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
723 let transported = ρ.α_γ.abs();
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
724 if transported > F::EPSILON {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
725 (a + (ρ.α_γ - δ.α).abs(), b + transported)
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
726 } else {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
727 (a, b)
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
728 }
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
729 })
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
730 };
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
731 }
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
732
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
733 /// Prune spikes with zero weight. To maintain correct ordering between μ and γ, also the
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
734 /// latter needs to be pruned when μ is.
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
735 pub(crate) fn prune_compat(&mut self, μ: &mut RNDM<N, F>, stats: &mut IterInfo<F>) {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
736 assert!(self.vec.len() <= μ.len());
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
737 let old_len = μ.len();
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
738 for (ρ, δ) in self.vec.iter_mut().zip(μ.iter_spikes()) {
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
739 ρ.retain = δ.α.abs() > F::EPSILON;
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
740 }
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
741 μ.prune_by(|δ| δ.α.abs() > F::EPSILON);
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
742 stats.pruned += old_len - μ.len();
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
743 self.vec.retain(|ρ| ρ.retain);
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
744 assert!(self.vec.len() <= μ.len());
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
745 }
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
746
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
747 /// Helper for initial transport. Called from [`TransportProxPenalty::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
748 pub(super) fn do_init_transport<D>(
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
749 &mut self,
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
750 v: &D,
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
751 μ: &RNDM<N, F>,
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
752 τθ_or_adaptive: &mut TransportStepLength<F>,
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
753 tconfig: &TransportConfig<F>,
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
754 domain: Option<&Cube<N, 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
755 ) where
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
756 D: DifferentiableRealMapping<N, F>,
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
757 {
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
758 use TransportStepLength::*;
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
759
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
760 // Initialise transport structure weights
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
761 for (δ, ρ) in izip!(μ.iter_spikes(), self.iter_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
762 ρ.α_μ_orig = δ.α;
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
763 ρ.x = δ.x;
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
764 ρ.y = δ.x; // Later updated if no fails.
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
765 ρ.α_γ = if ρ.fail_count > tconfig.max_fail {
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
766 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
767 } else {
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
768 // If old transport has opposing sign, the new transport will be none.
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
769 if (ρ.α_γ > 0.0 && δ.α < 0.0) || (ρ.α_γ < 0.0 && δ.α > 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
770 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
771 } else {
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
772 δ.α
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
773 }
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
774 };
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
775 }
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
776
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
777 let γ_prev_len = self.len();
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
778 assert!(μ.len() >= γ_prev_len);
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
779 self.extend(μ[γ_prev_len..].iter().map(|δ| SingleTransport {
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
780 x: δ.x,
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
781 y: δ.x, // Just something, will be filled properly in the next phase
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
782 α_μ_orig: δ.α,
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
783 α_γ: δ.α,
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
784 retain: true,
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
785 fail_count: 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
786 excess: 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
787 }));
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
788
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
789 // Calculate transport rays.
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
790 let simple_τθ = match *τθ_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
791 Fixed { τθ, .. } => Some(τθ),
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
792 Simple { ℓ_gradv, τθ0, ℓ_base } => Some(τθ0 / (ℓ_gradv + ℓ_base)),
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
793 AdaptiveMax {
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
794 ℓ_gradv,
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
795 ref mut adaptive_max_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
796 τθ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
797 ℓ_base,
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
798 ℓ_base_max_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
799 } => {
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
800 *adaptive_max_transport = adaptive_max_transport.max(self.norm(Radon));
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
801 Some(τθ0 / (ℓ_gradv + ℓ_base + ℓ_base_max_transport * *adaptive_max_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
802 }
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
803 FullyAdaptive {
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
804 ref mut adaptive_ℓ_gradv,
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
805 ref mut adaptive_max_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
806 τθ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
807 ℓ_base,
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
808 ℓ_base_max_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
809 } => {
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
810 *adaptive_max_transport = adaptive_max_transport.max(self.norm(Radon));
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
811 let mut τθ = τθ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
812 / (*adaptive_ℓ_gradv + ℓ_base + ℓ_base_max_transport * *adaptive_max_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
813 // Do two runs through the spikes to update θ, breaking if first run did not cause
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
814 // a change.
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
815 for _i in 0..=1 {
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
816 let mut changes = false;
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
817 for ρ in self.iter_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
818 if ρ.fail_count < tconfig.max_fail {
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
819 let dv_x = v.differential(&ρ.x);
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
820 let g = &dv_x * (ρ.α_γ.signum() * τθ);
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
821 let tmp = ρ.x - g;
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
822 ρ.y = if domain.is_none_or(|d| d.contains(&tmp)) { tmp } else { ρ.x };
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
823 let n = g.norm2();
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
824 if n >= F::EPSILON {
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
825 // Estimate Lipschitz factor of ∇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
826 let this_ℓ_gradv = (dv_x - v.differential(&ρ.y)).norm2() / n;
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
827 *adaptive_ℓ_gradv = adaptive_ℓ_gradv.max(this_ℓ_gradv);
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
828 τθ = τθ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
829 / (*adaptive_ℓ_gradv
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
830 + ℓ_base
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
831 + ℓ_base_max_transport * *adaptive_max_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
832 changes = true
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
833 }
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
834 }
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
835 }
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
836 if !changes {
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
837 break;
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
838 }
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
839 }
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
840 None
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
841 }
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
842 };
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
843
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
844 if let Some(τθ) = simple_τθ {
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
845 for ρ in self.iter_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
846 if ρ.fail_count <= tconfig.max_fail {
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
847 let tmp = ρ.x - v.differential(&ρ.x) * (ρ.α_γ.signum() * τθ);
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
848 ρ.y = if domain.is_none_or(|d| d.contains(&tmp)) { tmp } else { ρ.x };
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
849 }
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
850 }
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
851 }
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
852 }
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
853
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
854 /// Helper for a posteriori transport error control.
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
855 /// Called from [`TransportProxPenalty::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
856 fn do_new_aposteriori_transport<Reg, 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
857 &mut self,
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
858 μ: &RNDM<N, F>,
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
859 τv̆: &mut 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
860 v: &mut 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
861 ε: F,
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
862 τ: F,
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
863 τθ_or_adaptive: &TransportStepLength<F>,
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
864 reg: &Reg,
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
865 tconfig: &TransportConfig<F>,
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
866 ω: impl Fn(&Loc<N, F>, std::cmp::Ordering, bool) -> F,
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
867 ) -> bool
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
868 where
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
869 Reg: SlidingRegTerm<Loc<N, F>, F>,
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
870 F: ToNalgebraRealField,
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
871 M: MinMaxMapping<Loc<N, F>, F> + DifferentiableRealMapping<N, F>,
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
872 {
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
873 let τℓ_gradv2 = τ * τθ_or_adaptive.get_ℓ_gradv() / 2.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
874 let Bounds(α_lower, α_upper) = reg.subdiff_range();
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
875
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
876 let (all_ok, m) = izip!(self.vec.iter_mut(), μ.iter_spikes()).fold(
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
877 (true, 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
878 |(all_ok_so_far, total_excess), (ρ, δ)| {
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
879 use std::cmp::Ordering::*;
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
880 // NOTE: The tolerances ε are commented out, because they will in any case
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
881 // be consumed by `t` below by suitably large choice of `tolerance_mult`.
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
882 // Hence, we simply implicitly adapt the `tolerance_mult` be commenting out
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
883 // the `ε` here. That way, `d` is in its entirely multiplied by τ, as is `t`,
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
884 // making all factors independent of τ.
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
885 let maybe_excess = match ρ.α_γ.total_cmp(&0.0) {
82
afb3ce40cff6 Ensure that transport is reset if no spike was left at endpoint after weight optimisation
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
886 // Note, the δ.α > 0 (and < 0) restriction will cause the transport to be reset,
afb3ce40cff6 Ensure that transport is reset if no spike was left at endpoint after weight optimisation
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
887 // if no spike was left at the target point after weight optimisation.
afb3ce40cff6 Ensure that transport is reset if no spike was left at endpoint after weight optimisation
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
888 Greater => (δ.α > 0.0).then(|| {
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
889 let gvx = v.differential(&ρ.x);
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
890 let d = if tconfig.alt_remainder_control {
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
891 let τv̆y = τv̆.apply(&ρ.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
892 (/*ε +*/τ * α_upper + ω(&ρ.x, ρ.α_γ.total_cmp(&ρ.α_μ_orig), false))
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
893 + (τv̆y + τ * gvx.dot(&ρ.x - &ρ.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
894 - τℓ_gradv2 * ρ.y.dist2_squared(&ρ.x)
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
895 } else {
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
896 (/*2.0 * ε*/-ω(&ρ.y, δ.α.total_cmp(&ρ.α_γ), true)
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
897 + ω(&ρ.x, ρ.α_γ.total_cmp(&ρ.α_μ_orig), false))
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
898 + τ * gvx.dot(&ρ.x - &ρ.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
899 - τℓ_gradv2 * ρ.y.dist2_squared(&ρ.x)
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
900 };
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
901 d * ρ.α_γ
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
902 }),
82
afb3ce40cff6 Ensure that transport is reset if no spike was left at endpoint after weight optimisation
Tuomo Valkonen <tuomov@iki.fi>
parents: 81
diff changeset
903 Less => (δ.α < 0.0).then(|| {
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
904 let gvx = v.differential(&ρ.x);
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
905 let d = if tconfig.alt_remainder_control {
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
906 let τv̆y = τv̆.apply(&ρ.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
907 (/*ε*/-τ * α_lower - ω(&ρ.x, ρ.α_γ.total_cmp(&ρ.α_μ_orig), true))
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
908 - (τv̆y + τ * gvx.dot(&ρ.x - &ρ.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
909 - τℓ_gradv2 * ρ.y.dist2_squared(&ρ.x)
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
910 } else {
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
911 (/*2.0 * ε +*/ω(&ρ.y, δ.α.total_cmp(&ρ.α_γ), false)
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
912 - ω(&ρ.x, ρ.α_γ.total_cmp(&ρ.α_μ_orig), true))
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
913 - τ * gvx.dot(&ρ.x - &ρ.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
914 - τℓ_gradv2 * ρ.y.dist2_squared(&ρ.x)
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
915 };
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
916 d * (-ρ.α_γ)
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
917 }),
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
918 Equal => Some(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
919 };
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
920 match maybe_excess {
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
921 None => {
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
922 ρ.α_γ = 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
923 ρ.excess = 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
924 (false, total_excess)
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
925 }
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
926 Some(e) => {
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
927 ρ.excess = e;
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
928 (all_ok_so_far, total_excess + e)
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
929 }
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
930 }
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
931 },
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
932 );
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
933
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
934 let t = τ * ε * tconfig.tolerance_mult;
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
935
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
936 if m > t {
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
937 let mut it = self.vec.iter_mut().rev().filter(|ρ| ρ.excess > 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
938 let reduction_target = m - tconfig.adaptation * t;
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
939 let _unused = it.try_fold(reduction_target, |left, ρ| {
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
940 let d = ρ.excess;
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
941 if d >= left {
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
942 if tconfig.allow_partial_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
943 ρ.α_γ *= (d - left) / d;
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
944 } else {
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
945 ρ.α_γ = 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
946 }
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
947 ControlFlow::Break(())
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
948 } else {
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
949 ρ.α_γ = 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
950 ControlFlow::Continue(left - d)
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
951 }
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
952 });
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
953 false
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
954 } else {
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
955 all_ok
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
956 }
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
957 }
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
958 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
959
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
960 impl<const N: usize, F: Float> Norm<Radon, F> for Transport<Loc<N, F>, F> {
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
961 fn norm(&self, _: Radon) -> F {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
962 self.iter().map(|ρ| ρ.α_γ.abs()).sum()
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
963 }
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
964 }
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
965
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
966 impl<const N: usize, F: Float> MulAssign<F> for Transport<Loc<N, F>, F> {
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
967 fn mul_assign(&mut self, factor: F) {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
968 for ρ in self.iter_mut() {
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
969 ρ.α_γ *= factor;
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
970 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
971 }
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
972 }
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
973
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
974 /// Iteratively solve the pointsource localisation problem using sliding forward-backward
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
975 /// splitting
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
976 ///
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
977 /// The parametrisation is as for [`pointsource_fb_reg`], except an additional domain restriction
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
978 /// may be given.
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
979 /// Inertia is currently not supported.
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
980 #[replace_float_literals(F::cast_from(literal))]
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
981 pub fn pointsource_sliding_fb_dom<F, I, Dat, Reg, Plot, P, const N: usize>(
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
982 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
983 reg: &Reg,
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
984 prox_penalty: &P,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
985 config: &SlidingFBConfig<F>,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
986 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
987 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
988 μ0: Option<RNDM<N, F>>,
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
989 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
990 ) -> DynResult<RNDM<N, F>>
37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
991 where
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
992 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
993 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
994 Dat: DifferentiableMapping<RNDM<N, F>, Codomain = F> + 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
995 Dat::DerivativeDomain:
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
996 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
997 //for<'a> Dat::Differential<'a>: Lipschitz<&'a P, FloatType = 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
998 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
999 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
1000 P: TransportProxPenalty<Loc<N, F>, Dat::DerivativeDomain, Reg, F> + StepLengthBound<F, Dat>,
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
1001 Plot: Plotter<P::ReturnMapping, Dat::DerivativeDomain, RNDM<N, F>>,
37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents: 35
diff changeset
1002 {
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1003 // 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
1004 ensure!(config.τ0 > 0.0, "Invalid step length parameter");
4f468d35fa29 General 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
1005 config.transport.check()?;
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1006
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1007 // 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
1008 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
1009 let mut γ = Transport::new();
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1010
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1011 // Set up parameters
41
b6bdb6cb4d44 Remove initial transport adaptation—it is not needed, after all
Tuomo Valkonen <tuomov@iki.fi>
parents: 39
diff changeset
1012 // let opAnorm = opA.opnorm_bound(Radon, L2);
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1013 //let max_transport = config.max_transport.scale
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1014 // * reg.radon_norm_bound(b.norm2_squared() / 2.0);
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1015 //let ℓ = opA.transport.lipschitz_factor(L2Squared) * max_transport;
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
1016 let τ = config.τ0 / prox_penalty.step_length_bound(&f)?;
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
1017
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
1018 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
1019 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
1020 &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
1021 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
1022 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
1023 );
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1024 // 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: 34
diff changeset
1025 // by τ compared to the conditional gradient approach.
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1026 let tolerance = config.insertion.tolerance * τ * reg.tolerance_scaling();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1027 let mut ε = tolerance.initial();
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1028
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1029 // 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
1030 let full_stats = |μ: &RNDM<N, F>, ε, 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
1031 value: f.apply(μ) + reg.apply(μ),
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
1032 n_spikes: μ.len(),
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1033 ε,
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1034 // postprocessing: config.insertion.postprocessing.then(|| μ.clone()),
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
1035 ..stats
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1036 };
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1037 let mut stats = IterInfo::new();
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1038
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1039 // 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
1040 for state in iterator.iter_init(|| full_stats(&μ, ε, 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
1041 let mut v = f.differential(&μ);
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
1042
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1043 // Calculate initial 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
1044 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
1045 &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
1046 &μ,
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
1047 ε,
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
1048 τ,
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
1049 &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
1050 &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
1051 &config.transport,
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1052 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
1053 );
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
1054
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
1055 let mut attempts = 0;
34
efa60bc4f743 Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 32
diff changeset
1056
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1057 // Solve finite-dimensional subproblem several times until the dual variable for the
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1058 // 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
1059 let (mut τv̆, μ̆) = 'adapt_transport: loop {
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
1060 // Set initial guess for μ=μ^{k+1}.
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
1061 γ.μ̆_into(&mut μ);
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
1062 let μ̆ = μ.clone();
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
1063
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1064 // Calculate τv̆ = τA_*(A[μ_transported + μ_transported_base]-b)
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
1065 //let residual_μ̆ = calculate_residual2(&γ1, &μ0_minus_γ0, opA, b);
61
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
1066 // TODO: this could be optimised by doing the differential like the
4f468d35fa29 General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents: 49
diff changeset
1067 // old residual2.
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
1068 // NOTE: This assumes that μ = γ1
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
1069 let mut τv̆ = f.differential(&μ̆) * τ;
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1070
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1071 // 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
1072 prox_penalty.insert_and_reweigh(
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
1073 &mut μ,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
1074 &mut τv̆,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
1075 τ,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
1076 ε,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
1077 &config.insertion,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
1078 &reg,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
1079 &state,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
1080 &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
1081 )?;
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1082
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1083 // 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
1084 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
1085 &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
1086 &μ,
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
1087 &μ̆,
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
1088 &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
1089 &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
1090 None,
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
1091 ε,
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
1092 τ,
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
1093 &τθ_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
1094 reg,
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
1095 &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
1096 &config.insertion.refinement,
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
1097 &mut attempts,
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
1098 ) {
75
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1099 break 'adapt_transport (τv̆, μ̆);
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1100 }
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
1101
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
1102 stats.get_transport_mut().readjustment_iters += 1;
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1103 };
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1104
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
1105 γ.get_transport_stats(&mut stats, &μ);
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1106
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
1107 // Merge spikes.
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
1108 // 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
1109 // 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
1110 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
1111 let m = prox_penalty.merge_spikes(
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
1112 &mut μ,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
1113 &mut τv̆,
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
1114 &μ̆,
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
1115 τ,
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
1116 ε,
78
2a122736e91c Add maximum iteration setting for scaling heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
1117 ins,
49
6b0db7251ebe Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents: 46
diff changeset
1118 &reg,
81
642141008293 Add regularisation term to merge fitness for scaling heuristic to be justified
Tuomo Valkonen <tuomov@iki.fi>
parents: 78
diff changeset
1119 Some(|μ̃: &RNDM<N, F>| f.apply(μ̃) + reg.apply(μ̃) ),
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
1120 );
75
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1121 //if m > 0 {
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1122 stats.merged += m;
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1123 //v = f.differential(&μ);
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1124 //}
78
2a122736e91c Add maximum iteration setting for scaling heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
1125 });
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1126
63
7a8a55fd41c0 Subproblem solver and sliding adjustments/improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 61
diff changeset
1127 γ.prune_compat(&mut μ, &mut stats);
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1128
75
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1129 // Do extra weight optimisation step heuristic
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1130 for _ in 1..config.insertion.extra_weight_optimisation_steps {
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1131 τv̆ = f.differential(&μ) * τ;
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1132 prox_penalty.reweigh(
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1133 &mut μ,
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1134 &mut τv̆,
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1135 τ,
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1136 ε,
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1137 &config.insertion,
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1138 &reg,
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1139 &state,
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1140 &mut stats,
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1141 )?;
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1142 }
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1143
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1144 if config.insertion.extra_weight_optimisation_steps > 0 {
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1145 γ.prune_compat(&mut μ, &mut stats);
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1146 }
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1147
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1148 let iter = state.iteration();
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1149 stats.this_iters += 1;
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1150
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1151 // Give statistics if requested
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1152 state.if_verbose(|| {
75
677a5fd1b014 Added an extra step heuristic
Tuomo Valkonen <tuomov@iki.fi>
parents: 72
diff changeset
1153 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
1154 full_stats(&μ, ε, std::mem::replace(&mut stats, IterInfo::new()))
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1155 });
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1156
35
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1157 // Update main tolerance for next iteration
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1158 ε = tolerance.update(ε, iter);
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1159 }
b087e3eab191 New version of sliding.
Tuomo Valkonen <tuomov@iki.fi>
parents: 34
diff changeset
1160
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
1161 //postprocess(μ, &config.insertion, f)
84
edb5de5d5bd6 Minor merging adjustments
Tuomo Valkonen <tuomov@iki.fi>
parents: 83
diff changeset
1162 postprocess(μ, &config.insertion, |μ̃| f.apply(μ̃) + reg.apply(μ̃))
32
56c8adc32b09 Early transport sketches
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1163 }
83
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1164
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1165 #[deprecated]
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1166 /// Version of `pointsource_sliding_fb` without domain restriction
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1167 pub fn pointsource_sliding_fb_reg<F, I, Dat, Reg, Plot, P, const N: usize>(
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1168 f: &Dat,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1169 reg: &Reg,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1170 prox_penalty: &P,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1171 config: &SlidingFBConfig<F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1172 iterator: I,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1173 plotter: Plot,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1174 μ0: Option<RNDM<N, F>>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1175 ) -> DynResult<RNDM<N, F>>
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1176 where
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1177 F: Float + ToNalgebraRealField,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1178 I: AlgIteratorFactory<IterInfo<F>>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1179 Dat: DifferentiableMapping<RNDM<N, F>, Codomain = F> + BoundedCurvature<F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1180 Dat::DerivativeDomain:
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1181 DifferentiableRealMapping<N, F> + ClosedMul<F> + MinMaxMapping<Loc<N, F>, F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1182 //for<'a> Dat::Differential<'a>: Lipschitz<&'a P, FloatType = F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1183 RNDM<N, F>: SpikeMerging<F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1184 Reg: SlidingRegTerm<Loc<N, F>, F>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1185 P: TransportProxPenalty<Loc<N, F>, Dat::DerivativeDomain, Reg, F> + StepLengthBound<F, Dat>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1186 Plot: Plotter<P::ReturnMapping, Dat::DerivativeDomain, RNDM<N, F>>,
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1187 {
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1188 pointsource_sliding_fb_dom(f, reg, prox_penalty, config, iterator, plotter, μ0, None)
66b8ac0ebe00 Sliding methods now support domain restrictions
Tuomo Valkonen <tuomov@iki.fi>
parents: 82
diff changeset
1189 }

mercurial