src/prox_penalty/radon_squared.rs

Thu, 23 Jan 2025 23:48:52 +0100

author
Tuomo Valkonen <tuomov@iki.fi>
date
Thu, 23 Jan 2025 23:48:52 +0100
branch
dev
changeset 40
896b42b5ac1a
parent 39
6316d68b58af
permissions
-rw-r--r--

README updates

37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1 /*!
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
2 Solver for the point source localisation problem using a simplified forward-backward splitting method.
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
3
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
4 Instead of the $𝒟$-norm of `fb.rs`, this uses a standard Radon norm for the proximal map.
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
5 */
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
6
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
7 use numeric_literals::replace_float_literals;
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
8 use serde::{Serialize, Deserialize};
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
9 use nalgebra::DVector;
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
10
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
11 use alg_tools::iterate::{
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
12 AlgIteratorIteration,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
13 AlgIterator
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
14 };
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
15 use alg_tools::norms::{L2, Norm};
37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
16 use alg_tools::linops::Mapping;
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
17 use alg_tools::bisection_tree::{
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
18 BTFN,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
19 Bounds,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
20 BTSearch,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
21 SupportGenerator,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
22 LocalAnalysis,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
23 };
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
24 use alg_tools::mapping::RealMapping;
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
25 use alg_tools::nalgebra_support::ToNalgebraRealField;
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
26
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
27 use crate::types::*;
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
28 use crate::measures::{
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
29 RNDM,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
30 DeltaMeasure,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
31 Radon,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
32 };
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
33 use crate::measures::merging::SpikeMerging;
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
34 use crate::regularisation::RegTerm;
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
35 use crate::forward_model::{
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
36 ForwardModel,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
37 AdjointProductBoundedBy
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
38 };
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
39 use super::{
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
40 FBGenericConfig,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
41 ProxPenalty,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
42 };
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
43
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
44 /// Radon-norm squared proximal penalty
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
45
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
46 #[derive(Copy,Clone,Serialize,Deserialize)]
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
47 pub struct RadonSquared;
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
48
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
49 #[replace_float_literals(F::cast_from(literal))]
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
50 impl<F, GA, BTA, S, Reg, const N : usize>
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
51 ProxPenalty<F, BTFN<F, GA, BTA, N>, Reg, N> for RadonSquared
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
52 where
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
53 F : Float + ToNalgebraRealField,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
54 GA : SupportGenerator<F, N, SupportType = S, Id = usize> + Clone,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
55 BTA : BTSearch<F, N, Data=usize, Agg=Bounds<F>>,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
56 S: RealMapping<F, N> + LocalAnalysis<F, Bounds<F>, N>,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
57 Reg : RegTerm<F, N>,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
58 RNDM<F, N> : SpikeMerging<F>,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
59 {
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
60 type ReturnMapping = BTFN<F, GA, BTA, N>;
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
61
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
62 fn insert_and_reweigh<I>(
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
63 &self,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
64 μ : &mut RNDM<F, N>,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
65 τv : &mut BTFN<F, GA, BTA, N>,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
66 μ_base : &RNDM<F, N>,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
67 ν_delta: Option<&RNDM<F, N>>,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
68 τ : F,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
69 ε : F,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
70 config : &FBGenericConfig<F>,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
71 reg : &Reg,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
72 _state : &AlgIteratorIteration<I>,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
73 stats : &mut IterInfo<F, N>,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
74 ) -> (Option<Self::ReturnMapping>, bool)
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
75 where
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
76 I : AlgIterator
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
77 {
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
78 let mut y = μ_base.masses_dvector();
37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
79
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
80 assert!(μ_base.len() <= μ.len());
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
81
37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
82 'i_and_w: for i in 0..=1 {
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
83 // Optimise weights
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
84 if μ.len() > 0 {
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
85 // Form finite-dimensional subproblem. The subproblem references to the original μ^k
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
86 // from the beginning of the iteration are all contained in the immutable c and g.
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
87 // TODO: observe negation of -τv after switch from minus_τv: finite-dimensional
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
88 // problems have not yet been updated to sign change.
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
89 let g̃ = DVector::from_iterator(μ.len(),
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
90 μ.iter_locations()
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
91 .map(|ζ| - F::to_nalgebra_mixed(τv.apply(ζ))));
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
92 let mut x = μ.masses_dvector();
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
93 y.extend(std::iter::repeat(0.0.to_nalgebra_mixed()).take(0.max(x.len()-y.len())));
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
94 assert_eq!(y.len(), x.len());
37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
95 // Solve finite-dimensional subproblem.
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
96 // TODO: This assumes that ν_delta has no common locations with μ-μ_base, to
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
97 // ignore it.
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
98 stats.inner_iters += reg.solve_findim_l1squared(&y, &g̃, τ, &mut x, ε, config);
37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
99
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
100 // Update masses of μ based on solution of finite-dimensional subproblem.
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
101 μ.set_masses_dvector(&x);
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
102 }
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
103
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
104 if i>0 {
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
105 // Simple debugging test to see if more inserts would be needed. Doesn't seem so.
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
106 //let n = μ.dist_matching(μ_base);
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
107 //println!("{:?}", reg.find_tolerance_violation_slack(τv, τ, ε, false, config, n));
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
108 break 'i_and_w
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
109 }
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
110
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
111 // Calculate ‖μ - μ_base‖_ℳ
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
112 // TODO: This assumes that ν_delta has no common locations with μ-μ_base.
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
113 let n = μ.dist_matching(μ_base) + ν_delta.map_or(0.0, |ν| ν.norm(Radon));
37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
114
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
115 // Find a spike to insert, if needed.
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
116 // This only check the overall tolerances, not tolerances on support of μ-μ_base or μ,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
117 // which are supposed to have been guaranteed by the finite-dimensional weight optimisation.
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
118 match reg.find_tolerance_violation_slack(τv, τ, ε, false, config, n) {
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
119 None => { break 'i_and_w },
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
120 Some((ξ, _v_ξ, _in_bounds)) => {
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
121 // Weight is found out by running the finite-dimensional optimisation algorithm
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
122 // above
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
123 *μ += DeltaMeasure { x : ξ, α : 0.0 };
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
124 stats.inserted += 1;
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
125 }
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
126 };
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
127 }
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
128
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
129 (None, true)
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
130 }
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
131
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
132 fn merge_spikes(
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
133 &self,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
134 μ : &mut RNDM<F, N>,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
135 τv : &mut BTFN<F, GA, BTA, N>,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
136 μ_base : &RNDM<F, N>,
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
137 ν_delta: Option<&RNDM<F, N>>,
37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
138 τ : F,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
139 ε : F,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
140 config : &FBGenericConfig<F>,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
141 reg : &Reg,
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
142 fitness : Option<impl Fn(&RNDM<F, N>) -> F>,
37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
143 ) -> usize
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
144 {
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
145 if config.fitness_merging {
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
146 if let Some(f) = fitness {
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
147 return μ.merge_spikes_fitness(config.merging, f, |&v| v)
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
148 .1
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
149 }
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
150 }
37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
151 μ.merge_spikes(config.merging, |μ_candidate| {
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
152 // Important: μ_candidate's new points are afterwards,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
153 // and do not conflict with μ_base.
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
154 // TODO: could simplify to requiring μ_base instead of μ_radon.
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
155 // but may complicate with sliding base's exgtra points that need to be
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
156 // after μ_candidate's extra points.
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
157 // TODO: doesn't seem to work, maybe need to merge μ_base as well?
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
158 // Although that doesn't seem to make sense.
39
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
159 let μ_radon = match ν_delta {
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
160 None => μ_candidate.sub_matching(μ_base),
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
161 Some(ν) => μ_candidate.sub_matching(μ_base) - ν,
6316d68b58af Merging adjustments, parameter tuning, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents: 37
diff changeset
162 };
37
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
163 reg.verify_merge_candidate_radonsq(τv, μ_candidate, τ, ε, &config, &μ_radon)
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
164 //let n = μ_candidate.dist_matching(μ_base);
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
165 //reg.find_tolerance_violation_slack(τv, τ, ε, false, config, n).is_none()
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
166 })
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
167 }
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
168 }
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
169
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
170
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
171 impl<F, A, const N : usize> AdjointProductBoundedBy<RNDM<F, N>, RadonSquared>
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
172 for A
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
173 where
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
174 F : Float,
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
175 A : ForwardModel<RNDM<F, N>, F>
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
176 {
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
177 type FloatType = F;
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
178
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
179 fn adjoint_product_bound(&self, _ : &RadonSquared) -> Option<Self::FloatType> {
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
180 self.opnorm_bound(Radon, L2).powi(2).into()
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
181 }
c5d8bd1a7728 Generic proximal penalty support
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
182 }

mercurial