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 asCostFunction::cost. - Implementor must: return an
Outputwhose lengthmis fixed for a given problem —mdoes not depend on the iterate. Solvers may allocate workspace once based on the first call.mis independent ofparam.len() = n. - When
CostFunctionis also implemented, the cost must agree with the residual under the conventioncost(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§
Sourcetype Param
type Param
The parameter type the residual is defined over (matches
CostFunction::Param).
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
Source§impl Residual for BoothBoxedResiduals<Col<f64>>
Available on crate features problems and faer only.
impl Residual for BoothBoxedResiduals<Col<f64>>
Available on crate features
problems and faer only.Source§impl Residual for BoothBoxedResiduals<DVector<f64>>
Available on crate features problems and nalgebra only.
impl Residual for BoothBoxedResiduals<DVector<f64>>
Available on crate features
problems and nalgebra only.Source§impl Residual for BoothResiduals<Col<f64>>
Available on crate features problems and faer only.
impl Residual for BoothResiduals<Col<f64>>
Available on crate features
problems and faer only.Source§impl Residual for BoothResiduals<DVector<f64>>
Available on crate features problems and nalgebra only.
impl Residual for BoothResiduals<DVector<f64>>
Available on crate features
problems and nalgebra only.Source§impl Residual for ExponentialFit<Col<f64>>
Available on crate features problems and faer only.
impl Residual for ExponentialFit<Col<f64>>
Available on crate features
problems and faer only.Source§impl Residual for ExponentialFit<DVector<f64>>
Available on crate features problems and nalgebra only.
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.
impl Residual for ExponentialFit<Array1<f64>>
Available on crate features
problems and ndarray only.Source§impl Residual for PowellSingular<Col<f64>>
Available on crate features problems and faer only.
impl Residual for PowellSingular<Col<f64>>
Available on crate features
problems and faer only.Source§impl Residual for PowellSingular<DVector<f64>>
Available on crate features problems and nalgebra only.
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.
impl Residual for PowellSingular<Array1<f64>>
Available on crate features
problems and ndarray only.Source§impl Residual for RosenbrockResiduals<Col<f64>>
Available on crate features problems and faer only.
impl Residual for RosenbrockResiduals<Col<f64>>
Available on crate features
problems and faer only.Source§impl Residual for RosenbrockResiduals<DVector<f64>>
Available on crate features problems and nalgebra only.
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.
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.
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.
impl Residual for SparseLeastSquares<SparseColMat<usize, f64>, Col<f64>>
Available on crate features
problems and faer only.Source§impl Residual for SparseLeastSquaresBoxed<CscMatrix<f64>, DVector<f64>>
Available on crate features problems and nalgebra only.
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.
impl Residual for SparseLeastSquaresBoxed<SparseColMat<usize, f64>, Col<f64>>
Available on crate features
problems and faer only.