Trait argmin::core::Solver

source ·
pub trait Solver<O, I: State> {
    const NAME: &'static str;

    // Required method
    fn next_iter(
        &mut self,
        problem: &mut Problem<O>,
        state: I
    ) -> Result<(I, Option<KV>), Error>;

    // Provided methods
    fn init(
        &mut self,
        _problem: &mut Problem<O>,
        state: I
    ) -> Result<(I, Option<KV>), Error> { ... }
    fn terminate_internal(&mut self, state: &I) -> TerminationStatus { ... }
    fn terminate(&mut self, _state: &I) -> TerminationStatus { ... }
}
Expand description

The interface all solvers are required to implement.

Every solver needs to implement this trait in order to function with the Executor. It handles initialization (init), each iteration of the solver (next_iter), and termination of the algorithm (terminate and terminate_internal). Only next_iter is mandatory to implement, all others provide default implementations.

A Solver should be (de)serializable in order to work with checkpointing.

Example

use argmin::core::{
    ArgminFloat, Solver, IterState, CostFunction, Error, KV, Problem, TerminationReason, TerminationStatus
};

#[derive(Clone)]
struct OptimizationAlgorithm {}

impl<O, P, G, J, H, R, F> Solver<O, IterState<P, G, J, H, R, F>> for OptimizationAlgorithm
where
    O: CostFunction<Param = P, Output = F>,
    P: Clone,
    F: ArgminFloat
{
    const NAME: &'static str = "OptimizationAlgorithm";

    fn init(
        &mut self,
        problem: &mut Problem<O>,
        state: IterState<P, G, J, H, R, F>,
    ) -> Result<(IterState<P, G, J, H, R, F>, Option<KV>), Error> {
        // Initialize algorithm, update `state`.
        // Implementing this method is optional.
        Ok((state, None))
    }

    fn next_iter(
        &mut self,
        problem: &mut Problem<O>,
        state: IterState<P, G, J, H, R, F>,
    ) -> Result<(IterState<P, G, J, H, R, F>, Option<KV>), Error> {
        // Compute single iteration of algorithm, update `state`.
        // Implementing this method is required.
        Ok((state, None))
    }
     
    fn terminate(&mut self, state: &IterState<P, G, J, H, R, F>) -> TerminationStatus {
        // Check if stopping criteria are met.
        // Implementing this method is optional.
        TerminationStatus::NotTerminated
    }
}

Required Associated Constants§

source

const NAME: &'static str

Name of the solver. Mainly used in Observers.

Required Methods§

source

fn next_iter( &mut self, problem: &mut Problem<O>, state: I ) -> Result<(I, Option<KV>), Error>

Computes a single iteration of the algorithm and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers.

Provided Methods§

source

fn init( &mut self, _problem: &mut Problem<O>, state: I ) -> Result<(I, Option<KV>), Error>

Initializes the algorithm.

Executed before any iterations are performed and has access to the optimization problem definition and the internal state of the solver. Returns an updated state and optionally a KV which holds key-value pairs used in Observers. The default implementation returns the unaltered state and no KV.

source

fn terminate_internal(&mut self, state: &I) -> TerminationStatus

Checks whether basic termination reasons apply.

Terminate if

  1. algorithm was terminated somewhere else in the Executor
  2. iteration count exceeds maximum number of iterations
  3. best cost is lower than or equal to the target cost

