API reference — Rust generic seam¶
The Rust core owns the shared optimization seam. Python callers reach it through mltreelib.solvers.optimize. Guide: Generic optimizer.
Reach the module through mltreelib_core::generic or mltreelib_core::solver::generic. The short names Bounds, Budget, Constraint, ConstraintKind, Objective, ObjectiveError, OptimizationRequest, OptimizationResult, OptimizerKind, SmoothObjective, and SolveStatus are re-exported from mltreelib_core::solver.
solver/generic/annealing.rs¶
simulated_annealing¶
pub fn simulated_annealing( objective: &dyn Objective, budget: &Budget, options: &AnnealingOptions, seed: u64, start: Option<&[f64]>, ) -> OptimizationResult {
Runs bounded simulated annealing.
The starting point defaults to the middle of the box. The initial temperature comes from the observed objective spread when the caller does not supply one.
solver/generic/basin_hopping.rs¶
basin_hopping¶
pub fn basin_hopping( objective: &dyn Objective, smooth: &dyn SmoothObjective, budget: &Budget, options: &BasinHoppingOptions, seed: u64, start: Option<&[f64]>, ) -> OptimizationResult {
Runs basin hopping.
The inner local solver comes from the shared seam. The perturbation scales with the bound width, so one step size fits heterogeneous parameter scales.
solver/generic/bfgs.rs¶
bfgs¶
pub fn bfgs( objective: &dyn Objective, smooth: &dyn SmoothObjective, budget: &Budget, options: &BfgsOptions, start: Option<&[f64]>, ) -> OptimizationResult {
Runs BFGS on an unbounded smooth objective.
The starting point defaults to the origin. The run stops when the gradient falls under the tolerance, when the iteration limit is reached, or when a budget ends the run.
solver/generic/bounds.rs¶
Bounds¶
Lower and upper limits for each parameter.
A bound is either finite or infinite. lower[i] <= upper[i] holds for every dimension. A fully unbounded domain uses negative and positive infinity.
Bounds.new¶
Builds bounds from per-dimension lower and upper limits.
Returns an error when the vectors differ in length, when a limit is NaN, when a lower limit is positive infinity, when an upper limit is negative infinity, or when a lower limit exceeds its upper limit.
solver/generic/budget.rs¶
BudgetStatus¶
Which budget ended a run.
Budget¶
Counts user objective evaluations and solver iterations.
One counter covers every user objective call, including calls inside local solves, perturbation steps, population initialization, finite-difference gradients, and archive updates. The counters use interior mutability, so the objective wrapper and the solver share one budget without aliasing borrows.
Budget.new¶
Builds a budget with optional limits. None means unlimited.
solver/generic/cobyla.rs¶
cobyla¶
pub fn cobyla( objective: &dyn Objective, budget: &Budget, options: &CobylaOptions, start: Option<&[f64]>, constraints: Option<&dyn ConstraintEvaluator>, kind: ConstraintKind, ) -> OptimizationResult {
Runs COBYLA on a bounded problem with inequality constraints.
The starting point defaults to the middle of the box. The method stops when the trust region collapses, when the model step vanishes, when the iteration limit is reached, or when a budget ends the run.
solver/generic/conjugate_gradient.rs¶
nonlinear_conjugate_gradient¶
pub fn nonlinear_conjugate_gradient( objective: &dyn Objective, smooth: &dyn SmoothObjective, budget: &Budget, options: &NonlinearCgOptions, start: Option<&[f64]>, ) -> OptimizationResult {
Runs nonlinear conjugate gradient on an unbounded smooth objective.
The starting point defaults to the origin. The run stops when the gradient falls under the tolerance, when the iteration limit is reached, or when a budget ends the run.
solver/generic/constraint.rs¶
ConstraintKind¶
Constraint type.
ConstraintKind.as_str¶
Canonical name.
Constraint¶
Constraint values evaluated at one point.
Constraint.new¶
Builds evaluated constraint values.
violation¶
Largest violation of one constraint value.
An inequality value below zero violates the constraint by its magnitude. An equality value violates the constraint by its absolute distance from zero.
max_violation¶
Largest violation across all constraint values.
is_feasible¶
Reports whether constraint values satisfy the constraint.
Inequality values accept a small negative slack. Equality values accept an absolute distance from zero up to the tolerance.
ConstraintEvaluator¶
Evaluates constraint values at a point.
ConstraintEvaluator.values¶
Returns one value per constraint.
solver/generic/finite_difference.rs¶
FiniteDifferenceObjective¶
Objective that supplies a central-difference gradient.
The perturbation calls the wrapped objective, so the shared budget counts them like every other objective call.
solver/generic/lbfgs_b.rs¶
solve_lbfgs_b¶
pub fn solve_lbfgs_b( objective: &dyn Objective, budget: &Budget, options: &LbfgsBOptions, start: Option<&[f64]>, smooth: &dyn SmoothObjective, ) -> OptimizationResult {
Runs L-BFGS-B on one bounded smooth objective.
The returned point is always projected into the box. Evaluation budget exhaustion is reported as EvaluationLimit; iteration budget exhaustion is reported as IterationLimit.
solver/generic/line_search.rs¶
LineSearchOptions¶
Line search parameters.
LineSearchResult¶
Result of one line search.
strong_wolfe¶
pub fn strong_wolfe( objective: &dyn Objective, smooth: &dyn SmoothObjective, point: &[f64], direction: &[f64], options: &LineSearchOptions, ) -> Result<LineSearchResult, ObjectiveError> {
Runs a strong Wolfe line search along one direction.
The search returns the step, the objective value, and the gradient at the accepted point. It falls back to the steepest descent direction when the supplied direction is not a descent direction.
solver/generic/mod.rs¶
FINITE_DIFFERENCE_STEP¶
Step size used by the central-difference gradient fallback.
optimize¶
Runs one optimization with the shared contracts.
The method dispatch resolves the method-specific options, evaluates the objective through one shared budget, and returns the shared result type.
optimize_with_budget¶
pub fn optimize_with_budget( request: &OptimizationRequest, budget: &Budget, ) -> Result<OptimizationResult, String> {
Runs one optimization against a budget that the caller owns.
A composition method uses this entry point so the inner local solve spends the outer budget and no objective call escapes the count.
solver/generic/nelder_mead.rs¶
nelder_mead¶
pub fn nelder_mead( objective: &dyn Objective, budget: &Budget, options: &NelderMeadOptions, start: Option<&[f64]>, ) -> OptimizationResult {
Runs bounded Nelder-Mead.
The starting point defaults to the middle of the box. The method stops when the objective spread and the simplex spread fall under the configured tolerances, when the iteration limit is reached, or when a budget ends the run.
solver/generic/objective.rs¶
ObjectiveError¶
Failure reported by an objective or gradient evaluation.
Objective¶
A bounded scalar objective.
Implementations return one finite value for one point. Solvers reject non-finite values through [ObjectiveError::NotFinite] and report the [crate::solver::generic::SolveStatus::InvalidObjective] status.
Objective.dim¶
Number of parameters.
Objective.bounds¶
Parameter domain.
Objective.value¶
Objective value at one point.
SmoothObjective¶
An objective that also provides an exact gradient.
SmoothObjective.gradient¶
Gradient at one point. The returned vector has one entry per dimension.
require_finite¶
Checks that an objective value is finite.
require_dimension¶
Checks that a point matches the objective dimension.
CountedObjective¶
Objective wrapper that charges the shared budget for every value call.
Wrapping the user objective keeps one counter for every objective call, including the calls a finite-difference gradient makes.
solver/generic/powell.rs¶
powell¶
pub fn powell( objective: &dyn Objective, budget: &Budget, options: &PowellOptions, start: Option<&[f64]>, ) -> OptimizationResult {
Runs bounded Powell.
The starting point defaults to the middle of the box. The method stops when the objective and the point stop moving, when the iteration limit is reached, or when a budget ends the run.
solver/generic/random.rs¶
latin_hypercube_samples¶
pub fn latin_hypercube_samples( bounds: &Bounds, samples: usize, seed: u64, ) -> Result<Vec<Vec<f64>>, String> {
Builds Latin hypercube samples inside finite bounds.
Every dimension is stratified independently into samples strata. One point takes one stratum per dimension. The stratum order is shuffled per dimension with the seeded generator.
random_search¶
pub fn random_search( objective: &dyn Objective, budget: &Budget, options: &RandomSearchOptions, seed: u64, initial_population: Option<&[Vec<f64>]>, ) -> OptimizationResult {
Runs uniform random search inside bounds.
Candidates come from initial_population first when one is supplied. The remaining candidates are uniform draws.
latin_hypercube_search¶
pub fn latin_hypercube_search( objective: &dyn Objective, budget: &Budget, options: &LatinHypercubeOptions, seed: u64, ) -> OptimizationResult {
Runs Latin hypercube sampling inside bounds.
solver/generic/request.rs¶
DEFAULT_SEED¶
Default seed used by every stochastic method when no seed is supplied.
The fixed seed keeps omitted seeds reproducible across runs.
OptimizerKind¶
One optimizer method.
OptimizerKind.as_str¶
Canonical method name.
SharedOptions¶
Options shared by every method.
RandomSearchOptions¶
Options for random search.
LatinHypercubeOptions¶
Options for Latin hypercube sampling.
LbfgsBOptions¶
Options for L-BFGS-B.
BfgsOptions¶
Options for full-memory BFGS.
NonlinearCgOptions¶
Options for nonlinear conjugate gradient.
NelderMeadOptions¶
Options for Nelder-Mead.
PowellOptions¶
Options for Powell.
BoundaryPolicy¶
Boundary policy for proposals that leave the box.
AnnealingOptions¶
Options for bounded simulated annealing.
CobylaOptions¶
Options for COBYLA.
BasinHoppingOptions¶
Options for basin hopping.
MethodOptions¶
Method-specific options.
MethodOptions.kind¶
Method that owns these options.
OptimizationRequest¶
One optimization request.
solver/generic/result.rs¶
SolveStatus¶
Termination status of one optimization run.
Budget exhaustion never reports success. Only [SolveStatus::Converged] and [SolveStatus::Tolerance] report success.
SolveStatus.as_str¶
Canonical name used by the Python surface and result files.
HistoryEntry¶
One convergence history sample.
OptimizationResult¶
Result of one optimization run.
OptimizationResult.new¶
Builds a result with the given point and value.