Skip to main content

Objective

Trait Objective 

Source
pub trait Objective<F: Float> {
    // Required methods
    fn dim(&self) -> usize;
    fn eval_grad(&mut self, x: &[F]) -> (F, Vec<F>);

    // Provided methods
    fn eval_hessian(&mut self, x: &[F]) -> (F, Vec<F>, Vec<Vec<F>>) { ... }
    fn hvp(&mut self, x: &[F], v: &[F]) -> (Vec<F>, Vec<F>) { ... }
}
Expand description

Trait for optimization objectives.

Implementors provide function evaluation and gradient computation. Methods take &mut self to allow caching, eval counting, and internal buffers.

Required Methods§

Source

fn dim(&self) -> usize

Number of input variables.

Source

fn eval_grad(&mut self, x: &[F]) -> (F, Vec<F>)

Evaluate the objective and its gradient at x.

Returns (f(x), ∇f(x)).

Provided Methods§

Source

fn eval_hessian(&mut self, x: &[F]) -> (F, Vec<F>, Vec<Vec<F>>)

Evaluate the objective, gradient, and full Hessian at x.

Returns (f(x), ∇f(x), H(x)) where H[i][j] = ∂²f/∂x_i∂x_j.

Default implementation panics. Only solvers that need the Hessian call this.

Source

fn hvp(&mut self, x: &[F], v: &[F]) -> (Vec<F>, Vec<F>)

Compute the Hessian-vector product H(x)·v.

Returns (∇f(x), H(x)·v).

Default implementation panics. Only solvers that need HVP call this.

Implementors§