[]Trait argmin::prelude::finitediff::FiniteDiff

pub trait FiniteDiff {
type Jacobian;
type Hessian;
type OperatorOutput;
    fn forward_diff(&self, f: &dyn Fn(&Self)) -> Self;
fn central_diff(&self, f: &dyn Fn(&Self)) -> Self;
fn forward_jacobian(&self, fs: &dyn Fn(&Self)) -> Self::Jacobian;
fn central_jacobian(&self, fs: &dyn Fn(&Self)) -> Self::Jacobian;
fn forward_jacobian_vec_prod(&self, fs: &dyn Fn(&Self), p: &Self) -> Self;
fn central_jacobian_vec_prod(&self, fs: &dyn Fn(&Self), p: &Self) -> Self;
fn forward_jacobian_pert(
        &self,
        fs: &dyn Fn(&Self),
        pert: &Vec<PerturbationVector>
    ) -> Self::Jacobian;
fn central_jacobian_pert(
        &self,
        fs: &dyn Fn(&Self),
        pert: &Vec<PerturbationVector>
    ) -> Self::Jacobian;
fn forward_hessian(&self, g: &dyn Fn(&Self)) -> Self::Hessian;
fn central_hessian(&self, g: &dyn Fn(&Self)) -> Self::Hessian;
fn forward_hessian_vec_prod(&self, g: &dyn Fn(&Self), p: &Self) -> Self;
fn central_hessian_vec_prod(&self, g: &dyn Fn(&Self), p: &Self) -> Self;
fn forward_hessian_nograd(&self, f: &dyn Fn(&Self)) -> Self::Hessian;
fn forward_hessian_nograd_sparse(
        &self,
        f: &dyn Fn(&Self),
        indices: Vec<[usize; 2]>
    ) -> Self::Hessian; }

Associated Types

Loading content...

Required methods

fn forward_diff(&self, f: &dyn Fn(&Self)) -> Self

Forward difference calculated as

df/dx_i (x) \approx (f(x + sqrt(EPS_F64) * e_i) - f(x))/sqrt(EPS_F64) \forall i

where f is the cost function and e_i is the ith unit vector. For a parameter vector of length n, this requires n+1 evaluations of f.

fn central_diff(&self, f: &dyn Fn(&Self)) -> Self

Central difference calculated as

df/dx_i (x) \approx (f(x + sqrt(EPS_F64) * e_i) - f(x - sqrt(EPS_F64) * e_i))/(2.0 * sqrt(EPS_F64)) \forall i

where f is the cost function and e_i is the ith unit vector. For a parameter vector of length n, this requires 2*n evaluations of f.

fn forward_jacobian(&self, fs: &dyn Fn(&Self)) -> Self::Jacobian

Calculation of the Jacobian J(x) of a vector function fs using forward differences:

dfs/dx_i (x) \approx (fs(x + sqrt(EPS_F64) * e_i) - fs(x))/sqrt(EPS_F64) \forall i

where e_i is the ith unit vector. For a parameter vector of length n, this requires n+1 evaluations of fs.

fn central_jacobian(&self, fs: &dyn Fn(&Self)) -> Self::Jacobian

Calculation of the Jacobian J(x) of a vector function fs using central differences:

dfs/dx_i (x) \approx (fs(x + sqrt(EPS_F64) * e_i) - fs(x - sqrt(EPS_F64) * e_i))/(2.0 * sqrt(EPS_F64)) \forall i

where e_i is the ith unit vector. For a parameter vector of length n, this requires 2*n evaluations of fs.

fn forward_jacobian_vec_prod(&self, fs: &dyn Fn(&Self), p: &Self) -> Self

Calculation of the product of the Jacobian J(x) of a vector function fs with a vector p using forward differences:

J(x)*p \approx (fs(x + sqrt(EPS_F64) * p) - fs(x))/sqrt(EPS_F64) \forall i

where e_i is the ith unit vector. This requires 2 evaluations of fs.

fn central_jacobian_vec_prod(&self, fs: &dyn Fn(&Self), p: &Self) -> Self

