Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions crates/argmin/src/core/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ where
let kv = kv.unwrap_or(kv![]);

// Observe after init
self.observers.observe_init(S::NAME, &state, &kv)?;
self.observers
.observe_init(self.solver.name(), &state, &kv)?;
}

state.func_counts(&self.problem);
Expand Down Expand Up @@ -680,7 +681,9 @@ mod tests {
P: Clone,
F: ArgminFloat,
{
const NAME: &'static str = "OptimizationAlgorithm";
fn name(&self) -> &str {
"OptimizationAlgorithm"
}

// Only resets internal_state to 1
fn init(
Expand Down
2 changes: 1 addition & 1 deletion crates/argmin/src/core/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ where
{
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
writeln!(f, "OptimizationResult:")?;
writeln!(f, " Solver: {}", S::NAME)?;
writeln!(f, " Solver: {}", self.solver.name())?;
writeln!(
f,
" param (best): {}",
Expand Down
4 changes: 2 additions & 2 deletions crates/argmin/src/core/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::core::{Error, Problem, State, TerminationReason, TerminationStatus, K
/// P: Clone,
/// F: ArgminFloat
/// {
/// const NAME: &'static str = "OptimizationAlgorithm";
/// fn name(&self) -> &str { "OptimizationAlgorithm" }
///
/// fn init(
/// &mut self,
Expand Down Expand Up @@ -64,7 +64,7 @@ use crate::core::{Error, Problem, State, TerminationReason, TerminationStatus, K
/// ```
pub trait Solver<O, I: State> {
/// Name of the solver. Mainly used in [Observers](`crate::core::observers::Observe`).
const NAME: &'static str;
fn name(&self) -> &str;

/// Initializes the algorithm.
///
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/core/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,9 @@ impl TestSolver {
}

impl<O> Solver<O, IterState<Vec<f64>, (), (), (), (), f64>> for TestSolver {
const NAME: &'static str = "TestSolver";
fn name(&self) -> &str {
"TestSolver"
}

fn next_iter(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/brent/brentopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ where
O: CostFunction<Param = F, Output = F>,
F: ArgminFloat,
{
const NAME: &'static str = "BrentOpt";
fn name(&self) -> &str {
"BrentOpt"
}

fn init(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/brent/brentroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ where
O: CostFunction<Param = F, Output = F>,
F: ArgminFloat,
{
const NAME: &'static str = "BrentRoot";
fn name(&self) -> &str {
"BrentRoot"
}

fn init(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/conjugategradient/cg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ where
R: ArgminMul<F, R> + ArgminMul<F, P> + ArgminConj + ArgminDot<R, F> + ArgminScaledAdd<P, F, R>,
F: ArgminFloat + ArgminL2Norm<F>,
{
const NAME: &'static str = "Conjugate Gradient";
fn name(&self) -> &str {
"Conjugate Gradient"
}

fn init(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/conjugategradient/nonlinear_cg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ where
B: NLCGBetaUpdate<G, P, F>,
F: ArgminFloat,
{
const NAME: &'static str = "Nonlinear Conjugate Gradient";
fn name(&self) -> &str {
"Nonlinear Conjugate Gradient"
}

fn init(
&mut self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ where
F: ArgminFloat,
R: Clone,
{
const NAME: &'static str = "Gauss-Newton method with line search";
fn name(&self) -> &str {
"Gauss-Newton method with line search"
}

fn next_iter(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/gaussnewton/gaussnewton_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ where
+ ArgminDot<P, P>,
F: ArgminFloat,
{
const NAME: &'static str = "Gauss-Newton method";
fn name(&self) -> &str {
"Gauss-Newton method"
}

fn init(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/goldensectionsearch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ where
O: CostFunction<Param = F, Output = F>,
F: ArgminFloat,
{
const NAME: &'static str = "Golden-section search";
fn name(&self) -> &str {
"Golden-section search"
}

fn init(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/gradientdescent/steepestdescent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ where
L: Clone + LineSearch<G, F> + Solver<O, IterState<P, G, (), (), (), F>>,
F: ArgminFloat,
{
const NAME: &'static str = "Steepest Descent";
fn name(&self) -> &str {
"Steepest Descent"
}

fn next_iter(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/landweber/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ where
P: Clone + ArgminScaledSub<G, F, P>,
F: ArgminFloat,
{
const NAME: &'static str = "Landweber";
fn name(&self) -> &str {
"Landweber"
}

fn next_iter(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/linesearch/backtracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ where
L: LineSearchCondition<G, G, F>,
F: ArgminFloat,
{
const NAME: &'static str = "Backtracking line search";
fn name(&self) -> &str {
"Backtracking line search"
}

fn init(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/linesearch/hagerzhang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,9 @@ where
G: Clone + ArgminDot<G, F>,
F: ArgminFloat,
{
const NAME: &'static str = "Hager-Zhang line search";
fn name(&self) -> &str {
"Hager-Zhang line search"
}

fn init(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/linesearch/morethuente.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ where
G: Clone + ArgminDot<G, F>,
F: ArgminFloat,
{
const NAME: &'static str = "More-Thuente Line search";
fn name(&self) -> &str {
"More-Thuente Line search"
}

fn init(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/neldermead/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ where
P: Clone + ArgminSub<P, P> + ArgminAdd<P, P> + ArgminMul<F, P>,
F: ArgminFloat + std::iter::Sum<F>,
{
const NAME: &'static str = "Nelder-Mead method";
fn name(&self) -> &str {
"Nelder-Mead method"
}

fn init(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/newton/newton_cg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ where
L: Clone + LineSearch<P, F> + Solver<O, IterState<P, G, (), (), (), F>>,
F: ArgminFloat + ArgminL2Norm<F>,
{
const NAME: &'static str = "Newton-CG";
fn name(&self) -> &str {
"Newton-CG"
}

fn next_iter(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/newton/newton_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ where
H: ArgminInv<H> + ArgminDot<G, P>,
F: ArgminFloat,
{
const NAME: &'static str = "Newton method";
fn name(&self) -> &str {
"Newton method"
}

fn next_iter(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/particleswarm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ where
F: ArgminFloat,
R: Rng,
{
const NAME: &'static str = "Particle Swarm Optimization";
fn name(&self) -> &str {
"Particle Swarm Optimization"
}

fn init(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/quasinewton/bfgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ where
L: Clone + LineSearch<P, F> + Solver<O, IterState<P, G, (), (), (), F>>,
F: ArgminFloat,
{
const NAME: &'static str = "BFGS";
fn name(&self) -> &str {
"BFGS"
}

fn init(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/quasinewton/dfp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ where
L: Clone + LineSearch<P, F> + Solver<O, IterState<P, G, (), (), (), F>>,
F: ArgminFloat,
{
const NAME: &'static str = "DFP";
fn name(&self) -> &str {
"DFP"
}

fn init(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/quasinewton/lbfgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,9 @@ where
+ Solver<LineSearchProblem<O, P, G, F>, IterState<P, G, (), (), (), F>>,
F: ArgminFloat,
{
const NAME: &'static str = "L-BFGS";
fn name(&self) -> &str {
"L-BFGS"
}

fn init(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/quasinewton/sr1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ where
L: Clone + LineSearch<P, F> + Solver<O, IterState<P, G, (), (), (), F>>,
F: ArgminFloat,
{
const NAME: &'static str = "SR1";
fn name(&self) -> &str {
"SR1"
}

fn init(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/quasinewton/sr1_trustregion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ where
R: Clone + TrustRegionRadius<F> + Solver<O, IterState<P, G, (), B, (), F>>,
F: ArgminFloat + ArgminL2Norm<F>,
{
const NAME: &'static str = "SR1 trust region";
fn name(&self) -> &str {
"SR1 trust region"
}

fn init(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/simulatedannealing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,9 @@ where
F: ArgminFloat,
R: Rng,
{
const NAME: &'static str = "Simulated Annealing";
fn name(&self) -> &str {
"Simulated Annealing"
}
fn init(
&mut self,
problem: &mut Problem<O>,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/trustregion/cauchypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ where
G: ArgminMul<F, P> + ArgminWeightedDot<G, F, H> + ArgminL2Norm<F>,
F: ArgminFloat,
{
const NAME: &'static str = "Cauchy Point";
fn name(&self) -> &str {
"Cauchy Point"
}

fn next_iter(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/trustregion/dogleg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ where
H: ArgminInv<H> + ArgminDot<P, P>,
F: ArgminFloat,
{
const NAME: &'static str = "Dogleg";
fn name(&self) -> &str {
"Dogleg"
}

fn next_iter(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/trustregion/steihaug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ where
H: ArgminDot<P, P>,
F: ArgminFloat,
{
const NAME: &'static str = "Steihaug";
fn name(&self) -> &str {
"Steihaug"
}

fn init(
&mut self,
Expand Down
4 changes: 3 additions & 1 deletion crates/argmin/src/solver/trustregion/trustregion_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ where
R: Clone + TrustRegionRadius<F> + Solver<O, IterState<P, G, (), H, (), F>>,
F: ArgminFloat,
{
const NAME: &'static str = "Trust region";
fn name(&self) -> &str {
"Trust region"
}

fn init(
&mut self,
Expand Down
2 changes: 1 addition & 1 deletion media/book/src/implementing_solver.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ where
F: ArgminFloat,
{
// This gives the solver a name which will be used for logging
const NAME: &'static str = "Landweber";
fn name(&self) -> &str { "Landweber" }

// Defines the computations performed in a single iteration.
fn next_iter(
Expand Down