Assignment, trust regions and global optimisation
| Problem | Match the rows of a cost matrix to its columns at least total cost; minimise a smooth function with second derivatives robustly; find the global minimum of a function with many local minima |
| Devised by | Harold Kuhn (1955), the Hungarian method; Roy Jonker and Anton Volgenant (1987), shortest augmenting paths; David Crouse (2016), the rectangular form SciPy uses; Michael Powell (1970), dogleg; Trond Steihaug (1983), truncated CG; Jorge Moré and Danny Sorensen (1983), the nearly exact subproblem; David Wales and Jonathan Doye (1997), basin hopping; Constantino Tsallis and Daniel Stariolo (1996) and Yang Xiang et al. (1997), generalised and dual annealing; Donald Jones, Cary Perttunen and Bruce Stuckman (1993), DIRECT; Jörg Gablonsky and Tim Kelley (2001), DIRECT-L |
| Accuracy | Assignments identical to SciPy’s; trust-region iterates identical (same iterations and evaluations, to ); global optimisers find the same minima as SciPy’s at a similar cost |
| Cost | Assignment: . Trust region: one Hessian per iteration, plus CG steps (trust-ncg) or a few Cholesky factorisations (trust-exact, dogleg). Global: thousands of evaluations |
| Read first | Newton and quasi-Newton methods, Linear programming, Stochastic global optimisation |
| API | linear_sum_assignment, minimize_trust_region, basinhopping, dual_annealing, direct |
Overview
Three families of scipy.optimize complete the optimisation chapter:
- The linear assignment problem. Assign workers to jobs, or detections to tracks, or pixels to pixels, so that the total cost is
least.
linear_sum_assignmentsolves it exactly, for square or rectangular cost matrices. - Trust-region Newton methods. Line-search Newton methods choose a direction and then a step length. Trust-region methods choose the step
length first and then the best step within it. They are robust when the Hessian is indefinite, and they converge quadratically near a minimum.
trust-ncgneeds only Hessian-vector products,doglegneeds a positive definite Hessian, andtrust-exactsolves the subproblem almost exactly. - Global optimisers for functions with many local minima: basin hopping, a random walk between local minima; dual annealing, generalised simulated annealing with local searches; and DIRECT, a deterministic subdivision of the domain.
Where it is used
Three different tools for problems of different kinds.
- Assignment. Matching workers to tasks, tracked objects to detections in successive video or radar frames, and sources to sinks at least total cost.
- Trust-region methods. Robust minimisation of smooth functions, with second derivatives, in the engineering design and parameter estimation packages that need reliable convergence.
- Global optimisation. Basin hopping and dual annealing search for the lowest energy configuration of a molecule or cluster, and for the best design among many local optima.
History
Harold Kuhn (1955) named his assignment algorithm the “Hungarian method” after Dénes Kőnig and Jenő Egerváry, whose duality results it rests on. Roy Jonker and Anton Volgenant (1987) reorganised it around shortest augmenting paths, which made it the fastest practical method. David Crouse (2016) extended it to rectangular matrices in the form now used by SciPy.
Trust regions go back to Kenneth Levenberg (1944) and Donald Marquardt (1963) for least squares. Michael Powell (1970) introduced the dogleg step, Trond Steihaug (1983) showed that conjugate gradients stopped at the trust-region boundary give a good step at the cost of a few Hessian-vector products, and Jorge Moré and Danny Sorensen (1983) showed how to solve the subproblem to any accuracy, including the “hard case”.
Global optimisation took two routes. Stochastic methods: Scott Kirkpatrick and colleagues (1983) introduced simulated annealing, and Constantino Tsallis and Daniel Stariolo (1996) generalised it with heavy-tailed jumps. Yang Xiang and colleagues (1997) added local searches (“dual annealing”), and David Wales and Jonathan Doye (1997) found the structure of atomic clusters by hopping between local minima. Deterministic methods: Donald Jones, Cary Perttunen and Bruce Stuckman (1993) devised DIRECT, a Lipschitz method that needs no Lipschitz constant, and Jörg Gablonsky and Tim Kelley (2001) made it more local.
The idea
The assignment problem
Given costs , choose a permutation minimising . It is a linear program whose vertices are permutation matrices, and its dual has a variable per row and per column with . The algorithm keeps the reduced costs non-negative and adds one row at a time to the matching. From the new row it finds a shortest augmenting path in the reduced costs, Dijkstra’s algorithm over the columns. The path alternates between unmatched and matched pairs and ends at a free column. Flipping the path grows the matching by one. Updating and by the path lengths keeps the reduced costs non-negative and makes the matched pairs tight (), which certifies optimality at the end. Each path costs , so the whole costs .
A rectangular matrix with more rows than columns is transposed, so every row of the shorter side is matched. Among equal shortest distances, a free column is preferred, and the columns are scanned in reverse order. The port keeps these tie-breaking rules of SciPy’s code, so the two return the same assignment even when there are ties (Table 5.11).
Trust-region methods
At , model by and minimise it within . Then compare the actual and predicted reductions,
If the model is poor and is quartered. If and the step reached the boundary, doubles. The step is accepted if . The three methods differ in how they solve the subproblem:
- Steihaug CG (
trust-ncg) runs conjugate gradients on from . It stops early when the residual is small (relative tolerance , which gives superlinear convergence), when a step leaves the region (it then follows the last direction to the boundary), or when it meets a direction of negative curvature (it then goes to the boundary along it). Only products are needed. - Dogleg follows the path from the origin to the Cauchy point (the model’s minimiser along ) and on to the Newton point , stopping where it leaves the region. must be positive definite. Otherwise the method stops with status 3, as SciPy’s does.
- Moré-Sorensen (
trust-exact) uses the characterisation of the subproblem’s solution: with positive semidefinite, and . It applies Newton’s method to , using one Cholesky factorisation per step, safeguarded by bounds on from Gershgorin’s theorem. A failed factorisation raises the lower bound. In the hard case, is orthogonal to the eigenvector of the smallest eigenvalue. There a step along an estimate of that eigenvector, from a condition estimator, reaches the boundary.
Basin hopping
Basin hopping replaces by the staircase and walks on it. Each hop displaces the current minimum randomly, minimises locally and accepts the new minimum by the Metropolis rule. Every 50 hops the step size is adjusted towards an acceptance rate of one half. It works best when nearby minima are related, as in the energy landscapes of molecules. On functions whose minima are far apart relative to the step it rarely finds the global one (Table 5.13).
Dual annealing
Simulated annealing proposes random moves and accepts uphill ones with a probability that shrinks as the “temperature” falls. Generalised simulated annealing draws moves from Tsallis’s heavy-tailed visiting distribution with parameter . Long jumps stay likely, so the search keeps exploring, and the temperature can fall fast:
An uphill move by is accepted with probability , with . Each iteration runs a chain of moves: all coordinates at once, then one at a time. A local L-BFGS-B search is run whenever the best point improves, and from the chain’s best point after a long stretch without improvement. When the temperature falls below , the search re-anneals from a new random point.
DIRECT
If is Lipschitz with constant , a box with centre value and half-diagonal contains no value below . DIRECT divides the domain into boxes evaluated at their centres. Since is unknown, it divides every box that would be the most promising for some : the boxes on the lower-right convex hull of the points (size, value). Of these it keeps only those whose bound beats the best value by at least . Large boxes are divided for global exploration and boxes with low values for local refinement. A box is trisected along its longest sides, first along the side whose two new centres include the lowest value. The locally biased variant DIRECT-L, SciPy’s default, keeps at most one box per size, which favours refinement (Figure 5.12). DIRECT needs no gradients and no random numbers, and for a Lipschitz function it eventually samples the domain densely.
Figure 5.13. The 600 centres DIRECT-L evaluates on the six-hump camel function. A coarse grid covers the domain, and the subdivision concentrates around the two global minima.
Algorithm
linear_sum_assignment(C): transpose if tall; set ; for each row :
- Find the shortest augmenting path from in the reduced costs to a free column, recording the distance to each scanned column.
- Raise for the scanned rows and lower for the scanned columns by their distance deficits.
- Flip the path.
Trust region: ; while gtol:
- Solve the subproblem for .
- If the predicted reduction is not positive, stop with status 2.
- Update from , and accept the step if .
DIRECT-L: scale to the unit cube and evaluate the centre; repeat:
- Select the potentially optimal boxes, one per size.
- Trisect each along its longest sides in order of the best new value.
- Stop on the evaluation budget (), the iteration limit, or when the best box is tiny.
Implementation
/// The optimal assignment: pairs `(rowᵢ, colᵢ)`, as many as the smaller dimension, sorted by
/// row, minimising `Σ cost[rowᵢ][colᵢ]` (maximising with `maximize`). Each row in turn is joined
/// to the current matching by a shortest augmenting path in the reduced costs, and the dual
/// variables `u`, `v` are updated so that all reduced costs stay non-negative (the Hungarian
/// method's invariant). A tall matrix is transposed first. `O(n³)`. Infinite costs forbid a
/// pair; an error is returned if no complete assignment avoids them, or for NaN or `−∞`.
pub fn linear_sum_assignment(cost: &Array2<f64>, maximize: bool) -> Result<(Vec<usize>, Vec<usize>), ErrorsJSL> {
let (mut nr, mut nc) = cost.dim();
if nr == 0 || nc == 0 {
return Ok((Vec::new(), Vec::new()));
}
let transpose = nc < nr;
let mut c: Vec<f64> = if transpose { cost.t().iter().copied().collect() } else { cost.iter().copied().collect() };
if transpose {
std::mem::swap(&mut nr, &mut nc);
}
if maximize {
c.iter_mut().for_each(|x| *x = -*x);
}
if c.iter().any(|x| x.is_nan() || *x == f64::NEG_INFINITY) {
return Err(ErrorsJSL::InvalidInputRange("the cost matrix contains NaN or −∞"));
}
let (mut u, mut v) = (vec![0.0; nr], vec![0.0; nc]);
let mut shortest = vec![0.0; nc];
let mut path = vec![0usize; nc];
let mut col4row: Vec<Option<usize>> = vec![None; nr];
let mut row4col: Vec<Option<usize>> = vec![None; nc];
let (mut sr, mut sc) = (vec![false; nr], vec![false; nc]);
let mut remaining = vec![0usize; nc];
for cur in 0..nr {
let (sink, min_val) = augmenting_path(nc, &c, &u, &v, &mut path, &row4col, &mut shortest, cur, &mut sr, &mut sc, &mut remaining).ok_or(ErrorsJSL::InvalidInputRange("the cost matrix is infeasible"))?;
u[cur] += min_val;
for i in 0..nr {
if sr[i] && i != cur {
u[i] += min_val - shortest[col4row[i].expect("matched")];
}
}
for j in 0..nc {
if sc[j] {
v[j] -= min_val - shortest[j];
}
}
// Augment along the path back to the current row.
let mut j = sink;
loop {
let i = path[j];
row4col[j] = Some(i);
let previous = col4row[i].replace(j);
if i == cur {
break;
}
j = previous.expect("rows on the path are matched");
}
}
let pairs: Vec<(usize, usize)> = if transpose {
let mut p: Vec<(usize, usize)> = col4row.iter().enumerate().map(|(r, cl)| (cl.expect("matched"), r)).collect();
p.sort_unstable();
p
} else {
col4row.iter().enumerate().map(|(r, cl)| (r, cl.expect("matched"))).collect()
};
Ok(pairs.into_iter().unzip())
}
/// Steihaug-CG: conjugate gradients on `H p = −g` from `p = 0`, stopping at the boundary if
/// a step leaves the region or a direction of negative curvature appears, or when the
/// residual is below `min(½, √‖g‖) ‖g‖`.
fn solve_ncg(&self, radius: f64) -> (Vec<f64>, bool) {
let n = self.jac.len();
let tolerance = 0.5f64.min(self.jac_mag.sqrt()) * self.jac_mag;
if self.jac_mag < tolerance {
return (vec![0.0; n], false);
}
let mut z = vec![0.0; n];
let mut r = self.jac.clone();
let mut d: Vec<f64> = r.iter().map(|v| -v).collect();
loop {
let bd = self.hessp(&d);
let dbd = dot(&d, &bd);
if dbd <= 0.0 {
let (ta, tb) = boundaries(&z, &d, radius);
let pa: Vec<f64> = z.iter().zip(&d).map(|(a, b)| a + ta * b).collect();
let pb: Vec<f64> = z.iter().zip(&d).map(|(a, b)| a + tb * b).collect();
return (if self.value(&pa) < self.value(&pb) { pa } else { pb }, true);
}
let r2 = dot(&r, &r);
let alpha = r2 / dbd;
let z_next: Vec<f64> = z.iter().zip(&d).map(|(a, b)| a + alpha * b).collect();
if norm(&z_next) >= radius {
let (_, tb) = boundaries(&z, &d, radius);
return (z.iter().zip(&d).map(|(a, b)| a + tb * b).collect(), true);
}
let r_next: Vec<f64> = r.iter().zip(&bd).map(|(a, b)| a + alpha * b).collect();
let rn2 = dot(&r_next, &r_next);
if rn2.sqrt() < tolerance {
return (z_next, false);
}
let beta = rn2 / r2;
d = r_next.iter().zip(&d).map(|(a, b)| -a + beta * b).collect();
z = z_next;
r = r_next;
}
}
/// Minimises `f` with gradient and Hessian by a trust-region Newton method (SciPy's
/// `minimize(method='trust-ncg' | 'dogleg' | 'trust-exact')`). Each iteration minimises the
/// quadratic model within a ball of radius `Δ`, compares the actual reduction with the predicted
/// one, `ρ = (f(x) − f(x + p)) / (m(0) − m(p))`, quarters `Δ` if `ρ < ¼`, doubles it (up to the
/// maximum) if `ρ > ¾` and the step reached the boundary, and accepts the step if `ρ > η`.
pub fn minimize_trust_region(
mut f: impl FnMut(&[f64]) -> f64,
mut grad: impl FnMut(&[f64]) -> Vec<f64>,
mut hess: impl FnMut(&[f64]) -> Array2<f64>,
x0: &[f64],
method: TrustRegionMethod,
options: TrustRegionOptions,
) -> Result<TrustRegionResult, ErrorsJSL> {
let o = options;
if !(0.0..0.25).contains(&o.eta) || o.max_trust_radius <= 0.0 || o.initial_trust_radius <= 0.0 || o.initial_trust_radius >= o.max_trust_radius {
return Err(ErrorsJSL::InvalidInputRange("need 0 ≤ η < ¼ and 0 < initial radius < maximum radius"));
}
let max_it = o.max_iterations.unwrap_or(200 * x0.len());
let (mut nfev, mut njev, mut nhev) = (0, 0, 0);
let mut model_at = |x: &[f64]| {
let fun = f(x);
let jac = grad(x);
let h = hess(x);
let jac_mag = norm(&jac);
Model { fun, jac, hess: h, jac_mag, lambda_lb: 0.0, previous_radius: -1.0 }
};
let mut x = x0.to_vec();
let mut m = model_at(&x);
nfev += 1;
njev += 1;
nhev += 1;
let mut radius = o.initial_trust_radius;
let mut k = 0;
let mut status = 0;
while m.jac_mag >= o.gtol {
let (p, hits) = match method {
TrustRegionMethod::Ncg => m.solve_ncg(radius),
TrustRegionMethod::Exact => m.solve_exact(radius),
TrustRegionMethod::Dogleg => match m.solve_dogleg(radius) {
Some(s) => s,
None => {
status = 3;
break;
}
},
};
let predicted = m.value(&p);
let xp: Vec<f64> = x.iter().zip(&p).map(|(a, b)| a + b).collect();
let mp = model_at(&xp);
nfev += 1;
njev += 1;
nhev += 1;
let actual_reduction = m.fun - mp.fun;
let predicted_reduction = m.fun - predicted;
if predicted_reduction <= 0.0 {
status = 2;
break;
}
let rho = actual_reduction / predicted_reduction;
if rho < 0.25 {
radius *= 0.25;
} else if rho > 0.75 && hits {
radius = (2.0 * radius).min(o.max_trust_radius);
}
if rho > o.eta {
x = xp;
m = mp;
}
k += 1;
if m.jac_mag < o.gtol {
status = 0;
break;
}
if k >= max_it {
status = 1;
break;
}
}
Ok(TrustRegionResult { x, fun: m.fun, jac: m.jac, iterations: k, nfev, njev, nhev, status })
}
/// DIRECT, "DIviding RECTangles" (Jones, Perttunen and Stuckman, 1993), in Gablonsky and Kelley's
/// locally biased form DIRECT-L. The domain is scaled to the unit cube and covered by boxes, each
/// evaluated at its centre. Each iteration selects the *potentially optimal* boxes, those on the
/// lower-right convex hull of (size, value), one per size, whose value could be the lowest for some
/// Lipschitz constant `K` with a gain of at least `ε |f_min|`. Each selected box is trisected along
/// its longest sides, the side whose new centres give the lowest value first. No gradients, no
/// randomness: the search balances global exploration (large boxes) against local refinement.
pub fn direct(mut f: impl FnMut(&[f64]) -> f64, lower: &[f64], upper: &[f64], options: DirectOptions) -> Result<GlobalResult, ErrorsJSL> {
let n = lower.len();
if upper.len() != n || n == 0 || lower.iter().zip(upper).any(|(l, u)| u <= l || u.is_nan() || l.is_nan()) {
return Err(ErrorsJSL::InvalidInputRange("need bounds with lower < upper"));
}
let o = options;
let max_fun = o.max_fun.unwrap_or(1000 * n);
let to_x = |c: &[f64]| -> Vec<f64> { c.iter().enumerate().map(|(i, v)| lower[i] + v * (upper[i] - lower[i])).collect() };
let nfev = std::cell::Cell::new(0usize);
let mut eval = |c: &[f64]| {
nfev.set(nfev.get() + 1);
f(&to_x(c))
};
let mut boxes = vec![Box { centre: vec![0.5; n], f: 0.0, levels: vec![0; n] }];
boxes[0].f = eval(&boxes[0].centre);
let mut best = 0usize;
let mut iterations = 0;
'outer: while iterations < o.max_iterations {
iterations += 1;
let fmin = boxes[best].f;
// One candidate per size: the lowest value (DIRECT-L).
let mut by_size: Vec<(f64, usize)> = Vec::new();
for (i, b) in boxes.iter().enumerate() {
let d = b.size();
match by_size.iter_mut().find(|(s, _)| (*s - d).abs() <= 1e-12 * d) {
Some(entry) => {
if b.f < boxes[entry.1].f {
entry.1 = i;
}
}
None => by_size.push((d, i)),
}
}
by_size.sort_by(|a, b| a.0.total_cmp(&b.0));
// From the lowest value (the largest such box) to the largest box, the lower convex hull.
let start = (0..by_size.len()).min_by(|&a, &b| boxes[by_size[a].1].f.total_cmp(&boxes[by_size[b].1].f).then(by_size[b].0.total_cmp(&by_size[a].0))).expect("non-empty");
let mut hull: Vec<usize> = Vec::new();
for k in start..by_size.len() {
let p = (by_size[k].0, boxes[by_size[k].1].f);
while hull.len() >= 2 {
let a = (by_size[hull[hull.len() - 2]].0, boxes[by_size[hull[hull.len() - 2]].1].f);
let b = (by_size[hull[hull.len() - 1]].0, boxes[by_size[hull[hull.len() - 1]].1].f);
// Remove b if it lies on or above the segment a-p.
if (b.1 - a.1) * (p.0 - a.0) >= (p.1 - a.1) * (b.0 - a.0) {
hull.pop();
} else {
break;
}
}
if hull.len() == 1 && boxes[by_size[hull[0]].1].f <= p.1 && hull[0] != start {
hull.pop();
}
hull.push(k);
}
let mut selected = Vec::new();
for (h, &k) in hull.iter().enumerate() {
let (d, fj) = (by_size[k].0, boxes[by_size[k].1].f);
let ok = match hull.get(h + 1) {
Some(&next) => {
let slope = (boxes[by_size[next].1].f - fj) / (by_size[next].0 - d);
fj - slope * d <= fmin - o.eps * fmin.abs()
}
None => true,
};
if ok {
selected.push(by_size[k].1);
}
}
for idx in selected {
if nfev.get() >= max_fun {
break 'outer;
}
let lmin = *boxes[idx].levels.iter().min().expect("non-empty");
let dims: Vec<usize> = (0..n).filter(|&k| boxes[idx].levels[k] == lmin).collect();
let delta = 3f64.powi(-(lmin as i32 + 1));
// (best of the pair, dimension, centre +, value +, centre −, value −)
type Trial = (f64, usize, Vec<f64>, f64, Vec<f64>, f64);
let mut trials: Vec<Trial> = Vec::new();
for &k in &dims {
let mut cp = boxes[idx].centre.clone();
cp[k] += delta;
let fp = eval(&cp);
let mut cm = boxes[idx].centre.clone();
cm[k] -= delta;
let fm = eval(&cm);
trials.push((fp.min(fm), k, cp, fp, cm, fm));
}
trials.sort_by(|a, b| a.0.total_cmp(&b.0).then(a.1.cmp(&b.1)));
let mut levels = boxes[idx].levels.clone();
for (_, k, cp, fp, cm, fm) in trials {
levels[k] += 1;
boxes.push(Box { centre: cp, f: fp, levels: levels.clone() });
boxes.push(Box { centre: cm, f: fm, levels: levels.clone() });
}
boxes[idx].levels = levels;
}
best = (0..boxes.len()).min_by(|&a, &b| boxes[a].f.total_cmp(&boxes[b].f)).expect("non-empty");
let bb = &boxes[best];
let volume: f64 = bb.levels.iter().map(|&l| 3f64.powi(-(l as i32))).product();
if volume < o.vol_tol || 0.5 * bb.size() < o.len_tol || nfev.get() >= max_fun {
break;
}
}
let b = &boxes[best];
Ok(GlobalResult { x: to_x(&b.centre), fun: b.f, nfev: nfev.get(), iterations })
}
- The trust-region code is a port of SciPy’s Python.
trust-exactkeeps a quirk of SciPy’sIterativeSubproblem: after a successful trial factorisation it moves to the new but keeps using the previous Cholesky factor in the next iteration. Without the quirk the iterates would differ from SciPy’s. - The function-evaluation counts match SciPy’s. SciPy evaluates gradients lazily, so its gradient counts are lower than the library’s, which evaluates , and together.
- Basin hopping and dual annealing use L-BFGS-B with SciPy’s two-point finite differences as the local minimiser. SciPy’s basin hopping uses BFGS. Neither can reproduce NumPy’s random streams, so they are compared by their outcomes.
In practice
Every result is compared with SciPy 1.17.1 (references from book/generator/data/make_optim2_refs.py). Assignments, with random costs and with
heavily tied integer costs, are identical:
Table 5.13. `linear_sum_assignment` against SciPy.
| cost matrix | objective | assignment vs SciPy | total cost | difference from SciPy’s total |
|---|---|---|---|---|
| 60 × 60, uniform costs | minimise | identical | 1.486661005023 | 0 |
| 60 × 60, uniform costs | maximise | identical | 58.525961544895 | 0 |
| 40 × 70 | minimise | identical | 0.644174153648 | 0 |
| 40 × 70 | maximise | identical | 39.436226416644 | 0 |
| 70 × 40 | minimise | identical | 0.660844951323 | 0 |
| 70 × 40 | maximise | identical | 39.444965474116 | 0 |
| 30 × 30, integer costs 0–4 (many ties) | minimise | identical | 0.000000000000 | 0 |
| 30 × 30, integer costs 0–4 (many ties) | maximise | identical | 120.000000000000 | 0 |
The trust-region methods take the same steps as SciPy. The iteration and evaluation counts are identical, and so are the points reached. On the
4-D Rosenbrock function from , trust-ncg reaches the global minimum, while trust-exact (here and in SciPy) converges to the
function’s second local minimum near . Dogleg stops at once on the indefinite Hessian:
Table 5.14. Trust-region methods against SciPy, gtol = 10⁻⁸.
| problem | method | iterations (library / SciPy) | function evaluations | status | largest difference in x |
|---|---|---|---|---|---|
| Rosenbrock, n = 4 | trust-ncg | 53 / 53 | 54 / 54 | 0 / 0 | 0 |
| Rosenbrock, n = 4 | trust-exact | 15 / 15 | 16 / 16 | 0 / 0 | 4e-16 |
| Rosenbrock, n = 4 | dogleg | 0 / 0 | 1 / 1 | 3 / 3 | 0 |
| Rosenbrock, n = 10 | trust-ncg | 86 / 86 | 87 / 87 | 0 / 0 | 0 |
| Rosenbrock, n = 10 | trust-exact | 30 / 30 | 31 / 31 | 0 / 0 | 0 |
| Rosenbrock, n = 10 | dogleg | 4 / 4 | 5 / 5 | 3 / 3 | 2e-16 |
| Rosenbrock, n = 4, near the minimum | trust-ncg | 12 / 12 | 13 / 13 | 0 / 0 | 0 |
| Rosenbrock, n = 4, near the minimum | trust-exact | 11 / 11 | 12 / 12 | 0 / 0 | 0 |
| Rosenbrock, n = 4, near the minimum | dogleg | 11 / 11 | 12 / 12 | 0 / 0 | 0 |
| x⁴ − 2x² + y² + xy/2 from near the saddle | trust-ncg | 5 / 5 | 6 / 6 | 0 / 0 | 0 |
| x⁴ − 2x² + y² + xy/2 from near the saddle | trust-exact | 4 / 4 | 5 / 5 | 0 / 0 | 0 |
The global optimisers were run on six standard test functions. A run succeeds if it comes within of the global minimum:
Table 5.15. Global optimisers against SciPy on test functions.
| problem | DIRECT: best value (evaluations), library / SciPy | dual annealing: successes of 20 (median evaluations) | basin hopping, 100 hops: successes of 20 (median evaluations) |
|---|---|---|---|
| camel (2-D, f* = -1.031628) | -1.031628 (2001) / -1.031628 (2001) | 20 (4046) / 20 (4038) | 20 (4395) / 20 (3296) |
| branin (2-D, f* = 0.397887) | 0.397887 (2003) / 0.397887 (2009) | 20 (4031) / 20 (4028) | 20 (2526) / 20 (2110) |
| rastrigin (4-D, f* = 0.000000) | 0.000000 (167) / 0.000000 (235) | 20 (8206) / 20 (8261) | 5 (7870) / 11 (9910) |
| ackley (2-D, f* = 0.000000) | 0.000000 (103) / 0.000000 (237) | 20 (4708) / 20 (4240) | 20 (69840) / 0 (16526) |
| eggholder (2-D, f* = -959.640663) | -936.893598 (2001) / -953.332748 (2011) | 4 (4085) / 5 (4086) | 1 (2052) / 0 (2622) |
| styblinski (3-D, f* = -117.498497) | -117.498497 (3003) / -117.498497 (3021) | 20 (6085) / 20 (6089) | 2 (3500) / 0 (4718) |
Dual annealing is the most reliable: the library and SciPy succeed equally often at the same cost. Only the Eggholder function, whose global minimum sits in a corner of the domain, defeats both most of the time. DIRECT matches SciPy wherever both reach the minimum, sometimes with fewer evaluations, because its stopping test triggers sooner. Basin hopping depends on its local minimiser. With finite-difference L-BFGS-B it reaches Ackley’s minimum, which is a kink at the origin, in every run, but at great cost. SciPy’s BFGS never does. Neither reliably finds minima that are far apart, such as Rastrigin’s and Styblinski-Tang’s.
Strengths
- An exact port of SciPy’s assignment solver and trust-region methods: the same answers, ties and iterates.
- Three complementary global optimisers: a deterministic one (DIRECT), a robust stochastic one (dual annealing) and a fast one for smooth, related minima (basin hopping).
Weaknesses
- The global optimisers’ answers depend on the random seed, and their cost grows quickly with dimension; none certifies global optimality.
- No
trust-krylov,trust-constr,shgoorbrute. - DIRECT stores every box, so memory grows with the evaluation budget.
Exercises
- Show that adding a constant to a row or column of the cost matrix does not change the optimal assignment, and relate this to the dual variables.
- Why does the Steihaug iteration stop at the boundary when it meets negative curvature, rather than taking a full CG step?
- Show that the dogleg path from the origin through the Cauchy point to the Newton point increases monotonically in length when is positive definite.
- For which values of is a candidate solution of the trust-region subproblem, and what is the hard case?
- Show that a box is potentially optimal in DIRECT only if it has the lowest value among the boxes of its size.
Hints and answers
- Every permutation picks exactly one entry from each row and column, so the total changes by the same constant for every assignment. The dual variables are exactly such row and column offsets, which is why the algorithm can work with reduced costs.
- Along a direction of negative curvature the quadratic model decreases without bound, so the best point along it within the region is on the boundary.
- Powell’s lemma: increases along both legs; the second leg’s direction makes an acute angle with the Cauchy point because (Cauchy-Schwarz).
- , with if . In the hard case is orthogonal to the eigenvector of , so stays below as , and the solution is .
- Two boxes of the same size have the same for every , so only the one with the lower value can satisfy against the other.
Further reading
- H. W. Kuhn, “The Hungarian method for the assignment problem”, Naval Research Logistics Quarterly 2 (1955) 83–97.
- D. F. Crouse, “On implementing 2D rectangular assignment algorithms”, IEEE Transactions on Aerospace and Electronic Systems 52 (2016) 1679–1696.
- J. Nocedal and S. J. Wright, Numerical Optimization, 2nd ed., Springer, 2006, chapter 4 (trust-region methods) and algorithm 7.2 (Steihaug CG).
- J. J. Moré and D. C. Sorensen, “Computing a trust region step”, SIAM Journal on Scientific and Statistical Computing 4 (1983) 553–572.
- D. J. Wales and J. P. K. Doye, “Global optimization by basin-hopping and the lowest energy structures of Lennard-Jones clusters containing up to 110 atoms”, Journal of Physical Chemistry A 101 (1997) 5111–5116.
- Y. Xiang, D. Y. Sun, W. Fan and X. G. Gong, “Generalized simulated annealing algorithm and its application to the Thomson model”, Physics Letters A 233 (1997) 216–220.
- D. R. Jones, C. D. Perttunen and B. E. Stuckman, “Lipschitzian optimization without the Lipschitz constant”, Journal of Optimization Theory and Applications 79 (1993) 157–181.
- J. M. Gablonsky and C. T. Kelley, “A locally-biased form of the DIRECT algorithm”, Journal of Global Optimization 21 (2001) 27–37.