pub trait Objective<F> {
type Error;
// Required method
fn value(&mut self, x: &[F]) -> Result<F, Self::Error>;
// Provided methods
fn batch(&self) -> bool { ... }
fn values(&mut self, xs: &[F], out: &mut [F]) -> Result<(), Self::Error> { ... }
fn has_gradient(&self) -> bool { ... }
fn gradient(&mut self, x: &[F], g: &mut [F]) -> Result<(), Self::Error> { ... }
}Expand description
A function of a slice of F to minimize. A closure that returns a Result is one. Differentiable adds a gradient.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn batch(&self) -> bool
fn batch(&self) -> bool
Whether values evaluates a batch of points in one call. Nelder–Mead evaluates its first simplex and each shrink as a batch, and differential evolution each generation. Without batch, a search calls value on each point.
Sourcefn values(&mut self, xs: &[F], out: &mut [F]) -> Result<(), Self::Error>
fn values(&mut self, xs: &[F], out: &mut [F]) -> Result<(), Self::Error>
The value at each row of xs, into out, with xs.len() / out.len() items to a row. Methods call it only where batch is true.
Sourcefn has_gradient(&self) -> bool
fn has_gradient(&self) -> bool
Whether gradient gives the gradient. L-BFGS needs one, and Method::choose picks L-BFGS for an objective that has one.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".