Fri, 16 Jan 2026 19:39:22 -0500
Lipschitz estimation attempt (incomplete, not implemented for sliding. Doesn't work anyway for basic FB either.)
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
1 | /*! |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
2 | Regularisation terms |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
3 | */ |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
4 | |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
5 | #[allow(unused_imports)] // Used by documentation. |
| 32 | 6 | use crate::fb::pointsource_fb_reg; |
|
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:
51
diff
changeset
|
7 | use crate::fb::InsertionConfig; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
8 | use crate::measures::{DeltaMeasure, DiscreteMeasure, Radon, RNDM}; |
| 32 | 9 | #[allow(unused_imports)] // Used by documentation. |
| 10 | use crate::sliding_fb::pointsource_sliding_fb_reg; | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
11 | use crate::types::*; |
|
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:
51
diff
changeset
|
12 | use alg_tools::instance::{Instance, Space}; |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
13 | use alg_tools::linops::Mapping; |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
14 | use alg_tools::loc::Loc; |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
15 | use alg_tools::norms::Norm; |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
16 | use numeric_literals::replace_float_literals; |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
17 | use serde::{Deserialize, Serialize}; |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
18 | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
19 | use crate::subproblem::{ |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
20 | l1squared_nonneg::l1squared_nonneg, l1squared_unconstrained::l1squared_unconstrained, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
21 | nonneg::quadratic_nonneg, unconstrained::quadratic_unconstrained, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
22 | }; |
|
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:
51
diff
changeset
|
23 | use alg_tools::bounds::{Bounds, MinMaxMapping}; |
| 32 | 24 | use alg_tools::iterate::AlgIteratorFactory; |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
25 | use alg_tools::nalgebra_support::ToNalgebraRealField; |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
26 | use nalgebra::{DMatrix, DVector}; |
| 32 | 27 | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
28 | use std::cmp::Ordering::{Equal, Greater, Less}; |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
29 | |
| 32 | 30 | /// The regularisation term $α\\|μ\\|\_{ℳ(Ω)} + δ_{≥ 0}(μ)$ for [`pointsource_fb_reg`] and other |
| 31 | /// algorithms. | |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
32 | /// |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
33 | /// The only member of the struct is the regularisation parameter α. |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
34 | #[derive(Copy, Clone, Debug, Serialize, Deserialize)] |
|
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:
51
diff
changeset
|
35 | pub struct NonnegRadonRegTerm<F: Float = f64>(pub F /* α */); |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
36 | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
37 | impl<'a, F: Float> NonnegRadonRegTerm<F> { |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
38 | /// Returns the regularisation parameter |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
39 | pub fn α(&self) -> F { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
40 | let &NonnegRadonRegTerm(α) = self; |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
41 | α |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
42 | } |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
43 | } |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
44 | |
|
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:
51
diff
changeset
|
45 | impl<'a, F: Float, const N: usize> Mapping<RNDM<N, F>> for NonnegRadonRegTerm<F> { |
| 35 | 46 | type Codomain = F; |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
47 | |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
48 | fn apply<I>(&self, μ: I) -> F |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
49 | where |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
50 | I: Instance<RNDM<N, F>>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
51 | { |
| 35 | 52 | self.α() * μ.eval(|x| x.norm(Radon)) |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
53 | } |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
54 | } |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
55 | |
| 32 | 56 | /// The regularisation term $α\|μ\|_{ℳ(Ω)}$ for [`pointsource_fb_reg`]. |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
57 | /// |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
58 | /// The only member of the struct is the regularisation parameter α. |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
59 | #[derive(Copy, Clone, Debug, Serialize, Deserialize)] |
|
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:
51
diff
changeset
|
60 | pub struct RadonRegTerm<F: Float = f64>(pub F /* α */); |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
61 | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
62 | impl<'a, F: Float> RadonRegTerm<F> { |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
63 | /// Returns the regularisation parameter |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
64 | pub fn α(&self) -> F { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
65 | let &RadonRegTerm(α) = self; |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
66 | α |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
67 | } |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
68 | } |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
69 | |
|
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:
51
diff
changeset
|
70 | impl<'a, F: Float, const N: usize> Mapping<RNDM<N, F>> for RadonRegTerm<F> { |
| 35 | 71 | type Codomain = F; |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
72 | |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
73 | fn apply<I>(&self, μ: I) -> F |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
74 | where |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
75 | I: Instance<RNDM<N, F>>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
76 | { |
| 35 | 77 | self.α() * μ.eval(|x| x.norm(Radon)) |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
78 | } |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
79 | } |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
80 | |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
81 | /// Regularisation term configuration |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
82 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] |
|
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:
51
diff
changeset
|
83 | pub enum Regularisation<F: Float = f64> { |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
84 | /// $α \\|μ\\|\_{ℳ(Ω)}$ |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
85 | Radon(F), |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
86 | /// $α\\|μ\\|\_{ℳ(Ω)} + δ_{≥ 0}(μ)$ |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
87 | NonnegRadon(F), |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
88 | } |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
89 | |
|
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:
51
diff
changeset
|
90 | impl<'a, F: Float, const N: usize> Mapping<RNDM<N, F>> for Regularisation<F> { |
| 35 | 91 | type Codomain = F; |
| 92 | ||
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
93 | fn apply<I>(&self, μ: I) -> F |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
94 | where |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
95 | I: Instance<RNDM<N, F>>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
96 | { |
|
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
97 | match *self { |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
98 | Self::Radon(α) => RadonRegTerm(α).apply(μ), |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
99 | Self::NonnegRadon(α) => NonnegRadonRegTerm(α).apply(μ), |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
100 | } |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
101 | } |
|
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
102 | } |
| 32 | 103 | |
| 35 | 104 | /// Abstraction of regularisation terms. |
|
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:
51
diff
changeset
|
105 | pub trait RegTerm<Domain, F = f64>: Mapping<DiscreteMeasure<Domain, F>, Codomain = F> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
106 | where |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
107 | Domain: Space + Clone, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
108 | F: Float + ToNalgebraRealField, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
109 | { |
| 32 | 110 | /// Approximately solve the problem |
| 111 | /// <div>$$ | |
| 112 | /// \min_{x ∈ ℝ^n} \frac{1}{2} x^⊤Ax - g^⊤ x + τ G(x) | |
| 113 | /// $$</div> | |
| 114 | /// for $G$ depending on the trait implementation. | |
| 115 | /// | |
| 116 | /// The parameter `mA` is $A$. An estimate for its opeator norm should be provided in | |
| 117 | /// `mA_normest`. The initial iterate and output is `x`. The current main tolerance is `ε`. | |
| 118 | /// | |
| 119 | /// Returns the number of iterations taken. | |
| 120 | fn solve_findim( | |
| 121 | &self, | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
122 | mA: &DMatrix<F::MixedType>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
123 | g: &DVector<F::MixedType>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
124 | τ: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
125 | x: &mut DVector<F::MixedType>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
126 | mA_normest: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
127 | ε: 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:
51
diff
changeset
|
128 | config: &InsertionConfig<F>, |
| 32 | 129 | ) -> usize; |
| 130 | ||
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
131 | /// Approximately solve the problem |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
132 | /// <div>$$ |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
133 | /// \min_{x ∈ ℝ^n} \frac{1}{2} |x-y|_1^2 - g^⊤ x + τ G(x) |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
134 | /// $$</div> |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
135 | /// for $G$ depending on the trait implementation. |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
136 | /// |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
137 | /// Returns the number of iterations taken. |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
138 | fn solve_findim_l1squared( |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
139 | &self, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
140 | y: &DVector<F::MixedType>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
141 | g: &DVector<F::MixedType>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
142 | τ: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
143 | x: &mut DVector<F::MixedType>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
144 | ε: 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:
51
diff
changeset
|
145 | config: &InsertionConfig<F>, |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
146 | ) -> usize; |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
147 | |
| 32 | 148 | /// Find a point where `d` may violate the tolerance `ε`. |
| 149 | /// | |
| 150 | /// If `skip_by_rough_check` is set, do not find the point if a rough check indicates that we | |
| 151 | /// are in bounds. `ε` is the current main tolerance and `τ` a scaling factor for the | |
| 152 | /// regulariser. | |
| 153 | /// | |
| 154 | /// Returns `None` if `d` is in bounds either based on the rough check, or a more precise check | |
| 155 | /// terminating early. Otherwise returns a possibly violating point, the value of `d` there, | |
| 156 | /// and a boolean indicating whether the found point is in bounds. | |
|
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:
51
diff
changeset
|
157 | fn find_tolerance_violation<M>( |
| 32 | 158 | &self, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
159 | d: &mut M, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
160 | τ: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
161 | ε: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
162 | skip_by_rough_check: bool, |
|
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:
51
diff
changeset
|
163 | config: &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:
51
diff
changeset
|
164 | ) -> Option<(Domain, F, bool)> |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
165 | where |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
166 | M: MinMaxMapping<Domain, F>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
167 | { |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
168 | self.find_tolerance_violation_slack(d, τ, ε, skip_by_rough_check, config, F::ZERO) |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
169 | } |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
170 | |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
171 | /// Find a point where `d` may violate the tolerance `ε`. |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
172 | /// |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
173 | /// This version includes a `slack` parameter to expand the tolerances. |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
174 | /// It is used for Radon-norm squared proximal term in [`crate::prox_penalty::radon_squared`]. |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
175 | /// |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
176 | /// If `skip_by_rough_check` is set, do not find the point if a rough check indicates that we |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
177 | /// are in bounds. `ε` is the current main tolerance and `τ` a scaling factor for the |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
178 | /// regulariser. |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
179 | /// |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
180 | /// Returns `None` if `d` is in bounds either based on the rough check, or a more precise check |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
181 | /// terminating early. Otherwise returns a possibly violating point, the value of `d` there, |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
182 | /// and a boolean indicating whether the found point is in bounds. |
|
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:
51
diff
changeset
|
183 | fn find_tolerance_violation_slack<M>( |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
184 | &self, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
185 | d: &mut M, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
186 | τ: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
187 | ε: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
188 | skip_by_rough_check: bool, |
|
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:
51
diff
changeset
|
189 | config: &InsertionConfig<F>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
190 | slack: 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:
51
diff
changeset
|
191 | ) -> Option<(Domain, F, bool)> |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
192 | where |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
193 | M: MinMaxMapping<Domain, F>; |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
194 | |
| 32 | 195 | /// Verify that `d` is in bounds `ε` for a merge candidate `μ` |
| 196 | /// | |
| 197 | /// `ε` is the current main tolerance and `τ` a scaling factor for the regulariser. | |
|
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:
51
diff
changeset
|
198 | fn verify_merge_candidate<M>( |
| 32 | 199 | &self, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
200 | d: &mut M, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
201 | μ: &DiscreteMeasure<Domain, F>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
202 | τ: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
203 | ε: 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:
51
diff
changeset
|
204 | config: &InsertionConfig<F>, |
| 32 | 205 | ) -> bool |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
206 | where |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
207 | M: MinMaxMapping<Domain, F>; |
| 32 | 208 | |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
209 | /// Verify that `d` is in bounds `ε` for a merge candidate `μ` |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
210 | /// |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
211 | /// This version is s used for Radon-norm squared proximal term in |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
212 | /// [`crate::prox_penalty::radon_squared`]. |
| 35 | 213 | /// The [measures][crate::measures::DiscreteMeasure] `μ` and `radon_μ` are supposed to have |
| 214 | /// same coordinates at same agreeing indices. | |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
215 | /// |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
216 | /// `ε` is the current main tolerance and `τ` a scaling factor for the regulariser. |
|
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:
51
diff
changeset
|
217 | fn verify_merge_candidate_radonsq<M>( |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
218 | &self, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
219 | d: &mut M, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
220 | μ: &DiscreteMeasure<Domain, F>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
221 | τ: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
222 | ε: 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:
51
diff
changeset
|
223 | config: &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:
51
diff
changeset
|
224 | radon_μ: &DiscreteMeasure<Domain, F>, |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
225 | ) -> bool |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
226 | where |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
227 | M: MinMaxMapping<Domain, F>; |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
228 | |
| 32 | 229 | /// TODO: document this |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
230 | fn target_bounds(&self, τ: F, ε: F) -> Option<Bounds<F>>; |
| 32 | 231 | |
| 232 | /// Returns a scaling factor for the tolerance sequence. | |
| 233 | /// | |
| 234 | /// Typically this is the regularisation parameter. | |
| 235 | fn tolerance_scaling(&self) -> F; | |
| 236 | } | |
| 237 | ||
| 238 | /// Abstraction of regularisation terms for [`pointsource_sliding_fb_reg`]. | |
|
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:
51
diff
changeset
|
239 | pub trait SlidingRegTerm<Domain, F = f64>: RegTerm<Domain, 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:
51
diff
changeset
|
240 | where |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
241 | Domain: Space + Clone, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
242 | F: Float + ToNalgebraRealField, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
243 | { |
| 32 | 244 | /// Calculate $τ[w(z) - w(y)]$ for some w in the subdifferential of the regularisation |
| 245 | /// term, such that $-ε ≤ τw - d ≤ ε$. | |
|
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:
51
diff
changeset
|
246 | fn goodness<M>( |
| 32 | 247 | &self, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
248 | d: &mut M, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
249 | μ: &DiscreteMeasure<Domain, 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:
51
diff
changeset
|
250 | y: &Domain, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
251 | z: &Domain, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
252 | τ: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
253 | ε: 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:
51
diff
changeset
|
254 | config: &InsertionConfig<F>, |
| 32 | 255 | ) -> F |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
256 | where |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
257 | M: MinMaxMapping<Domain, F>; |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
258 | |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
259 | /// Convert bound on the regulariser to a bond on the Radon norm |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
260 | fn radon_norm_bound(&self, b: F) -> F; |
| 32 | 261 | } |
| 262 | ||
| 263 | #[replace_float_literals(F::cast_from(literal))] | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
264 | impl<F: Float + ToNalgebraRealField, const N: usize> RegTerm<Loc<N, F>, F> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
265 | for NonnegRadonRegTerm<F> |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
266 | { |
| 32 | 267 | fn solve_findim( |
| 268 | &self, | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
269 | mA: &DMatrix<F::MixedType>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
270 | g: &DVector<F::MixedType>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
271 | τ: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
272 | x: &mut DVector<F::MixedType>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
273 | mA_normest: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
274 | ε: 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:
51
diff
changeset
|
275 | config: &InsertionConfig<F>, |
| 32 | 276 | ) -> usize { |
| 277 | let inner_tolerance = ε * config.inner.tolerance_mult; | |
| 278 | let inner_it = config.inner.iterator_options.stop_target(inner_tolerance); | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
279 | quadratic_nonneg(mA, g, τ * self.α(), x, mA_normest, &config.inner, inner_it) |
| 32 | 280 | } |
| 281 | ||
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
282 | fn solve_findim_l1squared( |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
283 | &self, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
284 | y: &DVector<F::MixedType>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
285 | g: &DVector<F::MixedType>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
286 | τ: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
287 | x: &mut DVector<F::MixedType>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
288 | ε: 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:
51
diff
changeset
|
289 | config: &InsertionConfig<F>, |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
290 | ) -> usize { |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
291 | let inner_tolerance = ε * config.inner.tolerance_mult; |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
292 | let inner_it = config.inner.iterator_options.stop_target(inner_tolerance); |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
293 | l1squared_nonneg(y, g, τ * self.α(), 1.0, x, &config.inner, inner_it) |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
294 | } |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
295 | |
| 32 | 296 | #[inline] |
|
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:
51
diff
changeset
|
297 | fn find_tolerance_violation_slack<M>( |
| 32 | 298 | &self, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
299 | d: &mut M, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
300 | τ: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
301 | ε: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
302 | skip_by_rough_check: bool, |
|
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:
51
diff
changeset
|
303 | config: &InsertionConfig<F>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
304 | slack: 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:
51
diff
changeset
|
305 | ) -> Option<(Loc<N, F>, F, bool)> |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
306 | where |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
307 | M: MinMaxMapping<Loc<N, F>, F>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
308 | { |
| 32 | 309 | let τα = τ * self.α(); |
| 35 | 310 | let keep_above = -τα - slack - ε; |
| 311 | let minimise_below = -τα - slack - ε * config.insertion_cutoff_factor; | |
| 32 | 312 | let refinement_tolerance = ε * config.refinement.tolerance_mult; |
| 313 | ||
|
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:
51
diff
changeset
|
314 | // println!( |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
315 | // "keep_above: {keep_above}, rough lower bound: {}, tolerance: {ε}, slack: {slack}, τα: {τα}", |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
316 | // d.bounds().lower() |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
317 | // ); |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
318 | |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
319 | // If preliminary check indicates that we are in bounds, and if it otherwise matches |
| 32 | 320 | // the insertion strategy, skip insertion. |
| 35 | 321 | if skip_by_rough_check && d.bounds().lower() >= keep_above { |
| 32 | 322 | None |
| 323 | } else { | |
| 35 | 324 | // If the rough check didn't indicate no insertion needed, find minimising point. |
|
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:
51
diff
changeset
|
325 | let res = d.minimise_below( |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
326 | minimise_below, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
327 | refinement_tolerance, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
328 | config.refinement.max_steps, |
|
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:
51
diff
changeset
|
329 | ); |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
330 | |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
331 | res.map(|(ξ, v_ξ)| (ξ, v_ξ, v_ξ >= keep_above)) |
| 32 | 332 | } |
| 333 | } | |
| 334 | ||
|
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:
51
diff
changeset
|
335 | fn verify_merge_candidate<M>( |
| 32 | 336 | &self, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
337 | d: &mut M, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
338 | μ: &RNDM<N, F>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
339 | τ: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
340 | ε: 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:
51
diff
changeset
|
341 | config: &InsertionConfig<F>, |
| 32 | 342 | ) -> bool |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
343 | where |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
344 | M: MinMaxMapping<Loc<N, F>, F>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
345 | { |
| 32 | 346 | let τα = τ * self.α(); |
| 347 | let refinement_tolerance = ε * config.refinement.tolerance_mult; | |
| 348 | let merge_tolerance = config.merge_tolerance_mult * ε; | |
| 35 | 349 | let keep_above = -τα - merge_tolerance; |
| 350 | let keep_supp_below = -τα + merge_tolerance; | |
| 32 | 351 | let bnd = d.bounds(); |
| 352 | ||
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
353 | return (bnd.upper() <= keep_supp_below |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
354 | || μ |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
355 | .iter_spikes() |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
356 | .all(|&DeltaMeasure { α, ref x }| (α == 0.0) || d.apply(x) <= keep_supp_below)) |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
357 | && (bnd.lower() >= keep_above |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
358 | || d.has_lower_bound( |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
359 | keep_above, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
360 | refinement_tolerance, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
361 | config.refinement.max_steps, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
362 | )); |
| 32 | 363 | } |
| 364 | ||
|
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:
51
diff
changeset
|
365 | fn verify_merge_candidate_radonsq<M>( |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
366 | &self, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
367 | d: &mut M, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
368 | μ: &RNDM<N, F>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
369 | τ: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
370 | ε: 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:
51
diff
changeset
|
371 | config: &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:
51
diff
changeset
|
372 | radon_μ: &RNDM<N, F>, |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
373 | ) -> bool |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
374 | where |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
375 | M: MinMaxMapping<Loc<N, F>, F>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
376 | { |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
377 | let τα = τ * self.α(); |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
378 | let refinement_tolerance = ε * config.refinement.tolerance_mult; |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
379 | let merge_tolerance = config.merge_tolerance_mult * ε; |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
380 | let slack = radon_μ.norm(Radon); |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
381 | let bnd = d.bounds(); |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
382 | |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
383 | return { |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
384 | μ.both_matching(radon_μ).all(|(α, rα, x)| { |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
385 | let v = -d.apply(x); // TODO: observe ad hoc negation here, after minus_τv |
| 35 | 386 | // switch to τv. |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
387 | let (l1, u1) = match α.partial_cmp(&0.0).unwrap_or(Equal) { |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
388 | Greater => (τα, τα), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
389 | _ => (F::NEG_INFINITY, τα), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
390 | // Less should not happen; treated as Equal |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
391 | }; |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
392 | let (l2, u2) = match rα.partial_cmp(&0.0).unwrap_or(Equal) { |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
393 | Greater => (slack, slack), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
394 | Equal => (-slack, slack), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
395 | Less => (-slack, -slack), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
396 | }; |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
397 | // TODO: both fail. |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
398 | (l1 + l2 - merge_tolerance <= v) && (v <= u1 + u2 + merge_tolerance) |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
399 | }) |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
400 | } && { |
| 35 | 401 | let keep_above = -τα - slack - merge_tolerance; |
| 402 | bnd.lower() <= keep_above | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
403 | || d.has_lower_bound( |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
404 | keep_above, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
405 | refinement_tolerance, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
406 | config.refinement.max_steps, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
407 | ) |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
408 | }; |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
409 | } |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
410 | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
411 | fn target_bounds(&self, τ: F, ε: F) -> Option<Bounds<F>> { |
| 32 | 412 | let τα = τ * self.α(); |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
413 | Some(Bounds(τα - ε, τα + ε)) |
| 32 | 414 | } |
| 415 | ||
| 416 | fn tolerance_scaling(&self) -> F { | |
| 417 | self.α() | |
| 418 | } | |
| 419 | } | |
| 420 | ||
| 421 | #[replace_float_literals(F::cast_from(literal))] | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
422 | impl<F: Float + ToNalgebraRealField, const N: usize> SlidingRegTerm<Loc<N, F>, F> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
423 | for NonnegRadonRegTerm<F> |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
424 | { |
|
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:
51
diff
changeset
|
425 | fn goodness<M>( |
| 32 | 426 | &self, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
427 | d: &mut M, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
428 | _μ: &RNDM<N, F>, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
429 | y: &Loc<N, F>, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
430 | z: &Loc<N, F>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
431 | τ: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
432 | ε: 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:
51
diff
changeset
|
433 | _config: &InsertionConfig<F>, |
| 32 | 434 | ) -> F |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
435 | where |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
436 | M: MinMaxMapping<Loc<N, F>, F>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
437 | { |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
438 | let w = |x| 1.0.min((ε + d.apply(x)) / (τ * self.α())); |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
439 | w(z) - w(y) |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
440 | } |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
441 | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
442 | fn radon_norm_bound(&self, b: F) -> F { |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
443 | b / self.α() |
| 32 | 444 | } |
| 445 | } | |
| 446 | ||
| 447 | #[replace_float_literals(F::cast_from(literal))] | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
448 | impl<F: Float + ToNalgebraRealField, const N: usize> RegTerm<Loc<N, F>, F> for RadonRegTerm<F> { |
| 32 | 449 | fn solve_findim( |
| 450 | &self, | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
451 | mA: &DMatrix<F::MixedType>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
452 | g: &DVector<F::MixedType>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
453 | τ: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
454 | x: &mut DVector<F::MixedType>, |
| 32 | 455 | mA_normest: F, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
456 | ε: 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:
51
diff
changeset
|
457 | config: &InsertionConfig<F>, |
| 32 | 458 | ) -> usize { |
| 459 | let inner_tolerance = ε * config.inner.tolerance_mult; | |
| 460 | let inner_it = config.inner.iterator_options.stop_target(inner_tolerance); | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
461 | quadratic_unconstrained(mA, g, τ * self.α(), x, mA_normest, &config.inner, inner_it) |
| 32 | 462 | } |
| 463 | ||
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
464 | fn solve_findim_l1squared( |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
465 | &self, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
466 | y: &DVector<F::MixedType>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
467 | g: &DVector<F::MixedType>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
468 | τ: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
469 | x: &mut DVector<F::MixedType>, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
470 | ε: 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:
51
diff
changeset
|
471 | config: &InsertionConfig<F>, |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
472 | ) -> usize { |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
473 | let inner_tolerance = ε * config.inner.tolerance_mult; |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
474 | let inner_it = config.inner.iterator_options.stop_target(inner_tolerance); |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
475 | l1squared_unconstrained(y, g, τ * self.α(), 1.0, x, &config.inner, inner_it) |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
476 | } |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
477 | |
|
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:
51
diff
changeset
|
478 | fn find_tolerance_violation_slack<M>( |
| 32 | 479 | &self, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
480 | d: &mut M, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
481 | τ: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
482 | ε: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
483 | skip_by_rough_check: bool, |
|
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:
51
diff
changeset
|
484 | config: &InsertionConfig<F>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
485 | slack: 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:
51
diff
changeset
|
486 | ) -> Option<(Loc<N, F>, F, bool)> |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
487 | where |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
488 | M: MinMaxMapping<Loc<N, F>, F>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
489 | { |
| 32 | 490 | let τα = τ * self.α(); |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
491 | let keep_below = τα + slack + ε; |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
492 | let keep_above = -(τα + slack) - ε; |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
493 | let maximise_above = τα + slack + ε * config.insertion_cutoff_factor; |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
494 | let minimise_below = -(τα + slack) - ε * config.insertion_cutoff_factor; |
| 32 | 495 | let refinement_tolerance = ε * config.refinement.tolerance_mult; |
| 496 | ||
| 497 | // If preliminary check indicates that we are in bonds, and if it otherwise matches | |
| 498 | // the insertion strategy, skip insertion. | |
| 499 | if skip_by_rough_check && Bounds(keep_above, keep_below).superset(&d.bounds()) { | |
| 500 | None | |
| 501 | } else { | |
| 502 | // If the rough check didn't indicate no insertion needed, find maximising point. | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
503 | let mx = d.maximise_above( |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
504 | maximise_above, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
505 | refinement_tolerance, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
506 | config.refinement.max_steps, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
507 | ); |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
508 | let mi = d.minimise_below( |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
509 | minimise_below, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
510 | refinement_tolerance, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
511 | config.refinement.max_steps, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
512 | ); |
| 32 | 513 | |
| 514 | match (mx, mi) { | |
| 515 | (None, None) => None, | |
| 516 | (Some((ξ, v_ξ)), None) => Some((ξ, v_ξ, keep_below >= v_ξ)), | |
| 517 | (None, Some((ζ, v_ζ))) => Some((ζ, v_ζ, keep_above <= v_ζ)), | |
| 518 | (Some((ξ, v_ξ)), Some((ζ, v_ζ))) => { | |
| 519 | if v_ξ - τα > τα - v_ζ { | |
| 520 | Some((ξ, v_ξ, keep_below >= v_ξ)) | |
| 521 | } else { | |
| 522 | Some((ζ, v_ζ, keep_above <= v_ζ)) | |
| 523 | } | |
| 524 | } | |
| 525 | } | |
| 526 | } | |
| 527 | } | |
| 528 | ||
|
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:
51
diff
changeset
|
529 | fn verify_merge_candidate<M>( |
| 32 | 530 | &self, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
531 | d: &mut M, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
532 | μ: &RNDM<N, F>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
533 | τ: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
534 | ε: 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:
51
diff
changeset
|
535 | config: &InsertionConfig<F>, |
| 32 | 536 | ) -> bool |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
537 | where |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
538 | M: MinMaxMapping<Loc<N, F>, F>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
539 | { |
| 32 | 540 | let τα = τ * self.α(); |
| 541 | let refinement_tolerance = ε * config.refinement.tolerance_mult; | |
| 542 | let merge_tolerance = config.merge_tolerance_mult * ε; | |
| 543 | let keep_below = τα + merge_tolerance; | |
| 544 | let keep_above = -τα - merge_tolerance; | |
| 545 | let keep_supp_pos_above = τα - merge_tolerance; | |
| 546 | let keep_supp_neg_below = -τα + merge_tolerance; | |
| 547 | let bnd = d.bounds(); | |
| 548 | ||
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
549 | return ((bnd.lower() >= keep_supp_pos_above && bnd.upper() <= keep_supp_neg_below) |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
550 | || μ |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
551 | .iter_spikes() |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
552 | .all(|&DeltaMeasure { α: β, ref x }| match β.partial_cmp(&0.0) { |
| 32 | 553 | Some(Greater) => d.apply(x) >= keep_supp_pos_above, |
| 554 | Some(Less) => d.apply(x) <= keep_supp_neg_below, | |
| 555 | _ => true, | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
556 | })) |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
557 | && (bnd.upper() <= keep_below |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
558 | || d.has_upper_bound( |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
559 | keep_below, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
560 | refinement_tolerance, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
561 | config.refinement.max_steps, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
562 | )) |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
563 | && (bnd.lower() >= keep_above |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
564 | || d.has_lower_bound( |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
565 | keep_above, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
566 | refinement_tolerance, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
567 | config.refinement.max_steps, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
568 | )); |
| 32 | 569 | } |
| 570 | ||
|
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:
51
diff
changeset
|
571 | fn verify_merge_candidate_radonsq<M>( |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
572 | &self, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
573 | d: &mut M, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
574 | μ: &RNDM<N, F>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
575 | τ: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
576 | ε: 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:
51
diff
changeset
|
577 | config: &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:
51
diff
changeset
|
578 | radon_μ: &RNDM<N, F>, |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
579 | ) -> bool |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
580 | where |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
581 | M: MinMaxMapping<Loc<N, F>, F>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
582 | { |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
583 | let τα = τ * self.α(); |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
584 | let refinement_tolerance = ε * config.refinement.tolerance_mult; |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
585 | let merge_tolerance = config.merge_tolerance_mult * ε; |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
586 | let slack = radon_μ.norm(Radon); |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
587 | let bnd = d.bounds(); |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
588 | |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
589 | return { |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
590 | μ.both_matching(radon_μ).all(|(α, rα, x)| { |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
591 | let v = d.apply(x); |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
592 | let (l1, u1) = match α.partial_cmp(&0.0).unwrap_or(Equal) { |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
593 | Greater => (τα, τα), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
594 | Equal => (-τα, τα), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
595 | Less => (-τα, -τα), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
596 | }; |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
597 | let (l2, u2) = match rα.partial_cmp(&0.0).unwrap_or(Equal) { |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
598 | Greater => (slack, slack), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
599 | Equal => (-slack, slack), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
600 | Less => (-slack, -slack), |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
601 | }; |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
602 | (l1 + l2 - merge_tolerance <= v) && (v <= u1 + u2 + merge_tolerance) |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
603 | }) |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
604 | } && { |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
605 | let keep_below = τα + slack + merge_tolerance; |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
606 | bnd.upper() <= keep_below |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
607 | || d.has_upper_bound( |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
608 | keep_below, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
609 | refinement_tolerance, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
610 | config.refinement.max_steps, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
611 | ) |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
612 | } && { |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
613 | let keep_above = -τα - slack - merge_tolerance; |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
614 | bnd.lower() >= keep_above |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
615 | || d.has_lower_bound( |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
616 | keep_above, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
617 | refinement_tolerance, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
618 | config.refinement.max_steps, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
619 | ) |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
620 | }; |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
621 | } |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
622 | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
623 | fn target_bounds(&self, τ: F, ε: F) -> Option<Bounds<F>> { |
| 32 | 624 | let τα = τ * self.α(); |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
625 | Some(Bounds(-τα - ε, τα + ε)) |
| 32 | 626 | } |
| 627 | ||
| 628 | fn tolerance_scaling(&self) -> F { | |
| 629 | self.α() | |
| 630 | } | |
| 631 | } | |
| 632 | ||
| 633 | #[replace_float_literals(F::cast_from(literal))] | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
634 | impl<F: Float + ToNalgebraRealField, const N: usize> SlidingRegTerm<Loc<N, F>, F> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
635 | for RadonRegTerm<F> |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
636 | { |
|
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:
51
diff
changeset
|
637 | fn goodness<M>( |
| 32 | 638 | &self, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
639 | d: &mut M, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
640 | _μ: &RNDM<N, F>, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
641 | y: &Loc<N, F>, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
642 | z: &Loc<N, F>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
643 | τ: F, |
|
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
644 | ε: 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:
51
diff
changeset
|
645 | _config: &InsertionConfig<F>, |
| 32 | 646 | ) -> F |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
647 | where |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
51
diff
changeset
|
648 | M: MinMaxMapping<Loc<N, F>, F>, |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
649 | { |
| 32 | 650 | let α = self.α(); |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
651 | let w = |x| { |
| 32 | 652 | let dx = d.apply(x); |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
653 | ((-ε + dx) / (τ * α)).max(1.0.min(ε + dx) / (τ * α)) |
| 32 | 654 | }; |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
655 | w(z) - w(y) |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
656 | } |
|
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
657 | |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
658 | fn radon_norm_bound(&self, b: F) -> F { |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
659 | b / self.α() |
| 32 | 660 | } |
|
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
661 | } |