Expand description
Problem traits the user implements about their objective. Solvers
bind on whichever subset they need (e.g. gradient descent requires
CostFunction and Gradient; Nelder-Mead only needs
CostFunction).
§Soft reject vs hard abort
Every problem trait method returns Result<_, Self::Error>. The two
ways to signal “something went wrong” are deliberately distinct:
- Soft reject (
Ok(f64::INFINITY)): return+∞fromCostFunction::costto reject a single point. Line searches treat it as worse and retreat; population solvers treat it as worst fitness. This is the right channel for “thisxis outside my domain, but the solve should continue.” - Hard abort (
Err(_)): returnErrto terminate the entire solve. The error bubbles all the way out ofExecutor::runtyped asResult<_, P::Error>. Use this when the failure is not about a particularx: a downstream service vanished, the user pressed cancel, an early-stopping criterion in the problem’s own state fired.
Problems that never fail in this way pick
type Error = std::convert::Infallible; (or
! on nightly).
Niche optimization collapses Result<f64, Infallible> to f64 layout,
so the happy path stays zero-cost.
Structs§
- Eval
Counts - Per-kind evaluation counters carried by
Problem. - Problem
- Counting wrapper that solvers receive instead of
&Pdirectly.
Traits§
- Cost
Function - Scalar-valued objective
f(x): Param → Output. The smallest problem trait: every solver binds at least on this. - Gradient
- Analytic gradient
∇f(x): Param → Gradient. Required by first-order solvers (gradient descent, BFGS, …). - Hessian
- Analytic Hessian
H(x) = ∇²f(x): Param → Hessianfor second-order solvers (Newton, trust-region-Newton). The associatedHessianmatrix type lets solvers bound on the linear-algebra ops they need (LinearSolveSpd,SymmetricEigen, …) without baking in a backend. - Hessian
Product - Matrix-free Hessian-vector products:
v ↦ ∇²f(param) · v. - Jacobian
- Analytic Jacobian
J(x) = ∂r/∂x: Param → Jacobianfor least-squares solvers (Gauss-Newton, LM, TRF). The associatedJacobianmatrix type is what lets solvers bound on the linear-algebra ops they need (MatVec,LinearSolveSpd, …) without baking in a specific backend or assuming density. - Mini
Batch Gradient - Finite-sum gradient
(1/|B|) Σ_{i ∈ B} ∇fᵢ(x)over a chosen subsetBof component samples. Required by mini-batch stochastic solvers (Sgd), which call it once per step with a fresh batch of indices the solver drew from its ownChaCha8Rng. - Residual
- Vector-valued residual
r(x): Param → Outputfor least-squares problems. Required by Gauss-Newton, Levenberg-Marquardt, and any solver that minimizes½‖r(x)‖².