Derivative-Free Optimization
Sometimes there is no gradient: the objective is a simulation, a compiled black box, a lab experiment, a game's win rate, or a machine-learning pipeline's validation score. Derivative-free (or "zeroth-order") methods use only function values. They are slower per dimension than gradient methods, so they shine in low dimensions or when each evaluation is expensive and gradients are unavailable or meaningless.
One dimension: golden-section search
For a unimodal function on (one minimum, decreasing then increasing), compare two interior points and discard the part that cannot contain the minimum. Placing the points at the golden ratio lets each step reuse one old evaluation, shrinking the interval by per evaluation:
import numpy as np
def golden_section(f, a, b, tol=1e-8):
r = (np.sqrt(5) - 1) / 2 # 0.618...
c, d = b - r * (b - a), a + r * (b - a)
fc, fd = f(c), f(d); evals = 2
while b - a > tol:
if fc < fd:
b, d, fd = d, c, fc
c = b - r * (b - a); fc = f(c)
else:
a, c, fc = c, d, fd
d = a + r * (b - a); fd = f(d)
evals += 1
return (a + b) / 2, evals
f = lambda x: (x - 2)**2 + np.exp(-x) # unimodal on [0, 5]
x, n = golden_section(f, 0.0, 5.0)
print(f"minimum at x = {x:.6f} after {n} evaluations")minimum at x = 2.063504 after 44 evaluations
Coordinate and pattern search
In several dimensions the simplest method polls a pattern of points around the current one, , moves to any improvement, and halves when none is found. It converges (to stationary points of smooth functions) with no gradient at all, but needs many evaluations as the dimension grows.
import numpy as np
def pattern_search(f, x, h=1.0, tol=1e-6):
fx, evals = f(x), 1
while h > tol:
improved = False
for d in np.vstack([np.eye(len(x)), -np.eye(len(x))]):
y = x + h * d; fy = f(y); evals += 1
if fy < fx:
x, fx, improved = y, fy, True
break
if not improved:
h /= 2
return x, fx, evals
f = lambda p: (1 - p[0])**2 + 100 * (p[1] - p[0]**2)**2
x, fx, evals = pattern_search(f, np.array([-1.2, 1.0]))
print("x =", np.round(x, 4), " f =", f"{fx:.2e}", " evaluations:", evals)x = [0.9997 0.9993] f = 1.07e-07 evaluations: 12985
Many evaluations on Rosenbrock's curved valley, compared with about 40 gradient evaluations for BFGS.
Finite-difference gradients
If is smooth but its gradient is unknown, estimate it with (forward) or (central) extra evaluations and use a gradient method. This is what SciPy does when you call minimize(..., method="BFGS") without jac. It fails when is noisy: the difference quotient divides the noise by .
import numpy as np
rng = np.random.default_rng(0)
f = lambda x: x**2 + 1e-6 * rng.normal() # tiny evaluation noise
for h in (1e-1, 1e-3, 1e-6, 1e-9):
est = (f(1.0 + h) - f(1.0 - h)) / (2 * h)
print(f"h = {h:.0e}: derivative estimate {est:12.6f} (true 2)")h = 1e-01: derivative estimate 2.000001 (true 2)
h = 1e-03: derivative estimate 2.000268 (true 2)
h = 1e-06: derivative estimate 1.551368 (true 2)
h = 1e-09: derivative estimate 180.459541 (true 2)
Model-based and Bayesian methods
When evaluations are very expensive (minutes or hours), fit a surrogate model to the points seen so far and choose the next point by optimizing the model:
| Method | Surrogate | Typical use |
|---|---|---|
| trust-region DFO (COBYLA, BOBYQA, NEWUOA) | linear or quadratic interpolation | engineering design, up to ~100 variables |
| Bayesian optimization | Gaussian process + acquisition function | hyperparameter tuning, experiments |
| response surfaces | low-order polynomial regression | industrial experiments |
In software
scipy.optimize.minimize_scalar(Brent's method: golden section plus parabolic interpolation),minimize(method="Nelder-Mead" | "Powell" | "COBYLA" | "COBYQA"); NLopt, Py-BOBYQA.- Hyperparameter tuning libraries (Optuna, scikit-optimize, Ray Tune) use Bayesian optimization and tree-structured Parzen estimators.
Go further: Tuning hyperparameters is a derivative-free problem too: Bayesian Optimisation and Optuna uses a Gaussian-process surrogate to choose each trial.
Exercises
Exercise 1: Interval shrinkage
How many golden-section evaluations shrink an interval of length 1 below ?
Answer
About 30.
Solution
gives , so 29 shrinking steps plus the two initial evaluations.
Exercise 2: Unimodal?
Can golden-section search find the global minimum of on ?
Answer
Not reliably: the function has several local minima, so it is not unimodal there.
Solution
The method's discarding step assumes a single valley. With several valleys it converges to one of them, depending on the first comparisons.
Exercise 3: SciPy's Brent (code)
Minimize with minimize_scalar and compare its evaluation count with golden section.
Answer
Brent's method needs far fewer evaluations.
Solution
import numpy as np
from scipy.optimize import minimize_scalar
r = minimize_scalar(lambda x: (x - 2)**2 + np.exp(-x), bracket=(0, 5), method="brent", tol=1e-8)
print(round(r.x, 6), r.nfev)2.063504 13
Parabolic interpolation converges superlinearly on smooth functions; golden section is only linear but is the safe fallback Brent switches to when the parabola misbehaves.
Test yourself
Golden-section search requires the function to be…
- differentiable
- unimodal on the interval
- convex in two dimensions
- linear
Why do finite-difference gradients fail for noisy functions?
- The noise is divided by the small step
- They are too accurate
- They need the Hessian
- They only work in 1D
Bayesian optimization is most attractive when…
- each evaluation is very expensive and the dimension is modest
- gradients are cheap
- there are millions of variables
- the function is linear