Skip to main content

Residual

Trait Residual 

Source
pub trait Residual {
    type Param;
    type Output;

    // Required method
    fn residual(&self, param: &Self::Param) -> Self::Output;
}
Expand description

Vector-valued residual r(x): Param → Output for least-squares problems. Required by Gauss-Newton, Levenberg-Marquardt, and any solver that minimizes ½‖r(x)‖².

§Contract

  • Implementor must: be a pure function of param, with the same call-order independence as CostFunction::cost.
  • Implementor must: return an Output whose length m is fixed for a given problem — m does not depend on the iterate. Solvers may allocate workspace once based on the first call. m is independent of param.len() = n.
  • When CostFunction is also implemented, the cost must agree with the residual under the convention cost(x) = ½ Σ rᵢ(x)², unless the problem documents an unscaled Σ rᵢ² form (see e.g. the existing Rosenbrock cost, which is the published unscaled form).

§Examples

use basin::Residual;

// r(x) = (x₀ − 1, x₁ − 2); the least-squares optimum is (1, 2).
struct Affine;
impl Residual for Affine {
    type Param = Vec<f64>;
    type Output = Vec<f64>;
    fn residual(&self, x: &Vec<f64>) -> Vec<f64> {
        vec![x[0] - 1.0, x[1] - 2.0]
    }
}

assert_eq!(Affine.residual(&vec![0.0, 0.0]), vec![-1.0, -2.0]);

Required Associated Types§

Source

type Param

The parameter type the residual is defined over (matches CostFunction::Param).

Source

type Output

The residual vector type. Length is the number of residuals m, independent of param.len() = n.

Required Methods§

Source

fn residual(&self, param: &Self::Param) -> Self::Output

Evaluate the residual at param.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl Residual for BoothBoxedResiduals<Vec<f64>>

Available on crate feature problems only.
Source§

impl Residual for BoothBoxedResiduals<Col<f64>>

Available on crate features problems and faer only.
Source§

type Param = Col<Own<f64>>

Source§

type Output = Col<Own<f64>>

Source§

impl Residual for BoothBoxedResiduals<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl Residual for BoothResiduals<Vec<f64>>

Available on crate feature problems only.
Source§

impl Residual for BoothResiduals<Col<f64>>

Available on crate features problems and faer only.
Source§

type Param = Col<Own<f64>>

Source§

type Output = Col<Own<f64>>

Source§

impl Residual for BoothResiduals<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl Residual for ExponentialFit<Vec<f64>>

Available on crate feature problems only.
Source§

impl Residual for ExponentialFit<Col<f64>>

Available on crate features problems and faer only.
Source§

type Param = Col<Own<f64>>

Source§

type Output = Col<Own<f64>>

Source§

impl Residual for ExponentialFit<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl Residual for ExponentialFit<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl Residual for PowellSingular<Vec<f64>>

Available on crate feature problems only.
Source§

impl Residual for PowellSingular<Col<f64>>

Available on crate features problems and faer only.
Source§

type Param = Col<Own<f64>>

Source§

type Output = Col<Own<f64>>

Source§

impl Residual for PowellSingular<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl Residual for PowellSingular<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl Residual for RosenbrockResiduals<Vec<f64>>

Available on crate feature problems only.
Source§

impl Residual for RosenbrockResiduals<Col<f64>>

Available on crate features problems and faer only.
Source§

type Param = Col<Own<f64>>

Source§

type Output = Col<Own<f64>>

Source§

impl Residual for RosenbrockResiduals<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl Residual for RosenbrockResiduals<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl Residual for SparseLeastSquares<CscMatrix<f64>, DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl Residual for SparseLeastSquares<SparseColMat<usize, f64>, Col<f64>>

Available on crate features problems and faer only.
Source§

type Param = Col<Own<f64>>

Source§

type Output = Col<Own<f64>>

Source§

impl Residual for SparseLeastSquaresBoxed<CscMatrix<f64>, DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl Residual for SparseLeastSquaresBoxed<SparseColMat<usize, f64>, Col<f64>>

Available on crate features problems and faer only.
Source§

type Param = Col<Own<f64>>

Source§

type Output = Col<Own<f64>>

Source§

impl<P: Residual> Residual for FiniteDiff<P>