Mon, 17 Feb 2025 14:40:59 -0500
Added tag v2.0.0-pre for changeset b3312eee105c
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; |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
7 | use crate::fb::FBGenericConfig; |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
8 | use crate::measures::{DeltaMeasure, 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::*; |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
12 | use alg_tools::instance::Instance; |
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 | }; |
32 | 23 | use alg_tools::bisection_tree::{ |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
24 | BTSearch, Bounded, Bounds, LocalAnalysis, P2Minimise, SupportGenerator, BTFN, |
32 | 25 | }; |
26 | use alg_tools::iterate::AlgIteratorFactory; | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
27 | use alg_tools::nalgebra_support::ToNalgebraRealField; |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
28 | use nalgebra::{DMatrix, DVector}; |
32 | 29 | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
30 | use std::cmp::Ordering::{Equal, Greater, Less}; |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
31 | |
32 | 32 | /// The regularisation term $α\\|μ\\|\_{ℳ(Ω)} + δ_{≥ 0}(μ)$ for [`pointsource_fb_reg`] and other |
33 | /// algorithms. | |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
34 | /// |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
35 | /// 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
|
36 | #[derive(Copy, Clone, Debug, Serialize, Deserialize)] |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
37 | pub struct NonnegRadonRegTerm<F: Float>(pub F /* α */); |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
38 | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
39 | 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
|
40 | /// Returns the regularisation parameter |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
41 | pub fn α(&self) -> F { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
42 | let &NonnegRadonRegTerm(α) = self; |
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 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
45 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
46 | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
47 | impl<'a, F: Float, const N: usize> Mapping<RNDM<F, N>> for NonnegRadonRegTerm<F> { |
35 | 48 | type Codomain = F; |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
49 | |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
50 | fn apply<I>(&self, μ: I) -> F |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
51 | where |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
52 | I: Instance<RNDM<F, N>>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
53 | { |
35 | 54 | 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
|
55 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
56 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
57 | |
32 | 58 | /// 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
|
59 | /// |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
60 | /// 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
|
61 | #[derive(Copy, Clone, Debug, Serialize, Deserialize)] |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
62 | pub struct RadonRegTerm<F: Float>(pub F /* α */); |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
63 | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
64 | 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
|
65 | /// Returns the regularisation parameter |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
66 | pub fn α(&self) -> F { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
67 | let &RadonRegTerm(α) = self; |
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 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
70 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
71 | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
72 | impl<'a, F: Float, const N: usize> Mapping<RNDM<F, N>> for RadonRegTerm<F> { |
35 | 73 | type Codomain = F; |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
74 | |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
75 | fn apply<I>(&self, μ: I) -> F |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
76 | where |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
77 | I: Instance<RNDM<F, N>>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
78 | { |
35 | 79 | 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
|
80 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
81 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
82 | |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
83 | /// Regularisation term configuration |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
84 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
85 | pub enum Regularisation<F: Float> { |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
86 | /// $α \\|μ\\|\_{ℳ(Ω)}$ |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
87 | Radon(F), |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
88 | /// $α\\|μ\\|\_{ℳ(Ω)} + δ_{≥ 0}(μ)$ |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
89 | NonnegRadon(F), |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
90 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
91 | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
92 | impl<'a, F: Float, const N: usize> Mapping<RNDM<F, N>> for Regularisation<F> { |
35 | 93 | type Codomain = F; |
94 | ||
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
95 | fn apply<I>(&self, μ: I) -> F |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
96 | where |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
97 | I: Instance<RNDM<F, N>>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
98 | { |
24
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
99 | match *self { |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
100 | Self::Radon(α) => RadonRegTerm(α).apply(μ), |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
101 | Self::NonnegRadon(α) => NonnegRadonRegTerm(α).apply(μ), |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
102 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
103 | } |
d29d1fcf5423
Support arbitrary regularisation terms; implement non-positivity-constrained regularisation.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
104 | } |
32 | 105 | |
35 | 106 | /// Abstraction of regularisation terms. |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
107 | pub trait RegTerm<F: Float + ToNalgebraRealField, const N: usize>: |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
108 | Mapping<RNDM<F, N>, Codomain = F> |
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, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
128 | config: &FBGenericConfig<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, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
145 | config: &FBGenericConfig<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. | |
157 | fn find_tolerance_violation<G, BT>( | |
158 | &self, | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
159 | d: &mut BTFN<F, G, BT, N>, |
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, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
163 | config: &FBGenericConfig<F>, |
32 | 164 | ) -> Option<(Loc<F, N>, F, bool)> |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
165 | where |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
166 | BT: BTSearch<F, N, Agg = Bounds<F>>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
167 | G: SupportGenerator<F, N, Id = BT::Data>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
168 | G::SupportType: Mapping<Loc<F, N>, Codomain = F> + LocalAnalysis<F, Bounds<F>, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
169 | { |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
170 | 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
|
171 | } |
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 | /// Find a point where `d` may violate the tolerance `ε`. |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
174 | /// |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
175 | /// This version includes a `slack` parameter to expand the tolerances. |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
176 | /// 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
|
177 | /// |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
178 | /// 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
|
179 | /// 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
|
180 | /// regulariser. |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
181 | /// |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
182 | /// 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
|
183 | /// 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
|
184 | /// and a boolean indicating whether the found point is in bounds. |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
185 | fn find_tolerance_violation_slack<G, BT>( |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
186 | &self, |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
187 | d: &mut BTFN<F, G, BT, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
188 | τ: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
189 | ε: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
190 | skip_by_rough_check: bool, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
191 | config: &FBGenericConfig<F>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
192 | slack: F, |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
193 | ) -> Option<(Loc<F, N>, F, bool)> |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
194 | where |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
195 | BT: BTSearch<F, N, Agg = Bounds<F>>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
196 | G: SupportGenerator<F, N, Id = BT::Data>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
197 | G::SupportType: Mapping<Loc<F, N>, Codomain = F> + LocalAnalysis<F, Bounds<F>, N>; |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
198 | |
32 | 199 | /// Verify that `d` is in bounds `ε` for a merge candidate `μ` |
200 | /// | |
201 | /// `ε` is the current main tolerance and `τ` a scaling factor for the regulariser. | |
202 | fn verify_merge_candidate<G, BT>( | |
203 | &self, | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
204 | d: &mut BTFN<F, G, BT, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
205 | μ: &RNDM<F, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
206 | τ: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
207 | ε: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
208 | config: &FBGenericConfig<F>, |
32 | 209 | ) -> bool |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
210 | where |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
211 | BT: BTSearch<F, N, Agg = Bounds<F>>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
212 | G: SupportGenerator<F, N, Id = BT::Data>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
213 | G::SupportType: Mapping<Loc<F, N>, Codomain = F> + LocalAnalysis<F, Bounds<F>, N>; |
32 | 214 | |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
215 | /// Verify that `d` is in bounds `ε` for a merge candidate `μ` |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
216 | /// |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
217 | /// 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
|
218 | /// [`crate::prox_penalty::radon_squared`]. |
35 | 219 | /// The [measures][crate::measures::DiscreteMeasure] `μ` and `radon_μ` are supposed to have |
220 | /// same coordinates at same agreeing indices. | |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
221 | /// |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
222 | /// `ε` is the current main tolerance and `τ` a scaling factor for the regulariser. |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
223 | fn verify_merge_candidate_radonsq<G, BT>( |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
224 | &self, |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
225 | d: &mut BTFN<F, G, BT, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
226 | μ: &RNDM<F, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
227 | τ: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
228 | ε: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
229 | config: &FBGenericConfig<F>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
230 | radon_μ: &RNDM<F, N>, |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
231 | ) -> bool |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
232 | where |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
233 | BT: BTSearch<F, N, Agg = Bounds<F>>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
234 | G: SupportGenerator<F, N, Id = BT::Data>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
235 | G::SupportType: Mapping<Loc<F, N>, Codomain = F> + LocalAnalysis<F, Bounds<F>, N>; |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
236 | |
32 | 237 | /// TODO: document this |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
238 | fn target_bounds(&self, τ: F, ε: F) -> Option<Bounds<F>>; |
32 | 239 | |
240 | /// Returns a scaling factor for the tolerance sequence. | |
241 | /// | |
242 | /// Typically this is the regularisation parameter. | |
243 | fn tolerance_scaling(&self) -> F; | |
244 | } | |
245 | ||
246 | /// Abstraction of regularisation terms for [`pointsource_sliding_fb_reg`]. | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
247 | pub trait SlidingRegTerm<F: Float + ToNalgebraRealField, const N: usize>: RegTerm<F, N> { |
32 | 248 | /// Calculate $τ[w(z) - w(y)]$ for some w in the subdifferential of the regularisation |
249 | /// term, such that $-ε ≤ τw - d ≤ ε$. | |
250 | fn goodness<G, BT>( | |
251 | &self, | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
252 | d: &mut BTFN<F, G, BT, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
253 | μ: &RNDM<F, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
254 | y: &Loc<F, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
255 | z: &Loc<F, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
256 | τ: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
257 | ε: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
258 | config: &FBGenericConfig<F>, |
32 | 259 | ) -> F |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
260 | where |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
261 | BT: BTSearch<F, N, Agg = Bounds<F>>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
262 | G: SupportGenerator<F, N, Id = BT::Data>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
263 | G::SupportType: Mapping<Loc<F, N>, Codomain = F> + LocalAnalysis<F, Bounds<F>, N>; |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
264 | |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
265 | /// 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
|
266 | fn radon_norm_bound(&self, b: F) -> F; |
32 | 267 | } |
268 | ||
269 | #[replace_float_literals(F::cast_from(literal))] | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
270 | impl<F: Float + ToNalgebraRealField, const N: usize> RegTerm<F, N> for NonnegRadonRegTerm<F> |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
271 | where |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
272 | Cube<F, N>: P2Minimise<Loc<F, N>, F>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
273 | { |
32 | 274 | fn solve_findim( |
275 | &self, | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
276 | mA: &DMatrix<F::MixedType>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
277 | g: &DVector<F::MixedType>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
278 | τ: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
279 | x: &mut DVector<F::MixedType>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
280 | mA_normest: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
281 | ε: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
282 | config: &FBGenericConfig<F>, |
32 | 283 | ) -> usize { |
284 | let inner_tolerance = ε * config.inner.tolerance_mult; | |
285 | 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
|
286 | quadratic_nonneg(mA, g, τ * self.α(), x, mA_normest, &config.inner, inner_it) |
32 | 287 | } |
288 | ||
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
289 | fn solve_findim_l1squared( |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
290 | &self, |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
291 | y: &DVector<F::MixedType>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
292 | g: &DVector<F::MixedType>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
293 | τ: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
294 | x: &mut DVector<F::MixedType>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
295 | ε: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
296 | config: &FBGenericConfig<F>, |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
297 | ) -> usize { |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
298 | let inner_tolerance = ε * config.inner.tolerance_mult; |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
299 | 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
|
300 | 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
|
301 | } |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
302 | |
32 | 303 | #[inline] |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
304 | fn find_tolerance_violation_slack<G, BT>( |
32 | 305 | &self, |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
306 | d: &mut BTFN<F, G, BT, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
307 | τ: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
308 | ε: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
309 | skip_by_rough_check: bool, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
310 | config: &FBGenericConfig<F>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
311 | slack: F, |
32 | 312 | ) -> Option<(Loc<F, N>, F, bool)> |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
313 | where |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
314 | BT: BTSearch<F, N, Agg = Bounds<F>>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
315 | G: SupportGenerator<F, N, Id = BT::Data>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
316 | G::SupportType: Mapping<Loc<F, N>, Codomain = F> + LocalAnalysis<F, Bounds<F>, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
317 | { |
32 | 318 | let τα = τ * self.α(); |
35 | 319 | let keep_above = -τα - slack - ε; |
320 | let minimise_below = -τα - slack - ε * config.insertion_cutoff_factor; | |
32 | 321 | let refinement_tolerance = ε * config.refinement.tolerance_mult; |
322 | ||
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
323 | // If preliminary check indicates that we are in bounds, and if it otherwise matches |
32 | 324 | // the insertion strategy, skip insertion. |
35 | 325 | if skip_by_rough_check && d.bounds().lower() >= keep_above { |
32 | 326 | None |
327 | } else { | |
35 | 328 | // If the rough check didn't indicate no insertion needed, find minimising point. |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
329 | d.minimise_below( |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
330 | minimise_below, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
331 | refinement_tolerance, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
332 | config.refinement.max_steps, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
333 | ) |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
334 | .map(|(ξ, v_ξ)| (ξ, v_ξ, v_ξ >= keep_above)) |
32 | 335 | } |
336 | } | |
337 | ||
338 | fn verify_merge_candidate<G, BT>( | |
339 | &self, | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
340 | d: &mut BTFN<F, G, BT, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
341 | μ: &RNDM<F, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
342 | τ: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
343 | ε: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
344 | config: &FBGenericConfig<F>, |
32 | 345 | ) -> bool |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
346 | where |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
347 | BT: BTSearch<F, N, Agg = Bounds<F>>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
348 | G: SupportGenerator<F, N, Id = BT::Data>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
349 | G::SupportType: Mapping<Loc<F, N>, Codomain = F> + LocalAnalysis<F, Bounds<F>, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
350 | { |
32 | 351 | let τα = τ * self.α(); |
352 | let refinement_tolerance = ε * config.refinement.tolerance_mult; | |
353 | let merge_tolerance = config.merge_tolerance_mult * ε; | |
35 | 354 | let keep_above = -τα - merge_tolerance; |
355 | let keep_supp_below = -τα + merge_tolerance; | |
32 | 356 | let bnd = d.bounds(); |
357 | ||
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
358 | return (bnd.upper() <= keep_supp_below |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
359 | || μ |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
360 | .iter_spikes() |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
361 | .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
|
362 | && (bnd.lower() >= keep_above |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
363 | || d.has_lower_bound( |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
364 | keep_above, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
365 | refinement_tolerance, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
366 | config.refinement.max_steps, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
367 | )); |
32 | 368 | } |
369 | ||
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
370 | fn verify_merge_candidate_radonsq<G, BT>( |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
371 | &self, |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
372 | d: &mut BTFN<F, G, BT, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
373 | μ: &RNDM<F, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
374 | τ: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
375 | ε: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
376 | config: &FBGenericConfig<F>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
377 | radon_μ: &RNDM<F, N>, |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
378 | ) -> bool |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
379 | where |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
380 | BT: BTSearch<F, N, Agg = Bounds<F>>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
381 | G: SupportGenerator<F, N, Id = BT::Data>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
382 | G::SupportType: Mapping<Loc<F, N>, Codomain = F> + LocalAnalysis<F, Bounds<F>, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
383 | { |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
384 | let τα = τ * self.α(); |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
385 | let refinement_tolerance = ε * config.refinement.tolerance_mult; |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
386 | let merge_tolerance = config.merge_tolerance_mult * ε; |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
387 | let slack = radon_μ.norm(Radon); |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
388 | let bnd = d.bounds(); |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
389 | |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
390 | return { |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
391 | μ.both_matching(radon_μ).all(|(α, rα, x)| { |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
392 | let v = -d.apply(x); // TODO: observe ad hoc negation here, after minus_τv |
35 | 393 | // switch to τv. |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
394 | 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
|
395 | Greater => (τα, τα), |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
396 | _ => (F::NEG_INFINITY, τα), |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
397 | // Less should not happen; treated as Equal |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
398 | }; |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
399 | 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
|
400 | Greater => (slack, slack), |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
401 | Equal => (-slack, slack), |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
402 | Less => (-slack, -slack), |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
403 | }; |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
404 | // TODO: both fail. |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
405 | (l1 + l2 - merge_tolerance <= v) && (v <= u1 + u2 + merge_tolerance) |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
406 | }) |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
407 | } && { |
35 | 408 | let keep_above = -τα - slack - merge_tolerance; |
409 | bnd.lower() <= keep_above | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
410 | || d.has_lower_bound( |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
411 | keep_above, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
412 | refinement_tolerance, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
413 | config.refinement.max_steps, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
414 | ) |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
415 | }; |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
416 | } |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
417 | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
418 | fn target_bounds(&self, τ: F, ε: F) -> Option<Bounds<F>> { |
32 | 419 | let τα = τ * self.α(); |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
420 | Some(Bounds(τα - ε, τα + ε)) |
32 | 421 | } |
422 | ||
423 | fn tolerance_scaling(&self) -> F { | |
424 | self.α() | |
425 | } | |
426 | } | |
427 | ||
428 | #[replace_float_literals(F::cast_from(literal))] | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
429 | impl<F: Float + ToNalgebraRealField, const N: usize> SlidingRegTerm<F, N> for NonnegRadonRegTerm<F> |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
430 | where |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
431 | Cube<F, N>: P2Minimise<Loc<F, N>, F>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
432 | { |
32 | 433 | fn goodness<G, BT>( |
434 | &self, | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
435 | d: &mut BTFN<F, G, BT, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
436 | _μ: &RNDM<F, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
437 | y: &Loc<F, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
438 | z: &Loc<F, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
439 | τ: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
440 | ε: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
441 | _config: &FBGenericConfig<F>, |
32 | 442 | ) -> F |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
443 | where |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
444 | BT: BTSearch<F, N, Agg = Bounds<F>>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
445 | G: SupportGenerator<F, N, Id = BT::Data>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
446 | G::SupportType: Mapping<Loc<F, N>, Codomain = F> + LocalAnalysis<F, Bounds<F>, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
447 | { |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
448 | 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
|
449 | w(z) - w(y) |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
450 | } |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
451 | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
452 | fn radon_norm_bound(&self, b: F) -> F { |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
453 | b / self.α() |
32 | 454 | } |
455 | } | |
456 | ||
457 | #[replace_float_literals(F::cast_from(literal))] | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
458 | impl<F: Float + ToNalgebraRealField, const N: usize> RegTerm<F, N> for RadonRegTerm<F> |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
459 | where |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
460 | Cube<F, N>: P2Minimise<Loc<F, N>, F>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
461 | { |
32 | 462 | fn solve_findim( |
463 | &self, | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
464 | mA: &DMatrix<F::MixedType>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
465 | g: &DVector<F::MixedType>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
466 | τ: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
467 | x: &mut DVector<F::MixedType>, |
32 | 468 | mA_normest: F, |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
469 | ε: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
470 | config: &FBGenericConfig<F>, |
32 | 471 | ) -> usize { |
472 | let inner_tolerance = ε * config.inner.tolerance_mult; | |
473 | 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
|
474 | quadratic_unconstrained(mA, g, τ * self.α(), x, mA_normest, &config.inner, inner_it) |
32 | 475 | } |
476 | ||
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
477 | fn solve_findim_l1squared( |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
478 | &self, |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
479 | y: &DVector<F::MixedType>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
480 | g: &DVector<F::MixedType>, |
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 | x: &mut DVector<F::MixedType>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
483 | ε: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
484 | config: &FBGenericConfig<F>, |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
485 | ) -> usize { |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
486 | let inner_tolerance = ε * config.inner.tolerance_mult; |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
487 | 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
|
488 | 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
|
489 | } |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
490 | |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
491 | fn find_tolerance_violation_slack<G, BT>( |
32 | 492 | &self, |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
493 | d: &mut BTFN<F, G, BT, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
494 | τ: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
495 | ε: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
496 | skip_by_rough_check: bool, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
497 | config: &FBGenericConfig<F>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
498 | slack: F, |
32 | 499 | ) -> Option<(Loc<F, N>, F, bool)> |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
500 | where |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
501 | BT: BTSearch<F, N, Agg = Bounds<F>>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
502 | G: SupportGenerator<F, N, Id = BT::Data>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
503 | G::SupportType: Mapping<Loc<F, N>, Codomain = F> + LocalAnalysis<F, Bounds<F>, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
504 | { |
32 | 505 | let τα = τ * self.α(); |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
506 | let keep_below = τα + slack + ε; |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
507 | let keep_above = -(τα + slack) - ε; |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
508 | let maximise_above = τα + slack + ε * config.insertion_cutoff_factor; |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
509 | let minimise_below = -(τα + slack) - ε * config.insertion_cutoff_factor; |
32 | 510 | let refinement_tolerance = ε * config.refinement.tolerance_mult; |
511 | ||
512 | // If preliminary check indicates that we are in bonds, and if it otherwise matches | |
513 | // the insertion strategy, skip insertion. | |
514 | if skip_by_rough_check && Bounds(keep_above, keep_below).superset(&d.bounds()) { | |
515 | None | |
516 | } else { | |
517 | // 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
|
518 | let mx = d.maximise_above( |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
519 | maximise_above, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
520 | refinement_tolerance, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
521 | config.refinement.max_steps, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
522 | ); |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
523 | let mi = d.minimise_below( |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
524 | minimise_below, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
525 | refinement_tolerance, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
526 | config.refinement.max_steps, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
527 | ); |
32 | 528 | |
529 | match (mx, mi) { | |
530 | (None, None) => None, | |
531 | (Some((ξ, v_ξ)), None) => Some((ξ, v_ξ, keep_below >= v_ξ)), | |
532 | (None, Some((ζ, v_ζ))) => Some((ζ, v_ζ, keep_above <= v_ζ)), | |
533 | (Some((ξ, v_ξ)), Some((ζ, v_ζ))) => { | |
534 | if v_ξ - τα > τα - v_ζ { | |
535 | Some((ξ, v_ξ, keep_below >= v_ξ)) | |
536 | } else { | |
537 | Some((ζ, v_ζ, keep_above <= v_ζ)) | |
538 | } | |
539 | } | |
540 | } | |
541 | } | |
542 | } | |
543 | ||
544 | fn verify_merge_candidate<G, BT>( | |
545 | &self, | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
546 | d: &mut BTFN<F, G, BT, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
547 | μ: &RNDM<F, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
548 | τ: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
549 | ε: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
550 | config: &FBGenericConfig<F>, |
32 | 551 | ) -> bool |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
552 | where |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
553 | BT: BTSearch<F, N, Agg = Bounds<F>>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
554 | G: SupportGenerator<F, N, Id = BT::Data>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
555 | G::SupportType: Mapping<Loc<F, N>, Codomain = F> + LocalAnalysis<F, Bounds<F>, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
556 | { |
32 | 557 | let τα = τ * self.α(); |
558 | let refinement_tolerance = ε * config.refinement.tolerance_mult; | |
559 | let merge_tolerance = config.merge_tolerance_mult * ε; | |
560 | let keep_below = τα + merge_tolerance; | |
561 | let keep_above = -τα - merge_tolerance; | |
562 | let keep_supp_pos_above = τα - merge_tolerance; | |
563 | let keep_supp_neg_below = -τα + merge_tolerance; | |
564 | let bnd = d.bounds(); | |
565 | ||
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
566 | 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
|
567 | || μ |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
568 | .iter_spikes() |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
569 | .all(|&DeltaMeasure { α: β, ref x }| match β.partial_cmp(&0.0) { |
32 | 570 | Some(Greater) => d.apply(x) >= keep_supp_pos_above, |
571 | Some(Less) => d.apply(x) <= keep_supp_neg_below, | |
572 | _ => true, | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
573 | })) |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
574 | && (bnd.upper() <= keep_below |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
575 | || d.has_upper_bound( |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
576 | keep_below, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
577 | refinement_tolerance, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
578 | config.refinement.max_steps, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
579 | )) |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
580 | && (bnd.lower() >= keep_above |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
581 | || d.has_lower_bound( |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
582 | keep_above, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
583 | refinement_tolerance, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
584 | config.refinement.max_steps, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
585 | )); |
32 | 586 | } |
587 | ||
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
588 | fn verify_merge_candidate_radonsq<G, BT>( |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
589 | &self, |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
590 | d: &mut BTFN<F, G, BT, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
591 | μ: &RNDM<F, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
592 | τ: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
593 | ε: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
594 | config: &FBGenericConfig<F>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
595 | radon_μ: &RNDM<F, N>, |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
596 | ) -> bool |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
597 | where |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
598 | BT: BTSearch<F, N, Agg = Bounds<F>>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
599 | G: SupportGenerator<F, N, Id = BT::Data>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
600 | G::SupportType: Mapping<Loc<F, N>, Codomain = F> + LocalAnalysis<F, Bounds<F>, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
601 | { |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
602 | let τα = τ * self.α(); |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
603 | let refinement_tolerance = ε * config.refinement.tolerance_mult; |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
604 | let merge_tolerance = config.merge_tolerance_mult * ε; |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
605 | let slack = radon_μ.norm(Radon); |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
606 | let bnd = d.bounds(); |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
607 | |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
608 | return { |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
609 | μ.both_matching(radon_μ).all(|(α, rα, x)| { |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
610 | let v = d.apply(x); |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
611 | 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
|
612 | Greater => (τα, τα), |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
613 | Equal => (-τα, τα), |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
614 | Less => (-τα, -τα), |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
615 | }; |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
616 | 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
|
617 | Greater => (slack, slack), |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
618 | Equal => (-slack, slack), |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
619 | Less => (-slack, -slack), |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
620 | }; |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
621 | (l1 + l2 - merge_tolerance <= v) && (v <= u1 + u2 + merge_tolerance) |
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 | } && { |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
624 | let keep_below = τα + slack + merge_tolerance; |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
625 | bnd.upper() <= keep_below |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
626 | || d.has_upper_bound( |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
627 | keep_below, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
628 | refinement_tolerance, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
629 | config.refinement.max_steps, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
630 | ) |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
631 | } && { |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
632 | let keep_above = -τα - slack - merge_tolerance; |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
633 | bnd.lower() >= keep_above |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
634 | || d.has_lower_bound( |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
635 | keep_above, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
636 | refinement_tolerance, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
637 | config.refinement.max_steps, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
638 | ) |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
639 | }; |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
640 | } |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
641 | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
642 | fn target_bounds(&self, τ: F, ε: F) -> Option<Bounds<F>> { |
32 | 643 | let τα = τ * self.α(); |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
644 | Some(Bounds(-τα - ε, τα + ε)) |
32 | 645 | } |
646 | ||
647 | fn tolerance_scaling(&self) -> F { | |
648 | self.α() | |
649 | } | |
650 | } | |
651 | ||
652 | #[replace_float_literals(F::cast_from(literal))] | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
653 | impl<F: Float + ToNalgebraRealField, const N: usize> SlidingRegTerm<F, N> for RadonRegTerm<F> |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
654 | where |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
655 | Cube<F, N>: P2Minimise<Loc<F, N>, F>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
656 | { |
32 | 657 | fn goodness<G, BT>( |
658 | &self, | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
659 | d: &mut BTFN<F, G, BT, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
660 | _μ: &RNDM<F, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
661 | y: &Loc<F, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
662 | z: &Loc<F, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
663 | τ: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
664 | ε: F, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
665 | _config: &FBGenericConfig<F>, |
32 | 666 | ) -> F |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
667 | where |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
668 | BT: BTSearch<F, N, Agg = Bounds<F>>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
669 | G: SupportGenerator<F, N, Id = BT::Data>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
670 | G::SupportType: Mapping<Loc<F, N>, Codomain = F> + LocalAnalysis<F, Bounds<F>, N>, |
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
671 | { |
32 | 672 | let α = self.α(); |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
673 | let w = |x| { |
32 | 674 | let dx = d.apply(x); |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
675 | ((-ε + dx) / (τ * α)).max(1.0.min(ε + dx) / (τ * α)) |
32 | 676 | }; |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
677 | w(z) - w(y) |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
678 | } |
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
679 | |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
680 | fn radon_norm_bound(&self, b: F) -> F { |
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
681 | b / self.α() |
32 | 682 | } |
51
0693cc9ba9f0
Update documentation references
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
683 | } |