ganesh

Trait Algorithm

Source
pub trait Algorithm<U, E>: DynClone {
    // Required methods
    fn initialize(
        &mut self,
        func: &dyn Function<U, E>,
        x0: &[Float],
        bounds: Option<&Vec<Bound>>,
        user_data: &mut U,
        status: &mut Status,
    ) -> Result<(), E>;
    fn step(
        &mut self,
        i_step: usize,
        func: &dyn Function<U, E>,
        bounds: Option<&Vec<Bound>>,
        user_data: &mut U,
        status: &mut Status,
    ) -> Result<(), E>;
    fn check_for_termination(
        &mut self,
        func: &dyn Function<U, E>,
        bounds: Option<&Vec<Bound>>,
        user_data: &mut U,
        status: &mut Status,
    ) -> Result<bool, E>;

    // Provided method
    fn postprocessing(
        &mut self,
        func: &dyn Function<U, E>,
        bounds: Option<&Vec<Bound>>,
        user_data: &mut U,
        status: &mut Status,
    ) -> Result<(), E> { ... }
}
Expand description

A trait representing a minimization algorithm.

This trait is implemented for the algorithms found in the algorithms module, and contains all the methods needed to be run by a Minimizer.

Required Methods§

Source

fn initialize( &mut self, func: &dyn Function<U, E>, x0: &[Float], bounds: Option<&Vec<Bound>>, user_data: &mut U, status: &mut Status, ) -> Result<(), E>

Any setup work done before the main steps of the algorithm should be done here.

§Errors

Returns an Err(E) if the evaluation fails. See Function::evaluate for more information.

Source

fn step( &mut self, i_step: usize, func: &dyn Function<U, E>, bounds: Option<&Vec<Bound>>, user_data: &mut U, status: &mut Status, ) -> Result<(), E>

The main “step” of an algorithm, which is repeated until termination conditions are met or the max number of steps have been taken.

§Errors

Returns an Err(E) if the evaluation fails. See Function::evaluate for more information.

Source

fn check_for_termination( &mut self, func: &dyn Function<U, E>, bounds: Option<&Vec<Bound>>, user_data: &mut U, status: &mut Status, ) -> Result<bool, E>

Runs any termination/convergence checks and returns true if the algorithm has converged. Developers should also update the internal Status of the algorithm here if converged.

§Errors

Returns an Err(E) if the evaluation fails. See Function::evaluate for more information.

Provided Methods§

Source

fn postprocessing( &mut self, func: &dyn Function<U, E>, bounds: Option<&Vec<Bound>>, user_data: &mut U, status: &mut Status, ) -> Result<(), E>

Runs any steps needed by the Algorithm after termination or convergence. This will run regardless of whether the Algorithm converged.

§Errors

Returns an Err(E) if the evaluation fails. See Function::evaluate for more information.

Implementors§

Source§

impl<U, E> Algorithm<U, E> for BFGS<U, E>
where U: Clone, E: Clone,

Source§

impl<U, E> Algorithm<U, E> for LBFGS<U, E>
where U: Clone, E: Clone,

Source§

impl<U, E> Algorithm<U, E> for LBFGSB<U, E>
where U: Clone, E: Clone,

Source§

impl<U, E> Algorithm<U, E> for NelderMead