src/fb.rs

branch
dev
changeset 63
7a8a55fd41c0
parent 61
4f468d35fa29
--- a/src/fb.rs	Thu Feb 26 11:38:43 2026 -0500
+++ b/src/fb.rs	Thu Feb 26 11:36:22 2026 -0500
@@ -107,11 +107,7 @@
 #[replace_float_literals(F::cast_from(literal))]
 impl<F: Float> Default for FBConfig<F> {
     fn default() -> Self {
-        FBConfig {
-            τ0: 0.99,
-            σp0: 0.99,
-            insertion: Default::default(),
-        }
+        FBConfig { τ0: 0.99, σp0: 0.99, insertion: Default::default() }
     }
 }
 
@@ -157,7 +153,7 @@
     fbconfig: &FBConfig<F>,
     iterator: I,
     mut plotter: Plot,
-    μ0 : Option<RNDM<N, F>>,
+    μ0: Option<RNDM<N, F>>,
 ) -> DynResult<RNDM<N, F>>
 where
     F: Float + ToNalgebraRealField,
@@ -196,21 +192,22 @@
         // TODO: optimise τ to be applied to residual.
         let mut τv = f.differential(&μ) * τ;
 
-        // Save current base point
-        let μ_base = μ.clone();
+        // Save current base point for merge
+        let μ_base_len = μ.len();
+        let maybe_μ_base = config.merge_now(&state).then(|| μ.clone());
 
         // Insert and reweigh
-        let (maybe_d, _within_tolerances) = prox_penalty.insert_and_reweigh(
-            &mut μ, &mut τv, &μ_base, None, τ, ε, config, &reg, &state, &mut stats,
-        )?;
+        let (maybe_d, _within_tolerances) = prox_penalty
+            .insert_and_reweigh(&mut μ, &mut τv, τ, ε, config, &reg, &state, &mut stats)?;
+
+        stats.inserted += μ.len() - μ_base_len;
 
         // Prune and possibly merge spikes
-        if config.merge_now(&state) {
+        if let Some(μ_base) = maybe_μ_base {
             stats.merged += prox_penalty.merge_spikes(
                 &mut μ,
                 &mut τv,
                 &μ_base,
-                None,
                 τ,
                 ε,
                 config,
@@ -257,7 +254,7 @@
     fbconfig: &FBConfig<F>,
     iterator: I,
     mut plotter: Plot,
-    μ0: Option<RNDM<N, F>>
+    μ0: Option<RNDM<N, F>>,
 ) -> DynResult<RNDM<N, F>>
 where
     F: Float + ToNalgebraRealField,
@@ -298,13 +295,13 @@
         // Calculate smooth part of surrogate model.
         let mut τv = f.differential(&μ) * τ;
 
-        // Save current base point
-        let μ_base = μ.clone();
+        let μ_base_len = μ.len();
 
         // Insert new spikes and reweigh
-        let (maybe_d, _within_tolerances) = prox_penalty.insert_and_reweigh(
-            &mut μ, &mut τv, &μ_base, None, τ, ε, config, &reg, &state, &mut stats,
-        )?;
+        let (maybe_d, _within_tolerances) = prox_penalty
+            .insert_and_reweigh(&mut μ, &mut τv, τ, ε, config, &reg, &state, &mut stats)?;
+
+        stats.inserted += μ.len() - μ_base_len;
 
         // (Do not) merge spikes.
         if config.merge_now(&state) && !warned_merging {

mercurial