src/prox_penalty/wave.rs

branch
dev
changeset 39
6316d68b58af
parent 37
c5d8bd1a7728
--- a/src/prox_penalty/wave.rs	Thu Jan 23 23:35:28 2025 +0100
+++ b/src/prox_penalty/wave.rs	Thu Jan 23 23:34:05 2025 +0100
@@ -36,7 +36,6 @@
 use crate::types::{
     IterInfo,
 };
-use crate::measures::merging::SpikeMergingMethod;
 use crate::regularisation::RegTerm;
 use super::{ProxPenalty, FBGenericConfig};
 
@@ -74,7 +73,6 @@
         I : AlgIterator
     {
 
-        // TODO: is this inefficient to do in every iteration?
         let op𝒟norm = self.opnorm_bound(Radon, Linfinity);
 
         // Maximum insertion count and measure difference calculation depend on insertion style.
@@ -98,7 +96,7 @@
                 // problems have not yet been updated to sign change.
                 let à = self.findim_matrix(μ.iter_locations());
                 let g̃ = DVector::from_iterator(μ.len(),
-                                            μ.iter_locations()
+                                               μ.iter_locations()
                                                 .map(|ζ| ω0.apply(ζ) - τv.apply(ζ))
                                                 .map(F::to_nalgebra_mixed));
                 let mut x = μ.masses_dvector();
@@ -127,7 +125,7 @@
             // If no merging heuristic is used, let's be more conservative about spike insertion,
             // and skip it after first round. If merging is done, being more greedy about spike
             // insertion also seems to improve performance.
-            let skip_by_rough_check = if let SpikeMergingMethod::None = config.merging {
+            let skip_by_rough_check = if config.merging.enabled {
                 false
             } else {
                 count > 0
@@ -168,14 +166,25 @@
         μ : &mut RNDM<F, N>,
         τv : &mut BTFN<F, GA, BTA, N>,
         μ_base : &RNDM<F, N>,
+        ν_delta: Option<&RNDM<F, N>>,
         τ : F,
         ε : F,
         config : &FBGenericConfig<F>,
         reg : &Reg,
+        fitness : Option<impl Fn(&RNDM<F, N>) -> F>,
     ) -> usize
     {
+        if config.fitness_merging {
+            if let Some(f) = fitness {
+                return μ.merge_spikes_fitness(config.merging, f, |&v| v)
+                        .1
+            }
+        }
         μ.merge_spikes(config.merging, |μ_candidate| {
-            let mut d = &*τv + self.preapply(μ_candidate.sub_matching(μ_base));
+            let mut d = &*τv + self.preapply(match ν_delta {
+                None => μ_candidate.sub_matching(μ_base),
+                Some(ν) => μ_candidate.sub_matching(μ_base) - ν,
+            });
             reg.verify_merge_candidate(&mut d, μ_candidate, τ, ε, config)
         })
     }

mercurial