Skip to main content

Objective

Trait Objective 

Source
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§

Source

type Error

What stops an evaluation, such as an error in the caller’s function or an interrupt.

Required Methods§

Source

fn value(&mut self, x: &[F]) -> Result<F, Self::Error>

The value at x.

Provided Methods§

Source

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.

Source

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.

Source

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.

Source

fn gradient(&mut self, x: &[F], g: &mut [F]) -> Result<(), Self::Error>

The gradient at x, into g. Methods call it only where has_gradient is true.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<F, E, V, G> Objective<F> for Differentiable<V, G>
where V: FnMut(&[F]) -> Result<F, E>, G: FnMut(&[F], &mut [F]) -> Result<(), E>,

Source§

type Error = E

Source§

impl<F, E, V> Objective<F> for V
where V: FnMut(&[F]) -> Result<F, E>,

Source§

type Error = E