tpt-math-optimize-general
General numerical optimisation: in-house closure-driven minimisers for the
common smooth, unconstrained cases (steepest descent, nonlinear conjugate
gradient, Newton), built directly on tpt-math-linalg-dense's
DVector/DMatrix. A cost function and a starting point are enough to get
an answer, with no external optimisation framework in the dependency graph.
Part of tpt-math
Part of the tpt-math workspace —
the numeric substrate for tpt-science, tpt-engineering, and tpt-formal.
It is the general-purpose half of the optimisation layer (the convex/QP half is
tpt-math-optimize-convex), and is re-exported by the tpt-math-optimize
umbrella crate. Parameters are plain tpt-math-linalg-dense DVector<f64>s from the same
faer-backed storage that tpt-math-linalg wraps.
Features
This crate has no optional features: default = [] and everything described
here is always available. It is std-only — tpt-math-linalg-dense's
default (allocator-backed, faer) storage requires std, so there is no
no_std build.
The dependency set is fixed rather than feature-gated: tpt-math-linalg and
tpt-math-linalg-dense.
Quick start
[]
= "0.1"
Minimise f(x, y) = (x - 3)² + (y - 2)² by gradient descent:
use DVector;
use minimize_gradient_descent;
let cost = ;
let grad = ;
let best = minimize_gradient_descent.unwrap;
assert!;
assert!;
The three convenience solvers:
| Function | Method | Needs |
|---|---|---|
minimize_gradient_descent |
steepest descent + More-Thuente line search | cost, gradient |
minimize_conjugate_gradient |
nonlinear CG (Polak–Ribière+, with periodic restarts) + More-Thuente line search | cost, gradient |
minimize_newton |
Newton's method (full step, analytic Hessian) | cost, gradient, Hessian |
Each has a *_with variant that takes Options and returns a Solution
reporting the parameter vector, the cost re-evaluated there, the iteration
count, whether the gradient tolerance was met, and a human-readable
termination reason:
use DVector;
use ;
let cost = ;
let grad = ;
let options = new.with_gradient_tolerance;
let solution = minimize_conjugate_gradient_with.unwrap;
assert!;
assert!;
Notes
- Nothing is hidden:
tpt_math_linalgandtpt_math_linalg_denseare both re-exported, so you can build on the same parameter types without a second, possibly version-skewed, dependency on them. - Errors are flattened to a
Stringmessage rather than a typed error type. - Every run stops at
max_itersor earlier once the gradient's L2 norm falls toOptions::gradient_tolerance(default1e-9). That early stop matters: line searches fail outright on a numerically zero gradient, so without it an already-converged run would report an error instead of its answer. - Optimisation is deliberately unit-less — a cost mixes every unit in the
problem — but unit-tagged
tpt_math_linalg::Vecvalues can be moved in and out withpoint_from_tagged/point_to_tagged(TaggedVec<U>). minimize_newtontakes no line search; the step is the full Newton step.- Empty, non-finite initial points and negative gradient tolerances are rejected up front with a clear message.
#![forbid(unsafe_code)].- This crate is dual-licensed
MIT OR Apache-2.0, matching the rest of the workspace, and depends only ontpt-math-linalg/tpt-math-linalg-dense(both also part of this workspace) — no third-party optimisation framework.
License
Licensed under either of MIT or Apache-2.0 at your option.