pub trait Objective {
// Required methods
fn value(&self, x: &[f64]) -> f64;
fn grad(&self, x: &[f64]) -> Vec<f64>;
// Provided method
fn hessian(&self, x: &[f64]) -> Vec<Vec<f64>> { ... }
}Expand description
A differentiable scalar objective f: ℝⁿ → ℝ to be minimized.
Implementors must supply value and
grad. The Hessian defaults to a central finite-difference
approximation built from grad, so second-order optimizers work for any
objective without an analytic Hessian; objectives that have one may override
hessian for accuracy.
Required Methods§
Provided Methods§
Sourcefn hessian(&self, x: &[f64]) -> Vec<Vec<f64>>
fn hessian(&self, x: &[f64]) -> Vec<Vec<f64>>
Approximates the Hessian ∇²f(x) by central differences of the gradient.
The default uses a step of √ε ≈ 1.49e-8 per coordinate and symmetrizes
the result so it is exactly symmetric (rounding can otherwise break
symmetry). Objectives with an analytic Hessian should override this.
§Arguments
x— the point at which to approximate the Hessian.
§Returns
The n × n Hessian in row-major order (n = x.len()).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".