Trait ganesh::Algorithm

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

    // Provided method
    fn postprocessing(
        &mut self,
        func: &dyn Function<T, U, E>,
        bounds: Option<&Vec<Bound<T>>>,
        user_data: &mut U,
    ) -> 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<T, U, E>, x0: &[T], bounds: Option<&Vec<Bound<T>>>, user_data: &mut U, ) -> 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<T, U, E>, bounds: Option<&Vec<Bound<T>>>, user_data: &mut U, ) -> 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<T, U, E>, bounds: Option<&Vec<Bound<T>>>, user_data: &mut U, ) -> 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.

source

fn get_status(&self) -> &Status<T>

Returns the internal Status of the algorithm. This is a field that all Algorithms should probably contain.

Provided Methods§

source

fn postprocessing( &mut self, func: &dyn Function<T, U, E>, bounds: Option<&Vec<Bound<T>>>, user_data: &mut U, ) -> 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<T, U, E> Algorithm<T, U, E> for BFGS<T, U, E>
where T: RealField + Float,

source§

impl<T, U, E> Algorithm<T, U, E> for LBFGS<T, U, E>
where T: RealField + Float,

source§

impl<T, U, E> Algorithm<T, U, E> for LBFGSB<T, U, E>
where T: RealField + Float + TotalOrder,

source§

impl<T, U, E> Algorithm<T, U, E> for NelderMead<T>
where T: Float + NumAssign + Debug + FromPrimitive + Sum + RealField + Default + 'static + TotalOrder,