Thu, 26 Feb 2026 11:38:43 -0500
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
| 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(); |
|
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
|
100 | y.decompose().product_map(|x| self.value_1d_σ1(x / σ) / σ) |
| 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<L1> 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] | |
|
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
|
111 | fn lipschitz_factor(&self, L1: L1) -> DynResult<Self::FloatType> { |
| 32 | 112 | // For any ψ_i, we have |
| 113 | // ∏_{i=1}^N ψ_i(x_i) - ∏_{i=1}^N ψ_i(y_i) | |
| 114 | // = [ψ_1(x_1)-ψ_1(y_1)] ∏_{i=2}^N ψ_i(x_i) | |
| 115 | // + ψ_1(y_1)[ ∏_{i=2}^N ψ_i(x_i) - ∏_{i=2}^N ψ_i(y_i)] | |
| 116 | // = ∑_{j=1}^N [ψ_j(x_j)-ψ_j(y_j)]∏_{i > j} ψ_i(x_i) ∏_{i < j} ψ_i(y_i) | |
| 117 | // Thus | |
| 118 | // |∏_{i=1}^N ψ_i(x_i) - ∏_{i=1}^N ψ_i(y_i)| | |
| 35 | 119 | // ≤ ∑_{j=1}^N |ψ_j(x_j)-ψ_j(y_j)| ∏_{j ≠ i} \max_j |ψ_j| |
| 32 | 120 | let σ = self.radius(); |
|
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
|
121 | let l1d = self.lipschitz_1d_σ1() / (σ * σ); |
|
34
efa60bc4f743
Radon FB + sliding improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
122 | let m1d = self.value_1d_σ1(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
|
123 | Ok(l1d * m1d.powi(N as i32 - 1)) |
| 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<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
|
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 | { |
| 32 | 131 | type FloatType = S::Type; |
| 132 | #[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
|
133 | fn lipschitz_factor(&self, L2: L2) -> DynResult<Self::FloatType> { |
|
4f468d35fa29
General 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 | self.lipschitz_factor(L1) |
|
4f468d35fa29
General 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 | .map(|l1| l1 * <S::Type>::cast_from(N).sqrt()) |
| 32 | 136 | } |
| 137 | } | |
| 138 | ||
|
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
|
139 | 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
|
140 | 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
|
141 | 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
|
142 | { |
|
4f468d35fa29
General 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
|
143 | type Derivative = Loc<N, S::Type>; |
| 35 | 144 | |
| 32 | 145 | #[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
|
146 | 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
|
147 | let y = y0.decompose(); |
| 32 | 148 | let σ = self.radius(); |
| 149 | let σ2 = σ * σ; | |
|
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
|
150 | let vs = y.map(|x| self.value_1d_σ1(x / σ) / σ); |
|
4f468d35fa29
General 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
|
151 | product_differential(&*y, &vs, |x| self.diff_1d_σ1(x / σ) / σ2) |
| 32 | 152 | } |
| 153 | } | |
| 154 | ||
| 35 | 155 | #[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
|
156 | 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
|
157 | 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
|
158 | 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
|
159 | 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
|
160 | { |
| 35 | 161 | type FloatType = F; |
| 162 | ||
| 32 | 163 | #[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
|
164 | 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
|
165 | 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
|
166 | product_differential_lipschitz_factor::<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
|
167 | self.value_1d_σ1(0.0) / σ, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
168 | self.lipschitz_1d_σ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
|
169 | self.maxabsdiff_1d_σ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
|
170 | self.lipschitz_diff_1d_σ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
|
171 | ) |
| 32 | 172 | } |
| 173 | } | |
| 0 | 174 | |
| 175 | #[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
|
176 | 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
|
177 | 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
|
178 | 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
|
179 | { |
| 0 | 180 | /// Computes the value of the kernel for $n=1$ with $σ=1$. |
| 181 | #[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
|
182 | fn value_1d_σ1(&self, x: F) -> F { |
| 0 | 183 | let y = x.abs(); |
| 184 | if y >= 1.0 { | |
| 185 | 0.0 | |
| 186 | } 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
|
187 | -(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
|
188 | } 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
|
189 | /* 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
|
190 | { |
|
4f468d35fa29
General 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
|
191 | (4.0 / 3.0) + 8.0 * y * y * (y - 1.0) |
| 0 | 192 | } |
| 193 | } | |
| 32 | 194 | |
| 195 | /// Computes the differential of the kernel for $n=1$ with $σ=1$. | |
| 196 | #[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
|
197 | fn diff_1d_σ1(&self, x: F) -> F { |
| 32 | 198 | let y = x.abs(); |
| 199 | if y >= 1.0 { | |
| 200 | 0.0 | |
| 201 | } 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
|
202 | -8.0 * (y - 1.0).powi(2) |
|
4f468d35fa29
General 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
|
203 | } 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
|
204 | /* 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
|
205 | { |
| 32 | 206 | (24.0 * y - 16.0) * y |
| 207 | } | |
| 208 | } | |
| 209 | ||
| 210 | /// Computes the Lipschitz factor of the kernel for $n=1$ with $σ=1$. | |
| 211 | #[inline] | |
| 212 | fn lipschitz_1d_σ1(&self) -> F { | |
| 213 | // Maximal absolute differential achieved at ±0.5 by diff_1d_σ1 analysis | |
| 214 | 2.0 | |
| 215 | } | |
| 35 | 216 | |
| 217 | /// Computes the maximum absolute differential of the kernel for $n=1$ with $σ=1$. | |
| 218 | #[inline] | |
| 219 | fn maxabsdiff_1d_σ1(&self) -> F { | |
| 220 | // Maximal absolute differential achieved at ±0.5 by diff_1d_σ1 analysis | |
| 221 | 2.0 | |
| 222 | } | |
| 223 | ||
| 224 | /// Computes the second differential of the kernel for $n=1$ with $σ=1$. | |
| 225 | #[inline] | |
| 226 | #[allow(dead_code)] | |
|
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
|
227 | fn diff2_1d_σ1(&self, x: F) -> F { |
| 35 | 228 | let y = x.abs(); |
| 229 | if y >= 1.0 { | |
| 230 | 0.0 | |
| 231 | } 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
|
232 | -16.0 * (y - 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
|
233 | } 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
|
234 | /* 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
|
235 | { |
| 35 | 236 | 48.0 * y - 16.0 |
| 237 | } | |
| 238 | } | |
| 239 | ||
| 240 | /// Computes the differential of the kernel for $n=1$ with $σ=1$. | |
| 241 | #[inline] | |
| 242 | fn lipschitz_diff_1d_σ1(&self) -> F { | |
| 243 | // Maximal absolute second differential achieved at 0 by diff2_1d_σ1 analysis | |
| 244 | 16.0 | |
| 245 | } | |
| 0 | 246 | } |
| 247 | ||
|
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
|
248 | 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
|
249 | 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
|
250 | 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
|
251 | { |
| 0 | 252 | #[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
|
253 | fn support_hint(&self) -> Cube<N, S::Type> { |
| 0 | 254 | let σ = self.radius(); |
| 255 | array_init(|| [-σ, σ]).into() | |
| 256 | } | |
| 257 | ||
| 258 | #[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
|
259 | fn in_support(&self, y: &Loc<N, S::Type>) -> bool { |
| 0 | 260 | let σ = self.radius(); |
| 261 | y.iter().all(|x| x.abs() <= σ) | |
| 262 | } | |
| 263 | ||
| 264 | #[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
|
265 | fn bisection_hint(&self, cube: &Cube<N, S::Type>) -> [Option<S::Type>; N] { |
| 0 | 266 | let σ = self.radius(); |
| 267 | cube.map(|c, d| symmetric_peak_hint(σ, c, d)) | |
| 268 | } | |
| 269 | } | |
| 270 | ||
| 271 | #[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
|
272 | 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
|
273 | 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
|
274 | 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
|
275 | { |
| 0 | 276 | #[inline] |
| 277 | fn global_analysis(&self) -> Bounds<S::Type> { | |
| 278 | Bounds(0.0, self.apply(Loc::ORIGIN)) | |
| 279 | } | |
| 280 | } | |
| 281 | ||
|
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
|
282 | 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
|
283 | 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
|
284 | 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
|
285 | { |
| 0 | 286 | #[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
|
287 | fn local_analysis(&self, cube: &Cube<N, S::Type>) -> Bounds<S::Type> { |
| 0 | 288 | // The function is maximised/minimised where the 2-norm is minimised/maximised. |
| 289 | let lower = self.apply(cube.maxnorm_point()); | |
| 290 | let upper = self.apply(cube.minnorm_point()); | |
| 291 | Bounds(lower, upper) | |
| 292 | } | |
| 293 | } | |
| 294 | ||
| 295 | #[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
|
296 | impl<'a, C: Constant, const N: usize> Norm<L1, C::Type> for HatConv<C, N> { |
| 0 | 297 | #[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
|
298 | fn norm(&self, _: L1) -> C::Type { |
| 0 | 299 | 1.0 |
| 300 | } | |
| 301 | } | |
| 302 | ||
| 303 | #[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
|
304 | impl<'a, C: Constant, const N: usize> Norm<Linfinity, C::Type> for HatConv<C, N> { |
| 0 | 305 | #[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
|
306 | fn norm(&self, _: Linfinity) -> C::Type { |
| 0 | 307 | self.bounds().upper() |
| 308 | } | |
| 309 | } | |
| 310 | ||
| 311 | #[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
|
312 | 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
|
313 | 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
|
314 | 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
|
315 | 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
|
316 | 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
|
317 | { |
| 35 | 318 | type Codomain = F; |
| 0 | 319 | |
| 320 | #[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
|
321 | fn apply<I: Instance<Loc<N, F>>>(&self, y: I) -> F { |
| 0 | 322 | let Convolution(ref ind, ref hatconv) = self; |
| 323 | let β = ind.r.value(); | |
| 324 | let σ = hatconv.radius(); | |
| 325 | ||
| 326 | // 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
|
327 | y.decompose().product_map(|x| { |
| 0 | 328 | // With $u_σ(x) = u_1(x/σ)/σ$ the normalised hat convolution |
| 329 | // we have | |
| 330 | // $$ | |
| 331 | // [χ_{-β,β} * u_σ](x) | |
| 332 | // = ∫_{x-β}^{x+β} u_σ(z) d z | |
| 333 | // = (1/σ)∫_{x-β}^{x+β} u_1(z/σ) d z | |
| 334 | // = ∫_{(x-β)/σ}^{(x+β)/σ} u_1(z) d z | |
| 335 | // = [χ_{-β/σ, β/σ} * u_1](x/σ) | |
| 336 | // $$ | |
| 337 | self.value_1d_σ1(x / σ, β / σ) | |
| 338 | }) | |
| 339 | } | |
| 340 | } | |
| 341 | ||
| 35 | 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 | 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
|
344 | 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
|
345 | 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
|
346 | 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
|
347 | 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
|
348 | { |
|
4f468d35fa29
General 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
|
349 | type Derivative = Loc<N, F>; |
| 0 | 350 | |
| 351 | #[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
|
352 | 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
|
353 | let y = y0.decompose(); |
| 32 | 354 | let Convolution(ref ind, ref hatconv) = self; |
| 355 | let β = ind.r.value(); | |
| 356 | let σ = hatconv.radius(); | |
| 357 | let σ2 = σ * σ; | |
| 358 | ||
|
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
|
359 | let vs = y.map(|x| self.value_1d_σ1(x / σ, β / σ)); |
|
4f468d35fa29
General 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
|
360 | product_differential(&*y, &vs, |x| self.diff_1d_σ1(x / σ, β / σ) / σ2) |
| 32 | 361 | } |
| 362 | } | |
| 363 | ||
| 364 | /// Integrate $f$, whose support is $[c, d]$, on $[a, b]$. | |
| 365 | /// If $b > d$, add $g()$ to the result. | |
| 366 | #[inline] | |
| 367 | #[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
|
368 | fn i<F: Float>(a: F, b: F, c: F, d: F, f: impl Fn(F) -> F, g: impl Fn() -> F) -> F { |
| 32 | 369 | if b < c { |
| 370 | 0.0 | |
| 371 | } else if b <= d { | |
| 372 | if a <= c { | |
| 373 | f(b) - f(c) | |
| 374 | } else { | |
| 375 | f(b) - f(a) | |
| 376 | } | |
|
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
|
377 | } 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
|
378 | /* 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
|
379 | { |
| 32 | 380 | g() + if a <= c { |
| 381 | f(d) - f(c) | |
| 382 | } else if a < d { | |
| 383 | f(d) - f(a) | |
| 384 | } else { | |
| 385 | 0.0 | |
| 386 | } | |
| 387 | } | |
| 388 | } | |
| 0 | 389 | |
| 390 | #[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
|
391 | 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
|
392 | 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
|
393 | 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
|
394 | 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
|
395 | { |
| 32 | 396 | /// Calculates the value of the 1D hat convolution further convolved by a interval indicator. |
| 397 | /// As both functions are piecewise polynomials, this is implemented by explicit integral over | |
| 398 | /// all subintervals of polynomiality of the cube indicator, using easily formed | |
| 399 | /// antiderivatives. | |
| 0 | 400 | #[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
|
401 | pub fn value_1d_σ1(&self, x: F, β: F) -> F { |
| 0 | 402 | // The integration interval |
| 403 | let a = x - β; | |
| 404 | let b = x + β; | |
| 405 | ||
| 406 | #[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
|
407 | fn pow4<F: Float>(x: F) -> F { |
| 0 | 408 | let y = x * x; |
| 409 | y * y | |
| 410 | } | |
|
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
|
411 | |
| 0 | 412 | // Observe the factor 1/6 at the front from the antiderivatives below. |
| 413 | // 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
|
414 | (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
|
415 | * 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
|
416 | 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
|
417 | 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
|
418 | -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
|
419 | -0.5, |
| 32 | 420 | // (2/3) (y+1)^3 on -1 < y ≤ -1/2 |
| 0 | 421 | // The antiderivative is (2/12)(y+1)^4 = (1/6)(y+1)^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
|
422 | |y| pow4(y + 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
|
423 | || { |
|
4f468d35fa29
General 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 | 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
|
425 | 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
|
426 | 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
|
427 | -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
|
428 | 0.0, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
429 | // -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
|
430 | // The antiderivative is -1/2 y^4 - 2/3 y^3 + 1/3 y |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
431 | |y| y * (-y * y * (y * 3.0 + 4.0) + 2.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
|
432 | || { |
|
4f468d35fa29
General 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 | 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
|
434 | 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
|
435 | 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
|
436 | 0.0, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
437 | 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
|
438 | // 2 y^3 - 2 y^2 + 1/3 on 0 < y < 1/2 |
|
4f468d35fa29
General 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 | // The antiderivative is 1/2 y^4 - 2/3 y^3 + 1/3 y |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
440 | |y| y * (y * y * (y * 3.0 - 4.0) + 2.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
|
441 | || { |
|
4f468d35fa29
General 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
|
442 | 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
|
443 | 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
|
444 | 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
|
445 | 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
|
446 | 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
|
447 | // -(2/3) (y-1)^3 on 1/2 < y ≤ 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
|
448 | // The antiderivative is -(2/12)(y-1)^4 = -(1/6)(y-1)^4 |
|
4f468d35fa29
General 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
|
449 | |y| -pow4(y - 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
|
450 | || 0.0, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
451 | ) |
|
4f468d35fa29
General 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
|
452 | }, |
| 0 | 453 | ) |
|
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
|
454 | }, |
| 0 | 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 | }, |
|
4f468d35fa29
General 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
|
457 | ) |
| 0 | 458 | } |
| 32 | 459 | |
| 460 | /// Calculates the derivative of the 1D hat convolution further convolved by a interval | |
| 461 | /// indicator. The implementation is similar to [`Self::value_1d_σ1`], using the fact that | |
| 462 | /// $(θ * ψ)' = θ * ψ'$. | |
| 463 | #[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
|
464 | pub fn diff_1d_σ1(&self, x: F, β: F) -> F { |
| 32 | 465 | // The integration interval |
| 466 | let a = x - β; | |
| 467 | let b = x + β; | |
| 468 | ||
| 469 | // 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
|
470 | 4.0 * 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
|
471 | 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
|
472 | 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
|
473 | -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
|
474 | -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
|
475 | // (2/3) (y+1)^3 on -1 < y ≤ -1/2 |
|
4f468d35fa29
General 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
|
476 | |y| (2.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
|
477 | || { |
|
4f468d35fa29
General 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 | 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
|
479 | 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
|
480 | 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
|
481 | -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
|
482 | 0.0, |
| 32 | 483 | // -2 y^3 - 2 y^2 + 1/3 on -1/2 < y ≤ 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
|
484 | |y| -2.0 * (y + 1.0) * y * y + (1.0 / 3.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
|
485 | || { |
|
4f468d35fa29
General 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
|
486 | 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
|
487 | 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
|
488 | 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
|
489 | 0.0, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
490 | 0.5, |
| 32 | 491 | // 2 y^3 - 2 y^2 + 1/3 on 0 < y < 1/2 |
|
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
|
492 | |y| 2.0 * (y - 1.0) * y * y + (1.0 / 3.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
|
493 | || { |
|
4f468d35fa29
General 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 | 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
|
495 | 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
|
496 | 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
|
497 | 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
|
498 | 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
|
499 | // -(2/3) (y-1)^3 on 1/2 < y ≤ 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
|
500 | |y| -(2.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
|
501 | || 0.0, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
35
diff
changeset
|
502 | ) |
|
4f468d35fa29
General 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 | }, |
|
4f468d35fa29
General 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
|
504 | ) |
|
4f468d35fa29
General 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
|
505 | }, |
| 32 | 506 | ) |
|
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
|
507 | }, |
| 32 | 508 | ) |
| 509 | } | |
| 0 | 510 | } |
| 511 | ||
| 35 | 512 | /* |
| 513 | 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
|
514 | for Differential<Loc<N, F>, Convolution<CubeIndicator<R, N>, HatConv<C, N>>> |
| 35 | 515 | where R : Constant<Type=F>, |
| 516 | C : Constant<Type=F> { | |
| 517 | ||
| 518 | type FloatType = F; | |
| 519 | ||
| 520 | #[inline] | |
| 521 | fn lipschitz_factor(&self, _l2 : L2) -> Option<F> { | |
| 522 | dbg!("unimplemented"); | |
| 523 | None | |
| 524 | } | |
| 525 | } | |
| 526 | */ | |
| 527 | ||
|
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
|
528 | 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
|
529 | 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
|
530 | 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
|
531 | 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
|
532 | { |
| 0 | 533 | #[inline] |
| 534 | fn get_r(&self) -> F { | |
| 535 | let Convolution(ref ind, ref hatconv) = self; | |
| 536 | ind.r.value() + hatconv.radius() | |
| 537 | } | |
| 538 | } | |
| 539 | ||
|
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
|
540 | 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
|
541 | 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
|
542 | 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
|
543 | 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
|
544 | 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
|
545 | { |
| 0 | 546 | #[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
|
547 | fn support_hint(&self) -> Cube<N, F> { |
| 0 | 548 | let r = self.get_r(); |
| 549 | array_init(|| [-r, r]).into() | |
| 550 | } | |
| 551 | ||
| 552 | #[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
|
553 | fn in_support(&self, y: &Loc<N, F>) -> bool { |
| 0 | 554 | let r = self.get_r(); |
| 555 | y.iter().all(|x| x.abs() <= r) | |
| 556 | } | |
| 557 | ||
| 558 | #[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
|
559 | fn bisection_hint(&self, cube: &Cube<N, F>) -> [Option<F>; N] { |
| 0 | 560 | // It is not difficult to verify that [`HatConv`] is C^2. |
| 561 | // Therefore, so is [`Convolution<CubeIndicator<R, N>, HatConv<C, N>>`] so that a finer | |
| 562 | // subdivision for the hint than this is not particularly useful. | |
| 563 | let r = self.get_r(); | |
| 564 | cube.map(|c, d| symmetric_peak_hint(r, c, d)) | |
| 565 | } | |
| 566 | } | |
| 567 | ||
|
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
|
568 | 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
|
569 | 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
|
570 | 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
|
571 | 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
|
572 | 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
|
573 | { |
| 0 | 574 | #[inline] |
| 575 | fn global_analysis(&self) -> Bounds<F> { | |
| 576 | Bounds(F::ZERO, self.apply(Loc::ORIGIN)) | |
| 577 | } | |
| 578 | } | |
| 579 | ||
|
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
|
580 | 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
|
581 | 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
|
582 | 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
|
583 | 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
|
584 | 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
|
585 | { |
| 0 | 586 | #[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
|
587 | fn local_analysis(&self, cube: &Cube<N, F>) -> Bounds<F> { |
| 0 | 588 | // The function is maximised/minimised where the absolute value is minimised/maximised. |
| 589 | let lower = self.apply(cube.maxnorm_point()); | |
| 590 | let upper = self.apply(cube.minnorm_point()); | |
| 591 | //assert!(upper >= lower); | |
| 592 | if upper < lower { | |
| 593 | let Convolution(ref ind, ref hatconv) = self; | |
| 594 | let β = ind.r.value(); | |
| 595 | let σ = hatconv.radius(); | |
| 596 | 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()); | |
| 597 | Bounds(upper, lower) | |
| 598 | } else { | |
| 599 | Bounds(lower, upper) | |
| 600 | } | |
| 601 | } | |
| 602 | } | |
| 603 | ||
| 604 | /// This [`BoundedBy`] implementation bounds $u * u$ by $(ψ * ψ) u$ for $u$ a hat convolution and | |
| 605 | /// $ψ = χ_{[-a,a]^N}$ for some $a>0$. | |
| 606 | /// | |
| 607 | /// This is based on the general formula for bounding $(uχ) * (uχ)$ by $(ψ * ψ) u$, | |
| 608 | /// where we take $ψ = χ_{[-a,a]^N}$ and $χ = χ_{[-σ,σ]^N}$ for $σ$ the width of the hat | |
| 609 | /// convolution. | |
| 610 | #[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
|
611 | 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
|
612 | 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
|
613 | 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
|
614 | 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
|
615 | 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
|
616 | 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
|
617 | 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
|
618 | { |
| 0 | 619 | fn bounding_factor( |
| 620 | &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
|
621 | 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
|
622 | ) -> DynResult<F> { |
| 0 | 623 | // We use the comparison $ℱ[𝒜(ψ v)] ≤ L_1 ℱ[𝒜(ψ)u] ⟺ I_{v̂} v̂ ≤ L_1 û$ with |
| 624 | // $ψ = χ_{[-w, w]}$ satisfying $supp v ⊂ [-w, w]$, i.e. $w ≥ σ$. Here $v̂ = ℱ[v]$ and | |
| 625 | // $I_{v̂} = ∫ v̂ d ξ. For this relationship to be valid, we need $v̂ ≥ 0$, which is guaranteed | |
| 626 | // by $v̂ = u_σ$ being an autoconvolution. With $u = v$, therefore $L_1 = I_v̂ = ∫ u_σ(ξ) d ξ$. | |
| 627 | let SupportProductFirst(AutoConvolution(ref ind), hatconv2) = kernel; | |
| 628 | let σ = self.0.radius(); | |
| 629 | let a = ind.r.value(); | |
| 630 | let bounding_1d = 4.0 / (3.0 * σ); | |
| 631 | ||
| 632 | // Check that the cutting indicator of the comparison | |
| 633 | // `SupportProductFirst<AutoConvolution<CubeIndicator<S, N>>, HatConv<C, N>>` | |
| 634 | // is wide enough, and that the hat convolution has the same radius as ours. | |
| 635 | 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
|
636 | Ok(bounding_1d.powi(N as i32)) |
| 0 | 637 | } else { |
| 638 | // 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
|
639 | Err(anyhow!("Incomparable factors")) |
| 0 | 640 | } |
| 641 | } | |
| 642 | } | |
| 643 | ||
| 644 | /// This [`BoundedBy`] implementation bounds $u * u$ by $u$ for $u$ a hat convolution. | |
| 645 | /// | |
| 646 | /// This is based on Example 3.3 in the manuscript. | |
| 647 | #[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
|
648 | 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
|
649 | 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
|
650 | 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
|
651 | 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
|
652 | { |
| 0 | 653 | /// Returns an estimate of the factor $L_1$. |
| 654 | /// | |
| 655 | /// Returns `None` if `kernel` does not have the same width as hat convolution that `self` | |
| 656 | /// 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
|
657 | fn bounding_factor(&self, kernel: &HatConv<C, N>) -> DynResult<F> { |
| 0 | 658 | 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
|
659 | Ok(1.0) |
| 0 | 660 | } else { |
| 661 | // 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
|
662 | Err(anyhow!("Incomparable kernels")) |
| 0 | 663 | } |
| 664 | } | |
| 665 | } | |
| 666 | ||
| 667 | #[cfg(test)] | |
| 668 | 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
|
669 | 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
|
670 | use crate::kernels::{BallIndicator, Convolution, CubeIndicator}; |
| 0 | 671 | 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
|
672 | use alg_tools::loc::Loc; |
| 35 | 673 | use alg_tools::mapping::Mapping; |
| 0 | 674 | use alg_tools::norms::Linfinity; |
| 675 | ||
| 676 | /// Tests numerically that [`HatConv<f64, 1>`] is monotone. | |
| 677 | #[test] | |
| 678 | fn hatconv_monotonicity() { | |
| 679 | 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
|
680 | let hatconv: HatConv<f64, 1> = HatConv { radius: 1.0 }; |
| 0 | 681 | let mut vals = grid.into_iter().map(|t| hatconv.apply(Loc::from(t))); |
| 682 | 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
|
683 | 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
|
684 | .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
|
685 | .1; |
| 0 | 686 | assert!(monotone); |
| 687 | } | |
| 688 | ||
| 689 | /// Tests numerically that [`Convolution<CubeIndicator<f64, 1>, HatConv<f64, 1>>`] is monotone. | |
| 690 | #[test] | |
| 691 | fn convolution_cubeind_hatconv_monotonicity() { | |
| 692 | 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
|
693 | 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
|
694 | 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
|
695 | 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
|
696 | }); |
| 0 | 697 | let mut vals = grid.into_iter().map(|t| hatconv.apply(Loc::from(t))); |
| 698 | 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
|
699 | 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
|
700 | .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
|
701 | .1; |
| 0 | 702 | assert!(monotone); |
| 703 | ||
| 704 | 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
|
705 | 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
|
706 | 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
|
707 | 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
|
708 | }); |
| 0 | 709 | let mut vals = grid.into_iter().map(|t| hatconv.apply(Loc::from(t))); |
| 710 | 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
|
711 | 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
|
712 | .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
|
713 | .1; |
| 0 | 714 | assert!(monotone); |
| 715 | } | |
| 716 | } |