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§
sourcefn initialize(
&mut self,
func: &dyn Function<T, U, E>,
x0: &[T],
bounds: Option<&Vec<Bound<T>>>,
user_data: &mut U,
) -> Result<(), E>
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.
sourcefn step(
&mut self,
i_step: usize,
func: &dyn Function<T, U, E>,
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>
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.
sourcefn check_for_termination(
&mut self,
func: &dyn Function<T, U, E>,
bounds: Option<&Vec<Bound<T>>>,
user_data: &mut U,
) -> Result<bool, 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>
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.
sourcefn get_status(&self) -> &Status<T>
fn get_status(&self) -> &Status<T>
Provided Methods§
sourcefn postprocessing(
&mut self,
func: &dyn Function<T, U, E>,
bounds: Option<&Vec<Bound<T>>>,
user_data: &mut U,
) -> Result<(), E>
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.