Calculation of the product of the Jacobian J(x) of a vector function fs with a vector p using central differences:

J(x)*p \approx (fs(x + sqrt(EPS_F64) * p) - fs(x - sqrt(EPS_F64) * p))/(2.0 * sqrt(EPS_F64)) \forall i

where e_i is the ith unit vector. This requires 2 evaluations of fs.

fn forward_jacobian_pert(
    &self,
    fs: &dyn Fn(&Self),
    pert: &Vec<PerturbationVector>
) -> Self::Jacobian

fn central_jacobian_pert(
    &self,
    fs: &dyn Fn(&Self),
    pert: &Vec<PerturbationVector>
) -> Self::Jacobian

fn forward_hessian(&self, g: &dyn Fn(&Self)) -> Self::Hessian

Calculation of the Hessian using forward differences

dg/dx_i (x) \approx (g(x + sqrt(EPS_F64) * e_i) - g(x))/sqrt(EPS_F64) \forall i

where g is a function which computes the gradient of some other function f and e_i is the ith unit vector. For a parameter vector of length n, this requires n+1 evaluations of g.

fn central_hessian(&self, g: &dyn Fn(&Self)) -> Self::Hessian

Calculation of the Hessian using central differences

dg/dx_i (x) \approx (g(x + sqrt(EPS_F64) * e_i) - g(x - sqrt(EPS_F64) * e_i))/(2.0 * sqrt(EPS_F64)) \forall i

where g is a function which computes the gradient of some other function f and e_i is the ith unit vector. For a parameter vector of length n, this requires 2*n evaluations of g.

fn forward_hessian_vec_prod(&self, g: &dyn Fn(&Self), p: &Self) -> Self

Calculation of the product of the Hessian H(x) of a function g with a vector p using forward differences:

H(x)*p \approx (g(x + sqrt(EPS_F64) * p) - g(x))/sqrt(EPS_F64) \forall i

where g is a function which computes the gradient of some other function f and e_i is the ith unit vector. This requires 2 evaluations of g.

fn central_hessian_vec_prod(&self, g: &dyn Fn(&Self), p: &Self) -> Self

Calculation of the product of the Hessian H(x) of a function g with a vector p using central differences:

H(x)*p \approx (g(x + sqrt(EPS_F64) * p) - g(x - sqrt(EPS_F64) * p))/(2.0 * sqrt(EPS_F64)) \forall i

where g is a function which computes the gradient of some other function f and e_i is the ith unit vector. This requires 2 evaluations of g.

fn forward_hessian_nograd(&self, f: &dyn Fn(&Self)) -> Self::Hessian

Calculation of the Hessian using forward differences without knowledge of the gradient:

df/(dx_i dx_j) (x) \approx (f(x + sqrt(EPS_F64) * e_i + sqrt(EPS_F64) * e_j) - f(x + sqrt(EPS_F64) + e_i) - f(x + sqrt(EPS_F64) * e_j) + f(x))/EPS_F64 \forall i

where e_i and e_j are the ith and jth unit vector, respectively.

fn forward_hessian_nograd_sparse(
    &self,
    f: &dyn Fn(&Self),
    indices: Vec<[usize; 2]>
) -> Self::Hessian

Calculation of a sparse Hessian using forward differences without knowledge of the gradient:

df/(dx_i dx_j) (x) \approx (f(x + sqrt(EPS_F64) * e_i + sqrt(EPS_F64) * e_j) - f(x + sqrt(EPS_F64) + e_i) - f(x + sqrt(EPS_F64) * e_j) + f(x))/EPS_F64 \forall i

where e_i and e_j are the ith and jth unit vector, respectively. The indices which are to be evaluated need to be provided via indices. Note that due to the symmetry of the Hessian, an index (a, b) will also compute the value of the Hessian at (b, a).

Loading content...

Implementations on Foreign Types

impl FiniteDiff for Vec<f64> where
    Vec<f64>: Sized

type Jacobian = Vec<Vec<f64>>

type Hessian = Vec<Vec<f64>>

type OperatorOutput = Vec<f64>

Loading content...

Implementors

Loading content...