This can be overwritten; however it is not advised. It is recommended to implement other stopping criteria via (terminate.

source

fn terminate(&mut self, _state: &I) -> TerminationStatus

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal.

This method has access to the internal state and returns an TerminationReason.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<O> Solver<O, IterState<Vec<f64>, (), (), (), (), f64>> for TestSolver

source§

const NAME: &'static str = "TestSolver"

source§

impl<O, F> Solver<O, IterState<F, (), (), (), (), F>> for BrentOpt<F>
where O: CostFunction<Param = F, Output = F>, F: ArgminFloat,

source§

const NAME: &'static str = "BrentOpt"

source§

impl<O, F> Solver<O, IterState<F, (), (), (), (), F>> for BrentRoot<F>
where O: CostFunction<Param = F, Output = F>, F: ArgminFloat,

source§

const NAME: &'static str = "BrentRoot"

source§

impl<O, F> Solver<O, IterState<F, (), (), (), (), F>> for GoldenSectionSearch<F>
where O: CostFunction<Param = F, Output = F>, F: ArgminFloat,

source§

const NAME: &'static str = "Golden-section search"

source§

impl<O, F, P, G> Solver<O, IterState<P, G, (), (), (), F>> for Landweber<F>
where O: Gradient<Param = P, Gradient = G>, P: Clone + ArgminScaledSub<G, F, P>, F: ArgminFloat,

source§

const NAME: &'static str = "Landweber"

source§

impl<O, F, P, G, H> Solver<O, IterState<P, G, (), H, (), F>> for CauchyPoint<F>
where O: Gradient<Param = P, Gradient = G> + Hessian<Param = P, Hessian = H>, P: Clone + ArgminMul<F, P> + ArgminWeightedDot<P, F, H>, G: ArgminMul<F, P> + ArgminWeightedDot<G, F, H> + ArgminL2Norm<F>, F: ArgminFloat,

source§

const NAME: &'static str = "Cauchy Point"

source§

impl<O, F, P, H> Solver<O, IterState<P, P, (), H, (), F>> for Dogleg<F>
where O: Gradient<Param = P, Gradient = P> + Hessian<Param = P, Hessian = H>, P: Clone + ArgminMul<F, P> + ArgminL2Norm<F> + ArgminDot<P, F> + ArgminAdd<P, P> + ArgminSub<P, P>, H: ArgminInv<H> + ArgminDot<P, P>, F: ArgminFloat,

source§

const NAME: &'static str = "Dogleg"

source§

impl<O, L, F, P, G, J, U, R> Solver<O, IterState<P, G, J, (), R, F>> for GaussNewtonLS<L, F>
where O: Operator<Param = P, Output = U> + Jacobian<Param = P, Jacobian = J>, P: Clone + ArgminMul<F, P>, G: Clone, U: ArgminL2Norm<F>, J: Clone + ArgminTranspose<J> + ArgminInv<J> + ArgminDot<J, J> + ArgminDot<G, P> + ArgminDot<U, G>, L: Clone + LineSearch<P, F> + Solver<LineSearchProblem<O, F>, IterState<P, G, (), (), R, F>>, F: ArgminFloat, R: Clone,

source§

const NAME: &'static str = "Gauss-Newton method with line search"

source§

impl<O, L, P, G, F> Solver<O, IterState<P, G, (), (), (), F>> for SteepestDescent<L>
where O: CostFunction<Param = P, Output = F> + Gradient<Param = P, Gradient = G>, P: Clone, G: Clone + ArgminMul<F, G>, L: Clone + LineSearch<G, F> + Solver<O, IterState<P, G, (), (), (), F>>, F: ArgminFloat,

source§

const NAME: &'static str = "Steepest Descent"

source§

impl<O, L, P, G, F> Solver<O, IterState<P, G, (), (), (), F>> for LBFGS<L, P, G, F>
where O: CostFunction<Param = P, Output = F> + Gradient<Param = P, Gradient = G>, P: Clone + ArgminSub<P, P> + ArgminSub<F, P> + ArgminAdd<P, P> + ArgminAdd<F, P> + ArgminDot<G, F> + ArgminMul<F, P> + ArgminMul<P, P> + ArgminMul<G, P> + ArgminL1Norm<F> + ArgminSignum + ArgminZeroLike + ArgminMinMax, G: Clone + ArgminL2Norm<F> + ArgminSub<G, G> + ArgminAdd<G, G> + ArgminAdd<P, G> + ArgminDot<G, F> + ArgminDot<P, F> + ArgminMul<F, G> + ArgminMul<F, P> + ArgminZeroLike + ArgminMinMax, L: Clone + LineSearch<P, F> + Solver<LineSearchProblem<O, P, G, F>, IterState<P, G, (), (), (), F>>, F: ArgminFloat,

source§

const NAME: &'static str = "L-BFGS"

source§

impl<O, L, P, G, H, F> Solver<O, IterState<P, G, (), H, (), F>> for NewtonCG<L, F>
where O: Gradient<Param = P, Gradient = G> + Hessian<Param = P, Hessian = H>, P: Clone + ArgminSub<P, P> + ArgminDot<P, F> + ArgminScaledAdd<P, F, P> + ArgminMul<F, P> + ArgminConj + ArgminZeroLike, G: ArgminL2Norm<F> + ArgminMul<F, P>, H: Clone + ArgminDot<P, P>, L: Clone + LineSearch<P, F> + Solver<O, IterState<P, G, (), (), (), F>>, F: ArgminFloat + ArgminL2Norm<F>,

source§

const NAME: &'static str = "Newton-CG"

source§

impl<O, L, P, G, H, F> Solver<O, IterState<P, G, (), H, (), F>> for BFGS<L, F>
where O: CostFunction<Param = P, Output = F> + Gradient<Param = P, Gradient = G>, P: Clone + ArgminSub<P, P> + ArgminDot<G, H> + ArgminDot<P, H>, G: Clone + ArgminL2Norm<F> + ArgminMul<F, P> + ArgminDot<P, F> + ArgminSub<G, G>, H: ArgminSub<H, H> + ArgminDot<G, G> + ArgminDot<H, H> + ArgminAdd<H, H> + ArgminMul<F, H> + ArgminTranspose<H> + ArgminEye, L: Clone + LineSearch<P, F> + Solver<O, IterState<P, G, (), (), (), F>>, F: ArgminFloat,

source§

const NAME: &'static str = "BFGS"

source§

impl<O, L, P, G, H, F> Solver<O, IterState<P, G, (), H, (), F>> for DFP<L, F>
where O: CostFunction<Param = P, Output = F> + Gradient<Param = P, Gradient = G>, P: Clone + ArgminSub<P, P> + ArgminDot<G, F> + ArgminDot<P, H> + ArgminMul<F, P>, G: Clone + ArgminSub<G, G> + ArgminL2Norm<F> + ArgminDot<P, F>, H: Clone + ArgminSub<H, H> + ArgminDot<G, P> + ArgminAdd<H, H> + ArgminMul<F, H>, L: Clone + LineSearch<P, F> + Solver<O, IterState<P, G, (), (), (), F>>, F: ArgminFloat,

source§

const NAME: &'static str = "DFP"

source§

impl<O, L, P, G, H, F> Solver<O, IterState<P, G, (), H, (), F>> for SR1<L, F>
where O: CostFunction<Param = P, Output = F> + Gradient<Param = P, Gradient = G>, P: Clone + ArgminSub<P, P> + ArgminDot<G, F> + ArgminDot<P, F> + ArgminDot<P, H> + ArgminL2Norm<F> + ArgminMul<F, P>, G: Clone + ArgminSub<P, P> + ArgminL2Norm<F> + ArgminSub<G, G>, H: ArgminDot<G, P> + ArgminDot<P, P> + ArgminAdd<H, H> + ArgminMul<F, H>, L: Clone + LineSearch<P, F> + Solver<O, IterState<P, G, (), (), (), F>>, F: ArgminFloat,

source§

const NAME: &'static str = "SR1"

source§

impl<O, P, F> Solver<O, IterState<P, (), (), (), (), F>> for NelderMead<P, F>
where O: CostFunction<Param = P, Output = F>, P: Clone + ArgminSub<P, P> + ArgminAdd<P, P> + ArgminMul<F, P>, F: ArgminFloat + Sum<F>,

source§

const NAME: &'static str = "Nelder-Mead method"

source§

impl<O, P, F, R> Solver<O, IterState<P, (), (), (), (), F>> for SimulatedAnnealing<F, R>
where O: CostFunction<Param = P, Output = F> + Anneal<Param = P, Output = P, Float = F>, P: Clone, F: ArgminFloat, R: Rng,

source§

const NAME: &'static str = "Simulated Annealing"

source§

impl<O, P, F, R> Solver<O, PopulationState<Particle<P, F>, F>> for ParticleSwarm<P, F, R>
where O: CostFunction<Param = P, Output = F> + SyncAlias, P: Clone + SyncAlias + ArgminAdd<P, P> + ArgminSub<P, P> + ArgminMul<F, P> + ArgminZeroLike + ArgminRandom + ArgminMinMax, F: ArgminFloat, R: Rng,

source§

const NAME: &'static str = "Particle Swarm Optimization"

source§

impl<O, P, G, H, F> Solver<O, IterState<P, G, (), H, (), F>> for Newton<F>
where O: Gradient<Param = P, Gradient = G> + Hessian<Param = P, Hessian = H>, P: Clone + ArgminScaledSub<P, F, P>, H: ArgminInv<H> + ArgminDot<G, P>, F: ArgminFloat,

source§

const NAME: &'static str = "Newton method"

source§

impl<O, P, G, L, B, F> Solver<O, IterState<P, G, (), (), (), F>> for NonlinearConjugateGradient<P, L, B, F>
where O: CostFunction<Param = P, Output = F> + Gradient<Param = P, Gradient = G>, P: Clone + ArgminAdd<P, P> + ArgminMul<F, P>, G: Clone + ArgminMul<F, P> + ArgminDot<G, F> + ArgminL2Norm<F>, L: Clone + LineSearch<P, F> + Solver<O, IterState<P, G, (), (), (), F>>, B: NLCGBetaUpdate<G, P, F>, F: ArgminFloat,

source§

const NAME: &'static str = "Nonlinear Conjugate Gradient"

source§

impl<O, P, G, L, F> Solver<O, IterState<P, G, (), (), (), F>> for BacktrackingLineSearch<P, G, L, F>
where P: Clone + ArgminScaledAdd<G, F, P>, G: ArgminScaledAdd<G, F, G>, O: CostFunction<Param = P, Output = F> + Gradient<Param = P, Gradient = G>, L: LineSearchCondition<G, G, F>, F: ArgminFloat,

source§

const NAME: &'static str = "Backtracking line search"

source§

impl<O, P, J, R, F> Solver<O, IterState<P, (), J, (), R, F>> for GaussNewton<F>
where O: Operator<Param = P, Output = R> + Jacobian<Param = P, Jacobian = J>, P: Clone + ArgminSub<P, P> + ArgminMul<F, P>, R: ArgminL2Norm<F>, J: Clone + ArgminTranspose<J> + ArgminInv<J> + ArgminDot<J, J> + ArgminDot<R, P> + ArgminDot<P, P>, F: ArgminFloat,

source§

const NAME: &'static str = "Gauss-Newton method"

source§

impl<O, R, F, P, G, H> Solver<O, IterState<P, G, (), H, (), F>> for TrustRegion<R, F>
where O: CostFunction<Param = P, Output = F> + Gradient<Param = P, Gradient = G> + Hessian<Param = P, Hessian = H>, P: Clone + ArgminL2Norm<F> + ArgminDot<P, F> + ArgminDot<G, F> + ArgminAdd<P, P>, G: Clone, H: Clone + ArgminDot<P, P>, R: Clone + TrustRegionRadius<F> + Solver<O, IterState<P, G, (), H, (), F>>, F: ArgminFloat,

source§

const NAME: &'static str = "Trust region"

source§

impl<O, R, P, G, B, F> Solver<O, IterState<P, G, (), B, (), F>> for SR1TrustRegion<R, F>
where O: CostFunction<Param = P, Output = F> + Gradient<Param = P, Gradient = G> + Hessian<Param = P, Hessian = B>, P: Clone + ArgminSub<P, P> + ArgminAdd<P, P> + ArgminDot<P, F> + ArgminDot<P, B> + ArgminL2Norm<F> + ArgminZeroLike, G: Clone + ArgminL2Norm<F> + ArgminDot<P, F> + ArgminSub<G, P>, B: Clone + ArgminDot<P, P> + ArgminAdd<B, B> + ArgminMul<F, B>, R: Clone + TrustRegionRadius<F> + Solver<O, IterState<P, G, (), B, (), F>>, F: ArgminFloat + ArgminL2Norm<F>,

source§

const NAME: &'static str = "SR1 trust region"

source§

impl<P, G, O, F> Solver<O, IterState<P, G, (), (), (), F>> for HagerZhangLineSearch<P, G, F>
where O: CostFunction<Param = P, Output = F> + Gradient<Param = P, Gradient = G>, P: Clone + ArgminDot<G, F> + ArgminScaledAdd<G, F, P>, G: Clone + ArgminDot<G, F>, F: ArgminFloat,

source§

const NAME: &'static str = "Hager-Zhang line search"

source§

impl<P, G, O, F> Solver<O, IterState<P, G, (), (), (), F>> for MoreThuenteLineSearch<P, G, F>
where O: CostFunction<Param = P, Output = F> + Gradient<Param = P, Gradient = G>, P: Clone + ArgminDot<G, F> + ArgminScaledAdd<G, F, P>, G: Clone + ArgminDot<G, F>, F: ArgminFloat,

source§

const NAME: &'static str = "More-Thuente Line search"

source§

impl<P, O, F, H> Solver<O, IterState<P, P, (), H, (), F>> for Steihaug<P, F>
where P: Clone + ArgminMul<F, P> + ArgminL2Norm<F> + ArgminDot<P, F> + ArgminAdd<P, P> + ArgminZeroLike, H: ArgminDot<P, P>, F: ArgminFloat,

source§

const NAME: &'static str = "Steihaug"

source§

impl<P, O, R, F> Solver<O, IterState<P, (), (), (), R, F>> for ConjugateGradient<P, F>
where O: Operator<Param = P, Output = P>, P: Clone + ArgminDot<P, F> + ArgminSub<P, R> + ArgminScaledAdd<P, F, P> + ArgminConj, R: ArgminMul<F, R> + ArgminMul<F, P> + ArgminConj + ArgminDot<R, F> + ArgminScaledAdd<P, F, R>, F: ArgminFloat + ArgminL2Norm<F>,

source§

const NAME: &'static str = "Conjugate Gradient"