Added command line option for (power) tolerance

Fri, 09 Dec 2022 14:10:48 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Fri, 09 Dec 2022 14:10:48 +0200
changeset 20
90f77ad9a98d
parent 17
de8d43ebfd0d
child 21
0771706f472f
child 22
9fb8ecb3da74

Added command line option for (power) tolerance

src/main.rs file | annotate | diff | comparison | revisions
src/run.rs file | annotate | diff | comparison | revisions
--- a/src/main.rs	Wed Dec 07 08:17:46 2022 +0200
+++ b/src/main.rs	Fri Dec 09 14:10:48 2022 +0200
@@ -195,6 +195,11 @@
     /// Either the string "none", or a radius value for heuristic merging.
     /// Only affects FB, FISTA, and PDPS.
     final_merging : Option<SpikeMergingMethod<F>>,
+
+    #[arg(long, value_names = &["ε", "θ", "p"])]
+    /// Set the tolerance to ε_k = ε/(1+θk)^p
+    tolerance : Option<Vec<F>>,
+
 }
 
 /// The entry point for the program.
--- a/src/run.rs	Wed Dec 07 08:17:46 2022 +0200
+++ b/src/run.rs	Fri Dec 09 14:10:48 2022 +0200
@@ -64,6 +64,7 @@
 use crate::seminorms::*;
 use crate::plot::*;
 use crate::{AlgorithmOverrides, CommandLineArgs};
+use crate::tolerance::Tolerance;
 
 /// Available algorithms and their configurations
 #[derive(Copy, Clone, Debug, Serialize, Deserialize)]
@@ -73,6 +74,11 @@
     PDPS(PDPSConfig<F>),
 }
 
+fn unpack_tolerance<F : Float>(v : &Vec<F>) -> Tolerance<F> {
+    assert!(v.len() == 3);
+    Tolerance::Power { initial : v[0], factor : v[1], exponent : v[2] }
+}
+
 impl<F : ClapFloat> AlgorithmConfig<F> {
     /// Override supported parameters based on the command line.
     pub fn cli_override(self, cli : &AlgorithmOverrides<F>) -> Self {
@@ -85,6 +91,7 @@
                 merge_every : cli.merge_every.unwrap_or(g.merge_every),
                 merging : cli.merging.clone().unwrap_or(g.merging),
                 final_merging : cli.final_merging.clone().unwrap_or(g.final_merging),
+                tolerance: cli.tolerance.as_ref().map(unpack_tolerance).unwrap_or(g.tolerance),
                 .. g
             }
         };
@@ -105,6 +112,7 @@
             }),
             FW(fw) => FW(FWConfig {
                 merging : cli.merging.clone().unwrap_or(fw.merging),
+                tolerance : cli.tolerance.as_ref().map(unpack_tolerance).unwrap_or(fw.tolerance),
                 .. fw
             })
         }

mercurial