# HG changeset patch # User Tuomo Valkonen # Date 1669997320 -7200 # Node ID c32171f7cce5a86c133e8af08b62aae2561176e9 # Parent bcb508479948e1bc835955aef669b9310db0456a Remove ergodic tolerance; it's not useful. diff -r bcb508479948 -r c32171f7cce5 src/fb.rs --- a/src/fb.rs Thu Dec 01 23:37:14 2022 +0200 +++ b/src/fb.rs Fri Dec 02 18:08:40 2022 +0200 @@ -80,7 +80,6 @@ */ use numeric_literals::replace_float_literals; -use std::cmp::Ordering::*; use serde::{Serialize, Deserialize}; use colored::Colorize; use nalgebra::DVector; @@ -156,16 +155,6 @@ InertiaFISTA, } -/// Ergodic tolerance application style -#[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] -#[allow(dead_code)] -pub enum ErgodicTolerance { - /// Non-ergodic iteration-wise tolerance - NonErgodic, - /// Bound after `n`th iteration to `factor` times value on that iteration. - AfterNth{ n : usize, factor : F }, -} - /// Settings for [`pointsource_fb`]. #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] #[serde(default)] @@ -190,8 +179,6 @@ /// Stop looking for predual maximum (where to isert a new point) below /// `tolerance` multiplied by this factor. pub insertion_cutoff_factor : F, - /// Apply tolerance ergodically - pub ergodic_tolerance : ErgodicTolerance, /// Settings for branch and bound refinement when looking for predual maxima pub refinement : RefinementSettings, /// Maximum insertions within each outer iteration @@ -230,7 +217,6 @@ insertion_style : InsertionStyle::Reuse, tolerance : Default::default(), insertion_cutoff_factor : 1.0, - ergodic_tolerance : ErgodicTolerance::NonErgodic, refinement : Default::default(), max_insertions : 100, //bootstrap_insertions : None, @@ -554,10 +540,6 @@ // Initialise iterates let mut μ = DiscreteMeasure::new(); - let mut after_nth_bound = F::INFINITY; - // FIXME: Don't allocate if not needed. - let mut after_nth_accum = opA.zero_observable(); - let mut inner_iters = 0; let mut this_iters = 0; let mut pruned = 0; @@ -628,15 +610,10 @@ }; // Calculate smooth part of surrogate model. - residual *= -τ; - if let ErgodicTolerance::AfterNth{ .. } = config.ergodic_tolerance { - // Negative residual times τ expected here, as set above. - // TODO: is this the correct location? - after_nth_accum += &residual; - } // Using `std::mem::replace` here is not ideal, and expects that `empty_observable` // has no significant overhead. For some reosn Rust doesn't allow us simply moving // the residual and replacing it below before the end of this closure. + residual *= -τ; let r = std::mem::replace(&mut residual, opA.empty_observable()); let minus_τv = preadjA.apply(r); // minus_τv = -τA^*(Aμ^k-b) // TODO: should avoid a second copy of μ here; μ_base already stores a copy. @@ -688,40 +665,9 @@ count > 0 }; - // First do a rough check whether we are within bounds and can stop. - let in_bounds = match config.ergodic_tolerance { - ErgodicTolerance::NonErgodic => { - target_bounds.superset(&d.bounds()) - }, - ErgodicTolerance::AfterNth{ n, factor } => { - // Bound -τ∑_{k=0}^{N-1}[A_*(Aμ^k-b)+α] from above. - match state.iteration().cmp(&n) { - Less => true, - Equal => { - let iter = F::cast_from(state.iteration()); - let mut tmp = preadjA.apply(&after_nth_accum); - let (_, v0) = tmp.maximise(refinement_tolerance, - config.refinement.max_steps); - let v = v0 - iter * τ * α; - after_nth_bound = factor * v; - println!("{}", format!("Set ergodic tolerance to {}", after_nth_bound)); - true - }, - Greater => { - // TODO: can divide after_nth_accum by N, so use basic tolerance on that. - let iter = F::cast_from(state.iteration()); - let mut tmp = preadjA.apply(&after_nth_accum); - tmp.has_upper_bound(after_nth_bound + iter * τ * α, - refinement_tolerance, - config.refinement.max_steps) - } - } - } - }; - // If preliminary check indicates that we are in bonds, and if it otherwise matches // the insertion strategy, skip insertion. - if may_break && in_bounds { + if may_break && target_bounds.superset(&d.bounds()) { break 'insertion (true, d) }