rusvm/newton/
params.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Clone, Debug, Serialize, Deserialize)]
4/// Parameters of Newton's method
5pub struct Params {
6    /// Termination tolerance
7    pub tol: f64,
8    /// Maximum number of steps
9    pub max_steps: usize,
10    /// Frequency of logging (`0` for no logging)
11    pub verbose: usize,
12    /// Time limit (in seconds)
13    pub time_limit: f64,
14    /// Parameter σ in Armijo stepsize selection
15    pub sigma: f64,
16    /// Parameter η in Armijo stepsize selection
17    pub eta: f64,
18    /// Maximum number of steps in Armijo stepsize selection
19    pub max_back_steps: usize,
20}
21
22impl Params {
23    /// Creates a new [`Params`] struct with default parameter values.
24    pub fn new() -> Self {
25        Params {
26            tol: 1e-8,
27            max_steps: usize::MAX,
28            verbose: 0,
29            time_limit: f64::INFINITY,
30            sigma: 0.001,
31            eta: 0.1,
32            max_back_steps: 8,
33        }
34    }
35
36    /// Updates the verbosity level.
37    pub fn with_verbose(mut self, verbose: usize) -> Self {
38        self.verbose = verbose;
39        self
40    }
41
42    /// Updates the termination tolerance.
43    pub fn with_tol(mut self, tol: f64) -> Self {
44        self.tol = tol;
45        self
46    }
47
48    /// Updates the time limit.
49    pub fn with_time_limit(mut self, time_limit: f64) -> Self {
50        self.time_limit = time_limit;
51        self
52    }
53
54    /// Updates the maximum number of steps.
55    pub fn with_max_steps(mut self, max_steps: usize) -> Self {
56        self.max_steps = max_steps;
57        self
58    }
59}