Trait ganesh::Function

source ·
pub trait Function<T, U, E>
where T: Float + Scalar + NumAssign,
{ // Required method fn evaluate(&self, x: &[T], user_data: &mut U) -> Result<T, E>; // Provided methods fn evaluate_bounded( &self, x: &[T], bounds: Option<&Vec<Bound<T>>>, user_data: &mut U, ) -> Result<T, E> { ... } fn gradient(&self, x: &[T], user_data: &mut U) -> Result<DVector<T>, E> { ... } fn gradient_bounded( &self, x: &[T], bounds: Option<&Vec<Bound<T>>>, user_data: &mut U, ) -> Result<DVector<T>, E> { ... } fn hessian(&self, x: &[T], user_data: &mut U) -> Result<DMatrix<T>, E> { ... } fn hessian_bounded( &self, x: &[T], bounds: Option<&Vec<Bound<T>>>, user_data: &mut U, ) -> Result<DMatrix<T>, E> { ... } }
Expand description

A trait which describes a function $f(\mathbb{R}^n) \to \mathbb{R}$

Such a function may also take a user_data: &mut U field which can be used to pass external arguments to the function during minimization, or can be modified by the function itself.

The Function trait takes a generic T which represents a numeric scalar, a generic U representing the type of user data/arguments, and a generic E representing any possible errors that might be returned during function execution.

There is also a default implementation of a gradient function which uses a central finite-difference method to evaluate derivatives. If an exact gradient is known, it can be used to speed up gradient-dependent algorithms.

Required Methods§

source

fn evaluate(&self, x: &[T], user_data: &mut U) -> Result<T, E>

The evaluation of the function at a point x with the given arguments/user data.

§Errors

Returns an Err(E) if the evaluation fails. Users should implement this trait to return a std::convert::Infallible if the function evaluation never fails.

Provided Methods§

source

fn evaluate_bounded( &self, x: &[T], bounds: Option<&Vec<Bound<T>>>, user_data: &mut U, ) -> Result<T, E>

The evaluation of the function at a point x with the given arguments/user data. This function assumes x is an internal, unbounded vector, but performs a coordinate transform to bound x when evaluating the function.

§Errors

Returns an Err(E) if the evaluation fails. Users should implement this trait to return a std::convert::Infallible if the function evaluation never fails.

source

fn gradient(&self, x: &[T], user_data: &mut U) -> Result<DVector<T>, E>

The evaluation of the gradient at a point x with the given arguments/user data.

§Errors

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

source

fn gradient_bounded( &self, x: &[T], bounds: Option<&Vec<Bound<T>>>, user_data: &mut U, ) -> Result<DVector<T>, E>

The evaluation of the gradient at a point x with the given arguments/user data. This function assumes x is an internal, unbounded vector, but performs a coordinate transform to bound x when evaluating the function.

§Errors

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

source

fn hessian(&self, x: &[T], user_data: &mut U) -> Result<DMatrix<T>, E>

The evaluation of the hessian at a point x with the given arguments/user data.

§Errors

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

source

fn hessian_bounded( &self, x: &[T], bounds: Option<&Vec<Bound<T>>>, user_data: &mut U, ) -> Result<DMatrix<T>, E>

The evaluation of the hessian at a point x with the given arguments/user data. This function assumes x is an internal, unbounded vector, but performs a coordinate transform to bound x when evaluating the function.

§Errors

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

Implementors§