optimize::problems
Standard test functions with known minima (More, Garbow and Hillstrom
1981; Jamil and Yang 2013). Each is generic over Smooth, so
rosen::<f64> evaluates it, rosen::<Dual> gives exact gradients by
AD and rosen::<Complex<f64>> by the complex step.
Functions
rosenSource
pub fn rosen<T: Smooth>(x: Vector<T>) -> T The Rosenbrock function in n >= 2 variables,
sum 100 (x[i+1] - x[i]^2)^2 + (1 - x[i])^2; minimum 0 at all ones.
use core::array::Vector;
let x: Vector<f64> = [1.0, 1.0, 1.0];
assert(optimize::problems::rosen(x) == 0.0);
rosen_gradSource
pub fn rosen_grad(x: Vector<f64>) -> Vector<f64> The gradient of rosen, O(n).
use core::array::Vector;
let x: Vector<f64> = [-1.2, 1.0];
let g = optimize::problems::rosen_grad(x);
assert((g[0] + 215.6).abs() < 1e-12 && (g[1] + 88.0).abs() < 1e-12);
rosen_hessSource
pub fn rosen_hess(x: Vector<f64>) -> Matrix<f64> The Hessian of rosen (tridiagonal, returned dense).
use core::array::Vector;
let x: Vector<f64> = [1.0, 1.0];
let h = optimize::problems::rosen_hess(x);
assert(h[0, 0] == 802.0 && h[0, 1] == -400.0 && h[1, 1] == 200.0);
rosen_hesspSource
pub fn rosen_hessp(x: Vector<f64>, v: Vector<f64>) -> Vector<f64> The product of the Hessian of rosen at x with v, O(n).
use core::array::Vector;
let x: Vector<f64> = [1.0, 1.0];
let v: Vector<f64> = [1.0, 0.0];
assert(optimize::problems::rosen_hessp(x, v)[1] == -400.0);
rosenbrockSource
pub fn rosenbrock() -> Objective rosen with its exact gradient and Hessian-vector product, the
usual benchmark objective.
let m = try optimize::lbfgs(optimize::problems::rosenbrock(), [-1.2, 1.0]);
assert(m.success());
boothSource
pub fn booth<T: Smooth>(x: Vector<T>) -> T Booth: (x + 2y - 7)^2 + (2x + y - 5)^2; minimum 0 at (1, 3).
use core::array::Vector;
let x: Vector<f64> = [1.0, 3.0];
assert(optimize::problems::booth(x) == 0.0);
bealeSource
pub fn beale<T: Smooth>(x: Vector<T>) -> T Beale: minimum 0 at (3, 0.5).
use core::array::Vector;
let x: Vector<f64> = [3.0, 0.5];
assert(optimize::problems::beale(x) == 0.0);
himmelblauSource
pub fn himmelblau<T: Smooth>(x: Vector<T>) -> T Himmelblau: (x^2 + y - 11)^2 + (x + y^2 - 7)^2; four minima of 0,
one at (3, 2).
use core::array::Vector;
let x: Vector<f64> = [3.0, 2.0];
assert(optimize::problems::himmelblau(x) == 0.0);
powell_singularSource
pub fn powell_singular<T: Smooth>(x: Vector<T>) -> T Powell's singular function (4 variables): minimum 0 at the origin, where the Hessian is singular.
use core::array::Vector;
let x: Vector<f64> = [0.0, 0.0, 0.0, 0.0];
assert(optimize::problems::powell_singular(x) == 0.0);
woodSource
pub fn wood<T: Smooth>(x: Vector<T>) -> T Wood's function (4 variables): minimum 0 at all ones.
use core::array::Vector;
let x: Vector<f64> = [1.0, 1.0, 1.0, 1.0];
assert(optimize::problems::wood(x) == 0.0);
sphereSource
pub fn sphere<T: Smooth>(x: Vector<T>) -> T The sphere sum x[i]^2; minimum 0 at the origin.
use core::array::Vector;
let x: Vector<f64> = [1.0, 2.0];
assert(optimize::problems::sphere(x) == 5.0);
rastriginSource
pub fn rastrigin<T: Smooth>(x: Vector<T>) -> T Rastrigin, 10 n + sum x^2 - 10 cos(2 pi x): many local minima,
global 0 at the origin. For the global solvers.
use core::array::Vector;
let x: Vector<f64> = [0.0, 0.0];
assert(optimize::problems::rastrigin(x) == 0.0);
ackleySource
pub fn ackley<T: Smooth>(x: Vector<T>) -> T Ackley's function: a nearly flat outer region with a deep hole, global 0 at the origin. For the global solvers.
use core::array::Vector;
let x: Vector<f64> = [0.0, 0.0];
assert(optimize::problems::ackley(x).abs() < 1e-15);