Expand description
General numerical optimization — in-house smooth, unconstrained minimizers.
This crate provides closure-driven entry points for the common smooth,
unconstrained minimization cases, built directly on
tpt_math_linalg_dense’s DVector/DMatrix (no argmin/faer
dependency):
| Convenience function | Method |
|---|---|
minimize_gradient_descent | steepest descent + More-Thuente line search |
minimize_conjugate_gradient | nonlinear CG (Polak–Ribière+) + More-Thuente line search, periodic restarts |
minimize_newton | Newton’s method (full step, analytic Hessian) |
Parameters are plain DVector<f64>s; unit-tagged
tpt_math_linalg::Vec values move in and out with
point_from_tagged / point_to_tagged. Optimization itself is
deliberately unit-less: a cost mixes every unit in the problem, so there is
no meaningful tag for a search direction or a step length.
§Examples
Minimize f(x, y) = (x - 3)² + (y - 2)² by gradient descent:
use tpt_math_optimize_general::{minimize_gradient_descent, tpt_math_linalg_dense::DVector};
let cost = |p: &DVector<f64>| (p[0] - 3.0).powi(2) + (p[1] - 2.0).powi(2);
let grad = |p: &DVector<f64>| DVector::from_vec(vec![2.0 * (p[0] - 3.0), 2.0 * (p[1] - 2.0)]);
let best = minimize_gradient_descent(cost, grad, DVector::zeros(2), 100).unwrap();
assert!((best[0] - 3.0).abs() < 1e-6);
assert!((best[1] - 2.0).abs() < 1e-6);The *_with variants take Options and return a Solution, which
also reports the cost, the iteration count and why the solver stopped:
use tpt_math_optimize_general::{minimize_newton, tpt_math_linalg_dense::{DMatrix, DVector}};
// f(x) = exp(x) - x, minimized at x = 0 with f(0) = 1.
let cost = |p: &DVector<f64>| p[0].exp() - p[0];
let grad = |p: &DVector<f64>| DVector::from_vec(vec![p[0].exp() - 1.0]);
let hess = |p: &DVector<f64>| DMatrix::from_vec(1, 1, vec![p[0].exp()]);
let best = minimize_newton(cost, grad, hess, DVector::from_vec(vec![1.0]), 50).unwrap();
assert!(best[0].abs() < 1e-6);§Conventions
- Every run stops at
max_iters, or earlier once the gradient’s L2 norm falls toOptions::gradient_tolerance. The early stop matters: a solver that has already reached its optimum would otherwise keep iterating and report a worse (or non-finite) point. - The reported
Solution::paramis the best parameter vector found, andSolution::costis the user cost function re-evaluated there. - A non-finite or empty initial point, or a non-invertible Hessian (Newton),
is reported as an
Errwith a human-readable message.
Re-exports§
pub use autodiff_opt::minimize_lbfgs_autodiff;pub use least_squares::curve_fit;pub use least_squares::levenberg_marquardt;pub use least_squares::LeastSquaresOptions;pub use least_squares::LeastSquaresSolution;pub use least_squares::LsTermination;pub use tpt_math_linalg;pub use tpt_math_linalg::tpt_math_linalg_dense;
Modules§
- autodiff_
opt - Optimisation with gradients taken automatically by reverse-mode autodiff.
- least_
squares - Nonlinear least squares: Levenberg–Marquardt, optionally with box bounds,
and a
curve_fitconvenience for modelsy ≈ f(x; p). - linear_
program - Linear programming by the two-phase simplex method.
Structs§
Constants§
- DEFAULT_
GRADIENT_ TOLERANCE - Default gradient L2 norm at or below which a run counts as converged.
- DEFAULT_
MAX_ ITERS - Default iteration budget used by
Options::default.
Functions§
- minimize_
conjugate_ gradient - Minimize a smooth objective with nonlinear conjugate gradients (Polak–Ribière+ β update with periodic restarts, More-Thuente line search).
- minimize_
conjugate_ gradient_ with minimize_conjugate_gradientwith explicitOptions, reporting a fullSolution.- minimize_
gradient_ descent - Minimize a smooth objective by gradient descent with a More-Thuente line search.
- minimize_
gradient_ descent_ with minimize_gradient_descentwith explicitOptions, reporting a fullSolution.- minimize_
lbfgs - Minimize a smooth objective with limited-memory BFGS (L-BFGS).
- minimize_
lbfgs_ with minimize_lbfgswith explicitOptions, reporting a fullSolution.- minimize_
nelder_ mead - Minimize a derivative-free objective with Nelder–Mead, returning only the
best point. See
minimize_nelder_mead_with. - minimize_
nelder_ mead_ with - Minimize a derivative-free objective with the Nelder–Mead simplex method.
- minimize_
newton - Minimize a smooth objective with
Newton’s method, using the analytic Hessian. - minimize_
newton_ with minimize_newtonwith explicitOptions, reporting a fullSolution.- numerical_
gradient - Central finite-difference approximation of the gradient of
costatx, with steph · max(1, |xᵢ|)in each coordinate. Use it when no analytic gradient exists. - point_
from_ tagged - Copy a unit-tagged
tpt_math_linalg::Vecinto a raw parameter vector. - point_
to_ tagged - Tag a raw parameter vector with the unit
U, undoingpoint_from_tagged.
Type Aliases§
- Tagged
Vec - A unit-tagged vector of
f64s, as used bytpt_math_linalg.