Skip to main content

CostFunction

Trait CostFunction 

Source
pub trait CostFunction {
    type Param;
    type Output;

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

Scalar-valued objective f(x): Param → Output. The smallest problem trait — every solver binds at least on this.

§Contract

  • Implementor must: be a pure function of param — evaluating at the same param twice must return the same Output. Solvers cache costs across iterations, line searches reuse evaluations, and termination criteria assume the cost they read from the state matches what a fresh cost(param) would return.
  • Implementor must not: assume any particular call order or frequency. Solvers may evaluate at exploratory points outside the accepted iterate sequence (line-search probes, Nelder-Mead reflections / contractions / shrinks, finite-difference probes).

§Examples

use basin::CostFunction;

struct Sphere;
impl CostFunction for Sphere {
    type Param = Vec<f64>;
    type Output = f64;
    fn cost(&self, x: &Vec<f64>) -> f64 {
        x.iter().map(|xi| xi * xi).sum()
    }
}

assert_eq!(Sphere.cost(&vec![3.0, 4.0]), 25.0);

Required Associated Types§

Source

type Param

The parameter type the objective is defined over.

Source

type Output

Scalar cost type. In practice f64 (see AGENTS.md’s provisional choices).

Required Methods§

Source

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

Evaluate the objective at param.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl CostFunction for Ackley<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for Ackley<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for Ackley<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for Ackley<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for AckleyBoxed<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for AckleyBoxed<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for AckleyBoxed<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for AckleyBoxed<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for Beale<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for Beale<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for Beale<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for Beale<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for Booth<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for Booth<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for Booth<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for Booth<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for BoothBoxed<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for BoothBoxed<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for BoothBoxed<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for BoothBoxed<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for BoothBoxedResiduals<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for BoothBoxedResiduals<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for BoothBoxedResiduals<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for BoothResiduals<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for BoothResiduals<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for BoothResiduals<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for BukinN6<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for BukinN6<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for BukinN6<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for BukinN6<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for ConstrainedQuadratic<DenseMatrix, Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for ConstrainedQuadratic<Mat<f64>, Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for ConstrainedQuadratic<DMatrix<f64>, DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for ConstrainedQuadratic<Array2<f64>, Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for CrossInTray<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for CrossInTray<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for CrossInTray<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for CrossInTray<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for Easom<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for Easom<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for Easom<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for Easom<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for Eggholder<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for Eggholder<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for Eggholder<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for Eggholder<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for EqualityConstrainedQuadratic<DenseMatrix, Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for EqualityConstrainedQuadratic<Mat<f64>, Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for EqualityConstrainedQuadratic<DMatrix<f64>, DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for EqualityConstrainedQuadratic<Array2<f64>, Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for ExponentialFit<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for ExponentialFit<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for ExponentialFit<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for ExponentialFit<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for GoldsteinPrice<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for GoldsteinPrice<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for GoldsteinPrice<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for GoldsteinPrice<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for Himmelblau<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for Himmelblau<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for Himmelblau<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for Himmelblau<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for HolderTable<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for HolderTable<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for HolderTable<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for HolderTable<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for Levy<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for Levy<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for Levy<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for Levy<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for LevyBoxed<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for LevyBoxed<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for LevyBoxed<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for LevyBoxed<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for Matyas<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for Matyas<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for Matyas<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for Matyas<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for McCormick<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for McCormick<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for McCormick<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for McCormick<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for Picheny<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for Picheny<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for Picheny<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for Picheny<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for PowellSingular<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for PowellSingular<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for PowellSingular<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for PowellSingular<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for Rastrigin<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for Rastrigin<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for Rastrigin<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for Rastrigin<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for RastriginBoxed<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for RastriginBoxed<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for RastriginBoxed<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for RastriginBoxed<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for Rosenbrock<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for Rosenbrock<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for Rosenbrock<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for Rosenbrock<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for RosenbrockResiduals<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for RosenbrockResiduals<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for RosenbrockResiduals<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for RosenbrockResiduals<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for SchafferN2<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for SchafferN2<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for SchafferN2<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for SchafferN2<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for SchafferN4<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for SchafferN4<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for SchafferN4<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for SchafferN4<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

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

Available on crate features problems and nalgebra only.
Source§

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

Available on crate features problems and faer only.
Source§

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

Available on crate features problems and nalgebra only.
Source§

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

Available on crate features problems and faer only.
Source§

impl CostFunction for Sphere<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for Sphere<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for Sphere<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for Sphere<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for StyblinskiTang<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for StyblinskiTang<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for StyblinskiTang<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for StyblinskiTang<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for StyblinskiTangBoxed<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for StyblinskiTangBoxed<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for StyblinskiTangBoxed<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for StyblinskiTangBoxed<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for ThreeHumpCamel<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for ThreeHumpCamel<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for ThreeHumpCamel<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for ThreeHumpCamel<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl CostFunction for Zero<Vec<f64>>

Available on crate feature problems only.
Source§

impl CostFunction for Zero<Col<f64>>

Available on crate features problems and faer only.
Source§

impl CostFunction for Zero<DVector<f64>>

Available on crate features problems and nalgebra only.
Source§

impl CostFunction for Zero<Array1<f64>>

Available on crate features problems and ndarray only.
Source§

impl<P, V, M> CostFunction for AugmentedLagrangian<'_, P, V>
where P: CostFunction<Param = V, Output = f64> + LinearEqualityConstraints<Param = V, Matrix = M>, M: MatVec<V>, V: ScaledAdd<f64> + Dot + NormSquared,

Source§

impl<P, V, M> CostFunction for LogBarrier<'_, P>
where P: CostFunction<Param = V, Output = f64> + LinearInequalityConstraints<Param = V, Matrix = M>, M: MatVec<V>, V: ScaledAdd<f64> + NegInPlace + VectorIndex + VectorLen,

Source§

impl<P: CostFunction> CostFunction for FiniteDiff<P>