Mon, 05 Dec 2022 23:50:22 +0200
Zenodo packaging hacks
| 0 | 1 | /*! |
| 2 | Forward models from discrete measures to observations. | |
| 3 | */ | |
| 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:
49
diff
changeset
|
5 | use crate::dataterm::QuadraticDataTerm; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
6 | use crate::measures::{Radon, RNDM}; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
7 | use crate::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:
49
diff
changeset
|
8 | use alg_tools::error::{DynError, DynResult}; |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
9 | use alg_tools::euclidean::{ClosedEuclidean, Euclidean}; |
|
49
6b0db7251ebe
Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents:
44
diff
changeset
|
10 | pub use alg_tools::linops::*; |
|
6b0db7251ebe
Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents:
44
diff
changeset
|
11 | use alg_tools::norms::{Norm, NormExponent, 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:
49
diff
changeset
|
12 | use serde::{Deserialize, Serialize}; |
| 0 | 13 | |
|
49
6b0db7251ebe
Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents:
44
diff
changeset
|
14 | pub mod bias; |
| 35 | 15 | pub mod sensor_grid; |
| 0 | 16 | |
| 17 | /// `ForwardeModel`s are bounded preadjointable linear operators $A ∈ 𝕃(𝒵(Ω); E)$ | |
| 18 | /// where $𝒵(Ω) ⊂ ℳ(Ω)$ is the space of sums of delta measures, presented by | |
| 35 | 19 | /// [`crate::measures::DiscreteMeasure`], and $E$ is a [`Euclidean`] space. |
|
49
6b0db7251ebe
Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents:
44
diff
changeset
|
20 | pub trait ForwardModel<Domain: Space, F: Float = f64, E: NormExponent = Radon>: |
|
6b0db7251ebe
Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents:
44
diff
changeset
|
21 | BoundedLinear<Domain, E, L2, F, Codomain = Self::Observable> |
| 35 | 22 | + GEMV<F, Domain, Self::Observable> |
| 23 | + Preadjointable<Domain, Self::Observable> | |
| 24 | where | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
25 | Domain: Norm<E, F>, |
| 35 | 26 | { |
| 0 | 27 | /// The codomain or value space (of “observables”) for this operator. |
| 28 | /// It is assumed to be a [`Euclidean`] space, and therefore also (identified with) | |
| 29 | /// the domain of the preadjoint. | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
30 | type Observable: ClosedEuclidean<F> + Clone; |
| 0 | 31 | |
| 32 | /// Write an observable into a file. | |
|
49
6b0db7251ebe
Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents:
44
diff
changeset
|
33 | fn write_observable(&self, b: &Self::Observable, prefix: String) -> DynError; |
| 0 | 34 | |
| 35 | /// Returns a zero observable | |
| 36 | fn zero_observable(&self) -> Self::Observable; | |
| 37 | } | |
| 38 | ||
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
39 | /// Guess for [`BoundedCurvature`] calculations. |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
40 | #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
41 | pub enum BoundedCurvatureGuess { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
42 | /// No iterate $μ^k$ is worse than $μ=0$. |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
43 | BetterThanZero, |
| 0 | 44 | } |
| 45 | ||
|
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:
63
diff
changeset
|
46 | /// Curvature error control. |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
47 | pub trait BoundedCurvature<F: Float = f64> { |
|
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:
63
diff
changeset
|
48 | /// Returns an estimate of $(ℓ_F, ℓ_∇v, Θ²)$ or individual errors for each. |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
49 | fn curvature_bound_components( |
|
49
6b0db7251ebe
Some documentation and factor changes related to ℓ_F and ℓ_r.
Tuomo Valkonen <tuomov@iki.fi>
parents:
44
diff
changeset
|
50 | &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:
49
diff
changeset
|
51 | guess: BoundedCurvatureGuess, |
|
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:
63
diff
changeset
|
52 | ) -> (DynResult<F>, DynResult<F>, DynResult<F>); |
| 0 | 53 | } |
| 54 | ||
|
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:
63
diff
changeset
|
55 | /// Curvature error control: helper Lipschitz-like bounds for the quadratic dataterms |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
56 | /// $F(μ) = \frac{1}{2}\|Aμ-b\|^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:
49
diff
changeset
|
57 | pub trait BasicCurvatureBoundEstimates<F: Float = f64> { |
|
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:
63
diff
changeset
|
58 | /// Returns $(ℓ_F, ℓ_{∇v}^0, Θ²)$ or individual errors for each. |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
59 | fn basic_curvature_bound_components(&self) -> (DynResult<F>, DynResult<F>, DynResult<F>); |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
60 | } |
| 0 | 61 | |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
62 | impl<F, A, Z, const N: usize> BoundedCurvature<F> for QuadraticDataTerm<F, RNDM<N, F>, 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:
49
diff
changeset
|
63 | 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:
49
diff
changeset
|
64 | 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:
49
diff
changeset
|
65 | Z: Clone + Space + Euclidean<F>, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
66 | A: Mapping<RNDM<N, F>, Codomain = Z>, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
67 | A: BasicCurvatureBoundEstimates<F>, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
68 | { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
69 | fn curvature_bound_components( |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
70 | &self, |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
71 | guess: BoundedCurvatureGuess, |
|
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:
63
diff
changeset
|
72 | ) -> (DynResult<F>, DynResult<F>, DynResult<F>) { |
|
61
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
73 | match guess { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
74 | BoundedCurvatureGuess::BetterThanZero => { |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
75 | let opA = self.operator(); |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
76 | let b = self.data(); |
|
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:
63
diff
changeset
|
77 | let (ℓ_F, ℓ_gradv_0, θ2) = opA.basic_curvature_bound_components(); |
|
e9a460a0e638
New simplified sliding a posteriori rule. Enable scaling heuristic from fixed `measure` crate. “Fast” spread Lipschitz factor fixes, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
63
diff
changeset
|
78 | (ℓ_F, ℓ_gradv_0.map(|l| l * b.norm2()), θ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:
49
diff
changeset
|
79 | } |
|
4f468d35fa29
General forward operators, separation of measures into own crate, and other architecture improvements to support the pointsource_pde crate.
Tuomo Valkonen <tuomov@iki.fi>
parents:
49
diff
changeset
|
80 | } |
| 0 | 81 | } |
| 82 | } |