pub trait Function<U, E> {
// Required method
fn evaluate(&self, x: &[Float], user_data: &mut U) -> Result<Float, E>;
// Provided methods
fn evaluate_bounded(
&self,
x: &[Float],
bounds: Option<&Vec<Bound>>,
user_data: &mut U,
) -> Result<Float, E> { ... }
fn gradient(
&self,
x: &[Float],
user_data: &mut U,
) -> Result<DVector<Float>, E> { ... }
fn gradient_bounded(
&self,
x: &[Float],
bounds: Option<&Vec<Bound>>,
user_data: &mut U,
) -> Result<DVector<Float>, E> { ... }
fn hessian(
&self,
x: &[Float],
user_data: &mut U,
) -> Result<DMatrix<Float>, E> { ... }
fn hessian_bounded(
&self,
x: &[Float],
bounds: Option<&Vec<Bound>>,
user_data: &mut U,
) -> Result<DMatrix<Float>, 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§
Sourcefn evaluate(&self, x: &[Float], user_data: &mut U) -> Result<Float, E>
fn evaluate(&self, x: &[Float], user_data: &mut U) -> Result<Float, 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§
Sourcefn evaluate_bounded(
&self,
x: &[Float],
bounds: Option<&Vec<Bound>>,
user_data: &mut U,
) -> Result<Float, E>
fn evaluate_bounded( &self, x: &[Float], bounds: Option<&Vec<Bound>>, user_data: &mut U, ) -> Result<Float, 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.
Sourcefn gradient(&self, x: &[Float], user_data: &mut U) -> Result<DVector<Float>, E>
fn gradient(&self, x: &[Float], user_data: &mut U) -> Result<DVector<Float>, 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.
Sourcefn gradient_bounded(
&self,
x: &[Float],
bounds: Option<&Vec<Bound>>,
user_data: &mut U,
) -> Result<DVector<Float>, E>
fn gradient_bounded( &self, x: &[Float], bounds: Option<&Vec<Bound>>, user_data: &mut U, ) -> Result<DVector<Float>, 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.
Sourcefn hessian(&self, x: &[Float], user_data: &mut U) -> Result<DMatrix<Float>, E>
fn hessian(&self, x: &[Float], user_data: &mut U) -> Result<DMatrix<Float>, 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.
Sourcefn hessian_bounded(
&self,
x: &[Float],
bounds: Option<&Vec<Bound>>,
user_data: &mut U,
) -> Result<DMatrix<Float>, E>
fn hessian_bounded( &self, x: &[Float], bounds: Option<&Vec<Bound>>, user_data: &mut U, ) -> Result<DMatrix<Float>, 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.