Sun, 19 Jul 2026 07:30:06 +0200
Added an extra step heuristic
| 0 | 1 | //! Implementation of the convolution of two hat functions, |
| 2 | //! and its convolution with a [`CubeIndicator`]. | |
|
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:
35
diff
changeset
|
3 | |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
4 | use alg_tools::bisection_tree::{Constant, Support}; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
5 | use alg_tools::bounds::{Bounded, Bounds, GlobalAnalysis, LocalAnalysis}; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
6 | use alg_tools::error::DynResult; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
7 | use alg_tools::loc::Loc; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
8 | use alg_tools::mapping::{DifferentiableImpl, Instance, LipschitzDifferentiableImpl, Mapping}; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
9 | use alg_tools::maputil::array_init; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
10 | use alg_tools::norms::*; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
11 | use alg_tools::sets::Cube; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
12 | use alg_tools::types::*; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
13 | use anyhow::anyhow; |
| 0 | 14 | use numeric_literals::replace_float_literals; |
| 15 | use serde::Serialize; | |
| 16 | ||
|
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:
35
diff
changeset
|
17 | use super::ball_indicator::CubeIndicator; |
| 0 | 18 | use super::base::*; |
|
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:
35
diff
changeset
|
19 | use crate::types::Lipschitz; |
| 0 | 20 | |
| 21 | /// Hat convolution kernel. | |
| 22 | /// | |
| 23 | /// This struct represents the function | |
| 24 | /// $$ | |
| 25 | /// f(x\_1, …, x\_n) = \prod\_{i=1}^n \frac{4}{σ} (h\*h)(x\_i/σ) | |
| 26 | /// $$ | |
| 27 | /// where the “hat function” $h(y)= \max(0, 1 - |2y|)$. | |
| 28 | /// The factor $4/σ$ normalises $∫ f d x = 1$. | |
| 29 | /// We have | |
| 30 | /// $$ | |
| 31 | /// (h*h)(y) = | |
| 32 | /// \begin{cases} | |
| 33 | /// \frac{2}{3} (y+1)^3 & -1<y\leq -\frac{1}{2}, \\\\ | |
| 34 | /// -2 y^3-2 y^2+\frac{1}{3} & -\frac{1}{2}<y\leq 0, \\\\ | |
| 35 | /// 2 y^3-2 y^2+\frac{1}{3} & 0<y<\frac{1}{2}, \\\\ | |
| 36 | /// -\frac{2}{3} (y-1)^3 & \frac{1}{2}\leq y<1. \\\\ | |
| 37 | /// \end{cases} | |
| 38 | /// $$ | |
| 35 | 39 | // Hence |
| 40 | // $$ | |
| 41 | // (h\*h)'(y) = | |
| 42 | // \begin{cases} | |
| 43 | // 2 (y+1)^2 & -1<y\leq -\frac{1}{2}, \\\\ | |
| 44 | // -6 y^2-4 y & -\frac{1}{2}<y\leq 0, \\\\ | |
| 45 | // 6 y^2-4 y & 0<y<\frac{1}{2}, \\\\ | |
| 46 | // -2 (y-1)^2 & \frac{1}{2}\leq y<1. \\\\ | |
| 47 | // \end{cases} | |
| 48 | // $$ | |
| 49 | // as well as | |
| 50 | // $$ | |
| 51 | // (h\*h)''(y) = | |
| 52 | // \begin{cases} | |
| 53 | // 4 (y+1) & -1<y\leq -\frac{1}{2}, \\\\ | |
| 54 | // -12 y-4 & -\frac{1}{2}<y\leq 0, \\\\ | |
| 55 | // 12 y-4 & 0<y<\frac{1}{2}, \\\\ | |
| 56 | // -4 (y-1) & \frac{1}{2}\leq y<1. \\\\ | |
| 57 | // \end{cases} | |
| 58 | // $$ | |
| 59 | // This is maximised at y=±1/2 with value 2, and minimised at y=0 with value -4. | |
| 60 | // Now observe that | |
| 61 | // $$ | |
| 62 | // [∇f(x\_1, …, x\_n)]_j = \frac{4}{σ} (h\*h)'(x\_j/σ) \prod\_{j ≠ i} \frac{4}{σ} (h\*h)(x\_i/σ) | |
| 63 | // $$ | |
|
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:
35
diff
changeset
|
64 | #[derive(Copy, Clone, Debug, Serialize, Eq)] |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
65 | pub struct HatConv<S: Constant, const N: usize> { |
| 0 | 66 | /// The parameter $σ$ of the kernel. |
|
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:
35
diff
changeset
|
67 | pub radius: S, |
| 0 | 68 | } |
| 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:
35
diff
changeset
|
70 | impl<S1, S2, const N: usize> PartialEq<HatConv<S2, N>> for HatConv<S1, N> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
71 | 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:
35
diff
changeset
|
72 | S1: Constant, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
73 | S2: Constant<Type = S1::Type>, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
74 | { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
75 | fn eq(&self, other: &HatConv<S2, N>) -> bool { |
| 0 | 76 | self.radius.value() == other.radius.value() |
| 77 | } | |
| 78 | } | |
| 79 | ||
|
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:
35
diff
changeset
|
80 | impl<'a, S, const N: usize> HatConv<S, N> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
81 | 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:
35
diff
changeset
|
82 | S: Constant, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
83 | { |
| 0 | 84 | /// Returns the $σ$ parameter of the kernel. |
| 85 | #[inline] | |
| 86 | pub fn radius(&self) -> S::Type { | |
| 87 | self.radius.value() | |
| 88 | } | |
| 89 | } | |
| 90 | ||
|
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:
35
diff
changeset
|
91 | impl<'a, S, const N: usize> Mapping<Loc<N, S::Type>> for HatConv<S, N> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
92 | 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:
35
diff
changeset
|
93 | S: Constant, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
94 | { |
| 35 | 95 | type Codomain = S::Type; |
| 96 | ||
| 0 | 97 | #[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:
35
diff
changeset
|
98 | fn apply<I: Instance<Loc<N, S::Type>>>(&self, y: I) -> Self::Codomain { |
| 0 | 99 | let σ = self.radius(); |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
100 | y.decompose().product_map(|x| self.value_1d_σ1(x / σ)) / σ.powi(N as i32) |
| 0 | 101 | } |
| 102 | } | |
| 103 | ||
| 32 | 104 | #[replace_float_literals(S::Type::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:
35
diff
changeset
|
105 | impl<S, const N: usize> Lipschitz<L2> for HatConv<S, N> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
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:
35
diff
changeset
|
107 | S: Constant, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
108 | { |
| 32 | 109 | type FloatType = S::Type; |
| 110 | #[inline] | |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
111 | fn lipschitz_factor(&self, _L2: L2) -> DynResult<Self::FloatType> { |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
112 | // For arbitrary ψ(x) = ∏_{i=1}^n ψ_i(x_i), we have |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
113 | // ψ(x) - ψ(y) = ∑_i [ψ_i(x_i)-ψ_i(y_i)] ∏_{j < i} ψ_j(y_j) ∏_{j > i} ψ_j(x_j) |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
114 | // by a simple recursive argument. In particular, if ψ_i=g for all i, j, we have |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
115 | // |ψ(x) - ψ(y)| ≤ ∑_i L_g|x_i-y_i| M_g^{n-1} ≤ √n L_g M_g^{n-1} |x-y|₂ |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
116 | // where L_g is the Lipschitz factor of g, and M_g a bound on it. |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
117 | let σ = self.radius(); |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
118 | let l1d = self.lipschitz_1d_σ1(); |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
119 | let m1d = self.value_1d_σ1(0.0); |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
120 | Ok( |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
121 | S::Type::cast_from(N).sqrt() * l1d * m1d.powi((N - 1) as i32) |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
122 | / σ.powi((N - 1 + 2) as i32), |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
123 | ) |
| 32 | 124 | } |
| 125 | } | |
| 126 | ||
|
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:
35
diff
changeset
|
127 | impl<'a, S, const N: usize> DifferentiableImpl<Loc<N, S::Type>> for HatConv<S, N> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
128 | 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:
35
diff
changeset
|
129 | S: Constant, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
130 | { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
131 | type Derivative = Loc<N, S::Type>; |
| 35 | 132 | |
| 32 | 133 | #[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:
35
diff
changeset
|
134 | fn differential_impl<I: Instance<Loc<N, S::Type>>>(&self, y0: I) -> Self::Derivative { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
135 | let y = y0.decompose(); |
| 32 | 136 | let σ = self.radius(); |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
137 | let tmp = y.map(|x| x / σ); |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
138 | let vs = tmp.map(|x| self.value_1d_σ1(x)); |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
139 | product_differential(&tmp, &vs, |x| self.diff_1d_σ1(x)) / σ.powi((N + 1) as i32) |
| 32 | 140 | } |
| 141 | } | |
| 142 | ||
| 35 | 143 | #[replace_float_literals(S::Type::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:
35
diff
changeset
|
144 | impl<'a, F: Float, S, const N: usize> LipschitzDifferentiableImpl<Loc<N, S::Type>, L2> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
145 | for HatConv<S, N> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
146 | 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:
35
diff
changeset
|
147 | S: Constant<Type = 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:
35
diff
changeset
|
148 | { |
| 35 | 149 | type FloatType = F; |
| 150 | ||
| 32 | 151 | #[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:
35
diff
changeset
|
152 | fn diff_lipschitz_factor(&self, _l2: L2) -> DynResult<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:
35
diff
changeset
|
153 | let σ = self.radius(); |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
154 | product_differential_lipschitz_factor::<F, N>( |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
155 | self.value_1d_σ1(0.0), |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
156 | self.lipschitz_1d_σ1(), |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
157 | self.maxabsdiff_1d_σ1(), |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
158 | self.lipschitz_diff_1d_σ1(), |
|
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:
35
diff
changeset
|
159 | ) |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
160 | .map(|l| l / σ.powi((N + 2) as i32)) |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
161 | // We have f(x)=f₀(x/σ)/σ^N, where f₀(z)=∏_{i=1}^N f₁(z_i). |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
162 | // Thus |f'(x)-f'(y)| = |f₀'(x/σ)-f₀'(y/σ)|/σ^{N+1} ≤ L_{f₀'}/σ^{N+2}. |
| 32 | 163 | } |
| 164 | } | |
| 0 | 165 | |
| 166 | #[replace_float_literals(S::Type::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:
35
diff
changeset
|
167 | impl<'a, F: Float, S, const N: usize> HatConv<S, N> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
168 | 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:
35
diff
changeset
|
169 | S: Constant<Type = 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:
35
diff
changeset
|
170 | { |
| 0 | 171 | /// Computes the value of the kernel for $n=1$ with $σ=1$. |
| 172 | #[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:
35
diff
changeset
|
173 | fn value_1d_σ1(&self, x: F) -> F { |
| 0 | 174 | let y = x.abs(); |
| 175 | if y >= 1.0 { | |
| 176 | 0.0 | |
| 177 | } else if y > 0.5 { | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
178 | -(8.0 / 3.0) * (y - 1.0).powi(3) |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
179 | } else |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
180 | /* 0 ≤ y ≤ 0.5 */ |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
181 | { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
182 | (4.0 / 3.0) + 8.0 * y * y * (y - 1.0) |
| 0 | 183 | } |
| 184 | } | |
| 32 | 185 | |
| 186 | /// Computes the differential of the kernel for $n=1$ with $σ=1$. | |
| 187 | #[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:
35
diff
changeset
|
188 | fn diff_1d_σ1(&self, x: F) -> F { |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
189 | if x >= 1.0 || x <= -1.0 { |
| 32 | 190 | 0.0 |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
191 | } else if x > 0.5 { |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
192 | -8.0 * (x - 1.0).powi(2) |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
193 | } else if x < -0.5 { |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
194 | 8.0 * (x + 1.0).powi(2) |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
195 | } else { |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
196 | /* 0 ≤ y ≤ 0.5 */ |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
197 | (24.0 * x.abs() - 16.0) * x |
| 32 | 198 | } |
| 199 | } | |
| 200 | ||
| 201 | /// Computes the Lipschitz factor of the kernel for $n=1$ with $σ=1$. | |
| 202 | #[inline] | |
| 203 | fn lipschitz_1d_σ1(&self) -> F { | |
| 204 | // Maximal absolute differential achieved at ±0.5 by diff_1d_σ1 analysis | |
| 205 | 2.0 | |
| 206 | } | |
| 35 | 207 | |
| 208 | /// Computes the maximum absolute differential of the kernel for $n=1$ with $σ=1$. | |
| 209 | #[inline] | |
| 210 | fn maxabsdiff_1d_σ1(&self) -> F { | |
| 211 | // Maximal absolute differential achieved at ±0.5 by diff_1d_σ1 analysis | |
| 212 | 2.0 | |
| 213 | } | |
| 214 | ||
| 215 | /// Computes the differential of the kernel for $n=1$ with $σ=1$. | |
| 216 | #[inline] | |
| 217 | fn lipschitz_diff_1d_σ1(&self) -> F { | |
| 218 | // Maximal absolute second differential achieved at 0 by diff2_1d_σ1 analysis | |
| 219 | 16.0 | |
| 220 | } | |
| 0 | 221 | } |
| 222 | ||
|
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:
35
diff
changeset
|
223 | impl<'a, S, const N: usize> Support<N, S::Type> for HatConv<S, N> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
224 | 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:
35
diff
changeset
|
225 | S: Constant, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
226 | { |
| 0 | 227 | #[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:
35
diff
changeset
|
228 | fn support_hint(&self) -> Cube<N, S::Type> { |
| 0 | 229 | let σ = self.radius(); |
| 230 | array_init(|| [-σ, σ]).into() | |
| 231 | } | |
| 232 | ||
| 233 | #[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:
35
diff
changeset
|
234 | fn in_support(&self, y: &Loc<N, S::Type>) -> bool { |
| 0 | 235 | let σ = self.radius(); |
| 236 | y.iter().all(|x| x.abs() <= σ) | |
| 237 | } | |
| 238 | ||
| 239 | #[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:
35
diff
changeset
|
240 | fn bisection_hint(&self, cube: &Cube<N, S::Type>) -> [Option<S::Type>; N] { |
| 0 | 241 | let σ = self.radius(); |
| 242 | cube.map(|c, d| symmetric_peak_hint(σ, c, d)) | |
| 243 | } | |
| 244 | } | |
| 245 | ||
| 246 | #[replace_float_literals(S::Type::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:
35
diff
changeset
|
247 | impl<S, const N: usize> GlobalAnalysis<S::Type, Bounds<S::Type>> for HatConv<S, N> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
248 | 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:
35
diff
changeset
|
249 | S: Constant, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
250 | { |
| 0 | 251 | #[inline] |
| 252 | fn global_analysis(&self) -> Bounds<S::Type> { | |
| 253 | Bounds(0.0, self.apply(Loc::ORIGIN)) | |
| 254 | } | |
| 255 | } | |
| 256 | ||
|
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:
35
diff
changeset
|
257 | impl<S, const N: usize> LocalAnalysis<S::Type, Bounds<S::Type>, N> for HatConv<S, N> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
258 | 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:
35
diff
changeset
|
259 | S: Constant, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
260 | { |
| 0 | 261 | #[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:
35
diff
changeset
|
262 | fn local_analysis(&self, cube: &Cube<N, S::Type>) -> Bounds<S::Type> { |
| 0 | 263 | // The function is maximised/minimised where the 2-norm is minimised/maximised. |
| 264 | let lower = self.apply(cube.maxnorm_point()); | |
| 265 | let upper = self.apply(cube.minnorm_point()); | |
| 266 | Bounds(lower, upper) | |
| 267 | } | |
| 268 | } | |
| 269 | ||
| 270 | #[replace_float_literals(C::Type::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:
35
diff
changeset
|
271 | impl<'a, C: Constant, const N: usize> Norm<L1, C::Type> for HatConv<C, N> { |
| 0 | 272 | #[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:
35
diff
changeset
|
273 | fn norm(&self, _: L1) -> C::Type { |
| 0 | 274 | 1.0 |
| 275 | } | |
| 276 | } | |
| 277 | ||
| 278 | #[replace_float_literals(C::Type::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:
35
diff
changeset
|
279 | impl<'a, C: Constant, const N: usize> Norm<Linfinity, C::Type> for HatConv<C, N> { |
| 0 | 280 | #[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:
35
diff
changeset
|
281 | fn norm(&self, _: Linfinity) -> C::Type { |
| 0 | 282 | self.bounds().upper() |
| 283 | } | |
| 284 | } | |
| 285 | ||
| 286 | #[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:
35
diff
changeset
|
287 | impl<'a, F: Float, R, C, const N: usize> Mapping<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:
35
diff
changeset
|
288 | for Convolution<CubeIndicator<R, N>, HatConv<C, N>> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
289 | 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:
35
diff
changeset
|
290 | R: Constant<Type = 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:
35
diff
changeset
|
291 | C: Constant<Type = 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:
35
diff
changeset
|
292 | { |
| 35 | 293 | type Codomain = F; |
| 0 | 294 | |
| 295 | #[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:
35
diff
changeset
|
296 | fn apply<I: Instance<Loc<N, F>>>(&self, y: I) -> F { |
| 0 | 297 | let Convolution(ref ind, ref hatconv) = self; |
| 298 | let β = ind.r.value(); | |
| 299 | let σ = hatconv.radius(); | |
| 300 | ||
| 301 | // This is just a product of one-dimensional versions | |
|
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:
35
diff
changeset
|
302 | y.decompose().product_map(|x| { |
| 0 | 303 | // With $u_σ(x) = u_1(x/σ)/σ$ the normalised hat convolution |
| 304 | // we have | |
| 305 | // $$ | |
| 306 | // [χ_{-β,β} * u_σ](x) | |
| 307 | // = ∫_{x-β}^{x+β} u_σ(z) d z | |
| 308 | // = (1/σ)∫_{x-β}^{x+β} u_1(z/σ) d z | |
| 309 | // = ∫_{(x-β)/σ}^{(x+β)/σ} u_1(z) d z | |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
310 | // = (χ_{[-β/σ, β/σ]} * u_1)(x/σ) |
| 0 | 311 | // $$ |
| 312 | self.value_1d_σ1(x / σ, β / σ) | |
| 313 | }) | |
| 314 | } | |
| 315 | } | |
| 316 | ||
| 35 | 317 | #[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:
35
diff
changeset
|
318 | impl<'a, F: Float, R, C, const N: usize> DifferentiableImpl<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:
35
diff
changeset
|
319 | for Convolution<CubeIndicator<R, N>, HatConv<C, N>> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
320 | 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:
35
diff
changeset
|
321 | R: Constant<Type = 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:
35
diff
changeset
|
322 | C: Constant<Type = 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:
35
diff
changeset
|
323 | { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
324 | type Derivative = Loc<N, F>; |
| 0 | 325 | |
| 326 | #[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:
35
diff
changeset
|
327 | fn differential_impl<I: Instance<Loc<N, F>>>(&self, y0: I) -> 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:
35
diff
changeset
|
328 | let y = y0.decompose(); |
| 32 | 329 | let Convolution(ref ind, ref hatconv) = self; |
| 330 | let β = ind.r.value(); | |
| 331 | let σ = hatconv.radius(); | |
| 332 | ||
|
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:
35
diff
changeset
|
333 | let vs = y.map(|x| self.value_1d_σ1(x / σ, β / σ)); |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
334 | product_differential(&*y, &vs, |x| self.diff_1d_σ1(x / σ, β / σ)) / σ |
| 32 | 335 | } |
| 336 | } | |
| 337 | ||
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
338 | /// Integrate $f'$, whose support is $[c, d]$, on $[a, b]$. |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
339 | /// The value $f$ is given, not the derivative. |
| 32 | 340 | /// If $b > d$, add $g()$ to the result. |
| 341 | #[inline] | |
| 342 | #[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:
35
diff
changeset
|
343 | fn i<F: Float>(a: F, b: F, c: F, d: F, f: impl Fn(F) -> F, g: impl Fn() -> F) -> F { |
| 32 | 344 | if b < c { |
| 345 | 0.0 | |
| 346 | } else if b <= d { | |
| 347 | if a <= c { | |
| 348 | f(b) - f(c) | |
| 349 | } else { | |
| 350 | f(b) - f(a) | |
| 351 | } | |
|
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:
35
diff
changeset
|
352 | } else |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
353 | /* b > d */ |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
354 | { |
| 32 | 355 | g() + if a <= c { |
| 356 | f(d) - f(c) | |
| 357 | } else if a < d { | |
| 358 | f(d) - f(a) | |
| 359 | } else { | |
| 360 | 0.0 | |
| 361 | } | |
| 362 | } | |
| 363 | } | |
| 0 | 364 | |
| 365 | #[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:
35
diff
changeset
|
366 | impl<F: Float, C, R, const N: usize> Convolution<CubeIndicator<R, N>, HatConv<C, N>> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
367 | 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:
35
diff
changeset
|
368 | R: Constant<Type = 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:
35
diff
changeset
|
369 | C: Constant<Type = 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:
35
diff
changeset
|
370 | { |
| 32 | 371 | /// Calculates the value of the 1D hat convolution further convolved by a interval indicator. |
| 372 | /// As both functions are piecewise polynomials, this is implemented by explicit integral over | |
| 373 | /// all subintervals of polynomiality of the cube indicator, using easily formed | |
| 374 | /// antiderivatives. | |
| 0 | 375 | #[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:
35
diff
changeset
|
376 | pub fn value_1d_σ1(&self, x: F, β: F) -> F { |
| 0 | 377 | // The integration interval |
| 378 | let a = x - β; | |
| 379 | let b = x + β; | |
| 380 | ||
| 381 | // Observe the factor 1/6 at the front from the antiderivatives below. | |
| 382 | // The factor 4 is from normalisation of the original function. | |
|
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:
35
diff
changeset
|
383 | (4.0 / 6.0) |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
384 | * i( |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
385 | a, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
386 | b, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
387 | -1.0, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
388 | -0.5, |
| 32 | 389 | // (2/3) (y+1)^3 on -1 < y ≤ -1/2 |
| 0 | 390 | // The antiderivative is (2/12)(y+1)^4 = (1/6)(y+1)^4 |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
391 | |y| (y + 1.0).powi(4), |
|
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:
35
diff
changeset
|
392 | || { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
393 | i( |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
394 | a, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
395 | b, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
396 | -0.5, |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
397 | 0.5, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
398 | // -2 y^3 - 2 y^2 + 1/3 on -1/2 < y ≤ 0 |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
399 | // The antiderivative is -1/2 y^4 - 2/3 y^3 + 1/3 y |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
400 | // 2 y^3 - 2 y^2 + 1/3 on 0 < y < 1/2 |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
401 | // The antiderivative is 1/2 y^4 - 2/3 y^3 + 1/3 y |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
402 | |y| y * (y * y * (y.abs() * 3.0 - 4.0) + 2.0), |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
403 | || { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
404 | i( |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
405 | a, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
406 | b, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
407 | 0.5, |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
408 | 1.0, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
409 | // -(2/3) (y-1)^3 on 1/2 < y ≤ 1 |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
410 | // The antiderivative is -(2/12)(y-1)^4 = -(1/6)(y-1)^4 |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
411 | |y| -(y - 1.0).powi(4), |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
412 | || 0.0, |
| 0 | 413 | ) |
|
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:
35
diff
changeset
|
414 | }, |
| 0 | 415 | ) |
|
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:
35
diff
changeset
|
416 | }, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
417 | ) |
| 0 | 418 | } |
| 32 | 419 | |
| 420 | /// Calculates the derivative of the 1D hat convolution further convolved by a interval | |
| 421 | /// indicator. The implementation is similar to [`Self::value_1d_σ1`], using the fact that | |
| 422 | /// $(θ * ψ)' = θ * ψ'$. | |
| 423 | #[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:
35
diff
changeset
|
424 | pub fn diff_1d_σ1(&self, x: F, β: F) -> F { |
| 32 | 425 | // The integration interval |
| 426 | let a = x - β; | |
| 427 | let b = x + β; | |
| 428 | ||
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
429 | i( |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
430 | a, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
431 | b, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
432 | -1.0, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
433 | -0.5, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
434 | // (2/3) (y+1)^3 on -1 < y ≤ -1/2 |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
435 | |y| (8.0 / 3.0) * (y + 1.0).powi(3), |
|
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:
35
diff
changeset
|
436 | || { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
437 | i( |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
438 | a, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
439 | b, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
440 | -0.5, |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
441 | 0.5, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
442 | // 2 y^3 - 2 y^2 + 1/3 on 0 < y < 1/2 |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
443 | |y| 8.0 * (y.abs() - 1.0) * y * y + (4.0 / 3.0), |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
444 | || { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
445 | i( |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
446 | a, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
447 | b, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
448 | 0.5, |
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
449 | 1.0, |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
450 | // -(2/3) (y-1)^3 on 1/2 < y ≤ 1 |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
451 | |y| -(8.0 / 3.0) * (y - 1.0).powi(3), |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
452 | || 0.0, |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
453 | ) |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
454 | }, |
| 32 | 455 | ) |
|
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:
35
diff
changeset
|
456 | }, |
| 32 | 457 | ) |
| 458 | } | |
| 0 | 459 | } |
| 460 | ||
| 35 | 461 | /* |
| 462 | impl<'a, F : Float, R, C, const N : usize> Lipschitz<L2> | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
463 | for Differential<Loc<N, F>, Convolution<CubeIndicator<R, N>, HatConv<C, N>>> |
| 35 | 464 | where R : Constant<Type=F>, |
| 465 | C : Constant<Type=F> { | |
| 466 | ||
| 467 | type FloatType = F; | |
| 468 | ||
| 469 | #[inline] | |
| 470 | fn lipschitz_factor(&self, _l2 : L2) -> Option<F> { | |
| 471 | dbg!("unimplemented"); | |
| 472 | None | |
| 473 | } | |
| 474 | } | |
| 475 | */ | |
| 476 | ||
|
72
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
61
diff
changeset
|
477 | #[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:
35
diff
changeset
|
478 | impl<F: Float, R, C, const N: usize> Convolution<CubeIndicator<R, N>, HatConv<C, N>> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
479 | 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:
35
diff
changeset
|
480 | R: Constant<Type = 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:
35
diff
changeset
|
481 | C: Constant<Type = 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:
35
diff
changeset
|
482 | { |
| 0 | 483 | #[inline] |
| 484 | fn get_r(&self) -> F { | |
| 485 | let Convolution(ref ind, ref hatconv) = self; | |
| 486 | ind.r.value() + hatconv.radius() | |
| 487 | } | |
| 488 | } | |
| 489 | ||
|
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:
35
diff
changeset
|
490 | impl<F: Float, R, C, const N: usize> Support<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:
35
diff
changeset
|
491 | for Convolution<CubeIndicator<R, N>, HatConv<C, N>> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
492 | 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:
35
diff
changeset
|
493 | R: Constant<Type = 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:
35
diff
changeset
|
494 | C: Constant<Type = 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:
35
diff
changeset
|
495 | { |
| 0 | 496 | #[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:
35
diff
changeset
|
497 | fn support_hint(&self) -> Cube<N, F> { |
| 0 | 498 | let r = self.get_r(); |
| 499 | array_init(|| [-r, r]).into() | |
| 500 | } | |
| 501 | ||
| 502 | #[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:
35
diff
changeset
|
503 | fn in_support(&self, y: &Loc<N, F>) -> bool { |
| 0 | 504 | let r = self.get_r(); |
| 505 | y.iter().all(|x| x.abs() <= r) | |
| 506 | } | |
| 507 | ||
| 508 | #[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:
35
diff
changeset
|
509 | fn bisection_hint(&self, cube: &Cube<N, F>) -> [Option<F>; N] { |
| 0 | 510 | // It is not difficult to verify that [`HatConv`] is C^2. |
| 511 | // Therefore, so is [`Convolution<CubeIndicator<R, N>, HatConv<C, N>>`] so that a finer | |
| 512 | // subdivision for the hint than this is not particularly useful. | |
| 513 | let r = self.get_r(); | |
| 514 | cube.map(|c, d| symmetric_peak_hint(r, c, d)) | |
| 515 | } | |
| 516 | } | |
| 517 | ||
|
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:
35
diff
changeset
|
518 | impl<F: Float, R, C, const N: usize> GlobalAnalysis<F, Bounds<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:
35
diff
changeset
|
519 | for Convolution<CubeIndicator<R, N>, HatConv<C, N>> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
520 | 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:
35
diff
changeset
|
521 | R: Constant<Type = 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:
35
diff
changeset
|
522 | C: Constant<Type = 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:
35
diff
changeset
|
523 | { |
| 0 | 524 | #[inline] |
| 525 | fn global_analysis(&self) -> Bounds<F> { | |
| 526 | Bounds(F::ZERO, self.apply(Loc::ORIGIN)) | |
| 527 | } | |
| 528 | } | |
| 529 | ||
|
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:
35
diff
changeset
|
530 | impl<F: Float, R, C, const N: usize> LocalAnalysis<F, Bounds<F>, N> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
531 | for Convolution<CubeIndicator<R, N>, HatConv<C, N>> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
532 | 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:
35
diff
changeset
|
533 | R: Constant<Type = 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:
35
diff
changeset
|
534 | C: Constant<Type = 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:
35
diff
changeset
|
535 | { |
| 0 | 536 | #[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:
35
diff
changeset
|
537 | fn local_analysis(&self, cube: &Cube<N, F>) -> Bounds<F> { |
| 0 | 538 | // The function is maximised/minimised where the absolute value is minimised/maximised. |
| 539 | let lower = self.apply(cube.maxnorm_point()); | |
| 540 | let upper = self.apply(cube.minnorm_point()); | |
| 541 | //assert!(upper >= lower); | |
| 542 | if upper < lower { | |
| 543 | let Convolution(ref ind, ref hatconv) = self; | |
| 544 | let β = ind.r.value(); | |
| 545 | let σ = hatconv.radius(); | |
| 546 | eprintln!("WARNING: Hat convolution {β} {σ} upper bound {upper} < lower bound {lower} on {cube:?} with min-norm point {:?} and max-norm point {:?}", cube.minnorm_point(), cube.maxnorm_point()); | |
| 547 | Bounds(upper, lower) | |
| 548 | } else { | |
| 549 | Bounds(lower, upper) | |
| 550 | } | |
| 551 | } | |
| 552 | } | |
| 553 | ||
| 554 | /// This [`BoundedBy`] implementation bounds $u * u$ by $(ψ * ψ) u$ for $u$ a hat convolution and | |
| 555 | /// $ψ = χ_{[-a,a]^N}$ for some $a>0$. | |
| 556 | /// | |
| 557 | /// This is based on the general formula for bounding $(uχ) * (uχ)$ by $(ψ * ψ) u$, | |
| 558 | /// where we take $ψ = χ_{[-a,a]^N}$ and $χ = χ_{[-σ,σ]^N}$ for $σ$ the width of the hat | |
| 559 | /// convolution. | |
| 560 | #[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:
35
diff
changeset
|
561 | impl<F, C, S, const N: usize> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
562 | BoundedBy<F, SupportProductFirst<AutoConvolution<CubeIndicator<S, N>>, HatConv<C, N>>> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
563 | for AutoConvolution<HatConv<C, N>> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
564 | 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:
35
diff
changeset
|
565 | F: Float, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
566 | C: Constant<Type = 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:
35
diff
changeset
|
567 | S: Constant<Type = 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:
35
diff
changeset
|
568 | { |
| 0 | 569 | fn bounding_factor( |
| 570 | &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:
35
diff
changeset
|
571 | kernel: &SupportProductFirst<AutoConvolution<CubeIndicator<S, N>>, HatConv<C, N>>, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
572 | ) -> DynResult<F> { |
| 0 | 573 | // We use the comparison $ℱ[𝒜(ψ v)] ≤ L_1 ℱ[𝒜(ψ)u] ⟺ I_{v̂} v̂ ≤ L_1 û$ with |
| 574 | // $ψ = χ_{[-w, w]}$ satisfying $supp v ⊂ [-w, w]$, i.e. $w ≥ σ$. Here $v̂ = ℱ[v]$ and | |
| 575 | // $I_{v̂} = ∫ v̂ d ξ. For this relationship to be valid, we need $v̂ ≥ 0$, which is guaranteed | |
| 576 | // by $v̂ = u_σ$ being an autoconvolution. With $u = v$, therefore $L_1 = I_v̂ = ∫ u_σ(ξ) d ξ$. | |
| 577 | let SupportProductFirst(AutoConvolution(ref ind), hatconv2) = kernel; | |
| 578 | let σ = self.0.radius(); | |
| 579 | let a = ind.r.value(); | |
| 580 | let bounding_1d = 4.0 / (3.0 * σ); | |
| 581 | ||
| 582 | // Check that the cutting indicator of the comparison | |
| 583 | // `SupportProductFirst<AutoConvolution<CubeIndicator<S, N>>, HatConv<C, N>>` | |
| 584 | // is wide enough, and that the hat convolution has the same radius as ours. | |
| 585 | if σ <= a && hatconv2 == &self.0 { | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
586 | Ok(bounding_1d.powi(N as i32)) |
| 0 | 587 | } else { |
| 588 | // We cannot compare | |
|
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:
35
diff
changeset
|
589 | Err(anyhow!("Incomparable factors")) |
| 0 | 590 | } |
| 591 | } | |
| 592 | } | |
| 593 | ||
| 594 | /// This [`BoundedBy`] implementation bounds $u * u$ by $u$ for $u$ a hat convolution. | |
| 595 | /// | |
| 596 | /// This is based on Example 3.3 in the manuscript. | |
| 597 | #[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:
35
diff
changeset
|
598 | impl<F, C, const N: usize> BoundedBy<F, HatConv<C, N>> for AutoConvolution<HatConv<C, N>> |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
599 | 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:
35
diff
changeset
|
600 | F: Float, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
601 | C: Constant<Type = 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:
35
diff
changeset
|
602 | { |
| 0 | 603 | /// Returns an estimate of the factor $L_1$. |
| 604 | /// | |
| 605 | /// Returns `None` if `kernel` does not have the same width as hat convolution that `self` | |
| 606 | /// is based on. | |
|
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:
35
diff
changeset
|
607 | fn bounding_factor(&self, kernel: &HatConv<C, N>) -> DynResult<F> { |
| 0 | 608 | if kernel == &self.0 { |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
609 | Ok(1.0) |
| 0 | 610 | } else { |
| 611 | // We cannot compare | |
|
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:
35
diff
changeset
|
612 | Err(anyhow!("Incomparable kernels")) |
| 0 | 613 | } |
| 614 | } | |
| 615 | } | |
| 616 | ||
| 617 | #[cfg(test)] | |
| 618 | mod tests { | |
|
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:
35
diff
changeset
|
619 | use super::HatConv; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
620 | use crate::kernels::{BallIndicator, Convolution, CubeIndicator}; |
| 0 | 621 | use alg_tools::lingrid::linspace; |
|
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:
35
diff
changeset
|
622 | use alg_tools::loc::Loc; |
| 35 | 623 | use alg_tools::mapping::Mapping; |
| 0 | 624 | use alg_tools::norms::Linfinity; |
| 625 | ||
| 626 | /// Tests numerically that [`HatConv<f64, 1>`] is monotone. | |
| 627 | #[test] | |
| 628 | fn hatconv_monotonicity() { | |
| 629 | let grid = linspace(0.0, 1.0, 100000); | |
|
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:
35
diff
changeset
|
630 | let hatconv: HatConv<f64, 1> = HatConv { radius: 1.0 }; |
| 0 | 631 | let mut vals = grid.into_iter().map(|t| hatconv.apply(Loc::from(t))); |
| 632 | let first = vals.next().unwrap(); | |
|
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:
35
diff
changeset
|
633 | let monotone = vals |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
634 | .fold((first, true), |(prev, ok), t| (prev, ok && prev >= t)) |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
635 | .1; |
| 0 | 636 | assert!(monotone); |
| 637 | } | |
| 638 | ||
| 639 | /// Tests numerically that [`Convolution<CubeIndicator<f64, 1>, HatConv<f64, 1>>`] is monotone. | |
| 640 | #[test] | |
| 641 | fn convolution_cubeind_hatconv_monotonicity() { | |
| 642 | let grid = linspace(-2.0, 0.0, 100000); | |
|
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:
35
diff
changeset
|
643 | let hatconv: Convolution<CubeIndicator<f64, 1>, HatConv<f64, 1>> = |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
644 | Convolution(BallIndicator { r: 0.5, exponent: Linfinity }, HatConv { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
645 | radius: 1.0, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
646 | }); |
| 0 | 647 | let mut vals = grid.into_iter().map(|t| hatconv.apply(Loc::from(t))); |
| 648 | let first = vals.next().unwrap(); | |
|
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:
35
diff
changeset
|
649 | let monotone = vals |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
650 | .fold((first, true), |(prev, ok), t| (prev, ok && prev <= t)) |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
651 | .1; |
| 0 | 652 | assert!(monotone); |
| 653 | ||
| 654 | let grid = linspace(0.0, 2.0, 100000); | |
|
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:
35
diff
changeset
|
655 | let hatconv: Convolution<CubeIndicator<f64, 1>, HatConv<f64, 1>> = |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
656 | Convolution(BallIndicator { r: 0.5, exponent: Linfinity }, HatConv { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
657 | radius: 1.0, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
658 | }); |
| 0 | 659 | let mut vals = grid.into_iter().map(|t| hatconv.apply(Loc::from(t))); |
| 660 | let first = vals.next().unwrap(); | |
|
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:
35
diff
changeset
|
661 | let monotone = vals |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
662 | .fold((first, true), |(prev, ok), t| (prev, ok && prev >= t)) |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
663 | .1; |
| 0 | 664 | assert!(monotone); |
| 665 | } | |
| 666 | } |