| |
1 /*! |
| |
2 Regularisation terms |
| |
3 */ |
| |
4 |
| |
5 use serde::{Serialize, Deserialize}; |
| |
6 use alg_tools::norms::Norm; |
| |
7 use alg_tools::linops::Apply; |
| |
8 use alg_tools::loc::Loc; |
| |
9 use crate::types::*; |
| |
10 use crate::measures::{ |
| |
11 DiscreteMeasure, |
| |
12 Radon |
| |
13 }; |
| |
14 #[allow(unused_imports)] // Used by documentation. |
| |
15 use crate::fb::generic_pointsource_fb_reg; |
| |
16 |
| |
17 /// The regularisation term $α\\|μ\\|\_{ℳ(Ω)} + δ_{≥ 0}(μ)$ for [`generic_pointsource_fb_reg`]. |
| |
18 /// |
| |
19 /// The only member of the struct is the regularisation parameter α. |
| |
20 #[derive(Copy, Clone, Debug, Serialize, Deserialize)] |
| |
21 pub struct NonnegRadonRegTerm<F : Float>(pub F /* α */); |
| |
22 |
| |
23 impl<'a, F : Float> NonnegRadonRegTerm<F> { |
| |
24 /// Returns the regularisation parameter |
| |
25 pub fn α(&self) -> F { |
| |
26 let &NonnegRadonRegTerm(α) = self; |
| |
27 α |
| |
28 } |
| |
29 } |
| |
30 |
| |
31 impl<'a, F : Float, const N : usize> Apply<&'a DiscreteMeasure<Loc<F, N>, F>> |
| |
32 for NonnegRadonRegTerm<F> { |
| |
33 type Output = F; |
| |
34 |
| |
35 fn apply(&self, μ : &'a DiscreteMeasure<Loc<F, N>, F>) -> F { |
| |
36 self.α() * μ.norm(Radon) |
| |
37 } |
| |
38 } |
| |
39 |
| |
40 |
| |
41 /// The regularisation term $α\|μ\|_{ℳ(Ω)}$ for [`generic_pointsource_fb_reg`]. |
| |
42 /// |
| |
43 /// The only member of the struct is the regularisation parameter α. |
| |
44 #[derive(Copy, Clone, Debug, Serialize, Deserialize)] |
| |
45 pub struct RadonRegTerm<F : Float>(pub F /* α */); |
| |
46 |
| |
47 |
| |
48 impl<'a, F : Float> RadonRegTerm<F> { |
| |
49 /// Returns the regularisation parameter |
| |
50 pub fn α(&self) -> F { |
| |
51 let &RadonRegTerm(α) = self; |
| |
52 α |
| |
53 } |
| |
54 } |
| |
55 |
| |
56 impl<'a, F : Float, const N : usize> Apply<&'a DiscreteMeasure<Loc<F, N>, F>> |
| |
57 for RadonRegTerm<F> { |
| |
58 type Output = F; |
| |
59 |
| |
60 fn apply(&self, μ : &'a DiscreteMeasure<Loc<F, N>, F>) -> F { |
| |
61 self.α() * μ.norm(Radon) |
| |
62 } |
| |
63 } |
| |
64 |
| |
65 /// Regularisation term configuration |
| |
66 #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] |
| |
67 pub enum Regularisation<F : Float> { |
| |
68 /// $α \\|μ\\|\_{ℳ(Ω)}$ |
| |
69 Radon(F), |
| |
70 /// $α\\|μ\\|\_{ℳ(Ω)} + δ_{≥ 0}(μ)$ |
| |
71 NonnegRadon(F), |
| |
72 } |
| |
73 |
| |
74 impl<'a, F : Float, const N : usize> Apply<&'a DiscreteMeasure<Loc<F, N>, F>> |
| |
75 for Regularisation<F> { |
| |
76 type Output = F; |
| |
77 |
| |
78 fn apply(&self, μ : &'a DiscreteMeasure<Loc<F, N>, F>) -> F { |
| |
79 match *self { |
| |
80 Self::Radon(α) => RadonRegTerm(α).apply(μ), |
| |
81 Self::NonnegRadon(α) => NonnegRadonRegTerm(α).apply(μ), |
| |
82 } |
| |
83 } |
| |
84 } |