Foundations to Frontier
Tests
A. Mathematical Foundations › A6 Optimization › Advanced

Zeroth-Order and Derivative-Free Optimization

Sometimes all you can do is evaluate the objective: a physics simulation, a hardware test, a closed-source tool, a non-differentiable controller cost. Derivative-free methods optimize using function values only. You will learn finite differences and their error/step trade-off, random-direction (two-point) gradient estimators and why they cost about d times more evaluations, direct-search methods like Nelder–Mead and pattern search, and tune a PID controller on a simulated plant as a black box.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Tuning by trying

Suppose you’re tuning the three knobs of a controller, and the only thing you can do is run a test and read a score. No formula, no slope, just “try settings, get a number”. You can still improve: try nearby settings and keep what’s better, nudge in the direction that helped, or shrink your search when you’re close.

That’s derivative-free (or zeroth-order) optimization: optimizing with function values alone.

Optimizing a black box: no gradients allowed
1e-41e-21e01e2function evaluations → 300
best true value after 300 evaluations: Nelder–Mead 0.0e+0 · ZO-SGD 1.2e+0 · random search 2.0e-2
Only function values are available, as with a simulation, a hardware experiment or a non-differentiable controller cost. Nelder–Mead reflects, expands and shrinks a triangle of trial points. ZO-SGD estimates a gradient from two nearby evaluations along a random direction. Random search just samples. In 2-D they're all workable. Each costs roughly d times more evaluations per unit of progress than a gradient method, and noise and kinks hurt the gradient estimators most.
Why engineers care

Controller gains tuned on hardware, simulator parameters fitted to flight data, CFD shapes, and hyperparameters of learning systems are all black boxes. Derivative-free methods are the honest tool when gradients are unavailable, unreliable or too costly. Their scaling with dimension tells you when to switch to Bayesian optimization (A6.4-2) or evolution strategies (A6.4-3).

📝 Quick check (Level 0)
0/3 answered
  1. 1. A derivative-free method uses…
  2. 2. Which is a black-box objective?
  3. 3. Compared with gradient methods, derivative-free methods usually need…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Finite differences

  • Forward: ∂if≈f(x+hei)−f(x)h\partial_if\approx\frac{f(x + he_i) - f(x)}h, with error O(h)O(h) and d+1d + 1 evaluations per gradient.
  • Central: ∂if≈f(x+hei)−f(x−hei)2h\partial_if\approx\frac{f(x + he_i) - f(x - he_i)}{2h}, with error O(h2)O(h^2) and 2d2d evaluations.

Smaller hh reduces truncation error but amplifies floating-point rounding. The best forward step is about εmach≈10−8\sqrt{\varepsilon_{\text{mach}}}\approx10^{-8}, and for central differences about ε1/3≈10−5\varepsilon^{1/3}\approx10^{-5}. With noisy objectives, hh must be much larger.

Nelder–Mead keeps a simplex of d+1d + 1 points. It reflects the worst point through the centroid of the others, expands if that helps a lot, contracts if not, and shrinks toward the best point if all else fails. It’s simple and robust for small dd and non-smooth costs, but has no general convergence guarantee. Pattern (compass) search tries ±\pm steps along each axis and halves the step when nothing improves. It provably converges for smooth functions.

📝 Quick check (Level 1)
0/3 answered
  1. 1. Central differences have error…
  2. 2. A Nelder–Mead simplex in d dimensions has…
  3. 3. Making h extremely small in finite differences…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

Random-direction gradient estimators

Draw u∼N(0,I)u\sim\mathcal N(0, I) and estimate

g^=f(x+μu)−f(x−μu)2μ u\hat g = \frac{f(x + \mu u) - f(x - \mu u)}{2\mu}\,u

It’s an unbiased estimate of ∇fμ\nabla f_\mu, the gradient of the Gaussian-smoothed fμ(x)=Ef(x+μu)f_\mu(x) = \mathbb E f(x + \mu u), at a cost of 2 evaluations. Plugging it into SGD gives zeroth-order SGD. Its variance scales like d∥∇f∥2d\|\nabla f\|^2, so convergence needs about dd times more iterations than GD (Nesterov and Spokoiny, 2017). This factor-d penalty is unavoidable for zeroth-order methods in general (Duchi et al., 2015).

Choosing a derivative-free method

Situation Good choice
d ≲ 10, cheap, non-smooth Nelder–Mead, pattern search
d ≲ 20, expensive, smooth-ish Bayesian optimization (A6.4-2), model-based trust region
d large, parallel evaluations, noisy Evolution strategies / CMA-ES (A6.4-3), ZO-SGD
gradients available but slow automatic or adjoint differentiation instead

Noise

With measurement noise σ\sigma, finite-difference error grows like σ/h\sigma/h. Use larger hh, average repeated evaluations, or fit a local model (regression over many points), as in trust-region DFO methods like COBYLA and BOBYQA (Powell, 2009).

🐍 Exercise 1: finite differences and random-direction estimators
Implement forward and central finite differences, the two-point random-direction estimator and ZO-SGD. Verify the O(h) and O(h²) error orders, unbiasedness, and the factor-d cost of zeroth-order optimization.
📝 Quick check (Level 2)
0/3 answered
  1. 1. The two-point random-direction estimator is unbiased for the gradient of…
  2. 2. Zeroth-order SGD typically needs about … more iterations than GD
  3. 3. For noisy black boxes, finite-difference steps should be…

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Error of forward differences

Taylor: f(x+h)=f(x)+hf′(x)+h22f′′(ξ)f(x + h) = f(x) + hf'(x) + \frac{h^2}2f''(\xi), so the truncation error is h2∣f′′∣\frac h2|f''|. Rounding error in each evaluation is about ε∣f∣\varepsilon|f|, which contributes 2ε∣f∣/h2\varepsilon|f|/h. Minimizing h2∣f′′∣+2ε∣f∣h\frac h2|f''| + \frac{2\varepsilon|f|}h gives h⋆=2ε∣f∣/∣f′′∣h^\star = 2\sqrt{\varepsilon|f|/|f''|}. For unit scales that’s ≈2ε\approx2\sqrt\varepsilon. ∎ For central differences the f′′f'' terms cancel, leaving h26∣f′′′∣\frac{h^2}6|f'''|.

Unbiasedness of the smoothed estimator

By Stein’s lemma, for u∼N(0,I)u\sim\mathcal N(0, I), E[f(x+μu)u]=μ∇fμ(x)\mathbb E[f(x + \mu u)u] = \mu\nabla f_\mu(x). By symmetry, E[f(x−μu)u]=−μ∇fμ(x)\mathbb E[f(x - \mu u)u] = -\mu\nabla f_\mu(x). Subtracting and dividing by 2μ2\mu gives Eg^=∇fμ(x)\mathbb E\hat g = \nabla f_\mu(x). ∎ Also ∣fμ−f∣≤Lμ2d2|f_\mu - f|\le\frac{L\mu^2d}2, so small μ\mu keeps the bias small.

Why the factor d?

For a linear f=g⊤xf = g^\top x, g^=(g⊤u)u\hat g = (g^\top u)u, so E∥g^∥2=(d+2)∥g∥2\mathbb E\|\hat g\|^2 = (d + 2)\|g\|^2. The estimate is dd times noisier than the true gradient, so the step size must shrink by about dd, and the iteration count grows by dd. ∎

Exercise 3.1: Best forward-difference step with ε = 10⁻¹⁶ and unit scales

h⋆=210−16=2×10−8h^\star = 2\sqrt{10^{-16}} = 2\times10^{-8}.

📝 Quick check (Level 3)
0/3 answered
  1. 1. The optimal forward-difference step scales as…
  2. 2. Unbiasedness of the smoothed estimator follows from…
  3. 3. For linear f, E‖ĝ‖² equals…

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

Tuning a PID controller as a black box

The plant is a lightly damped second-order system with a saturating actuator. The cost is the integrated squared error plus an overshoot penalty plus control effort, measured by simulating a step response. The cost isn’t differentiable (saturation, max), so treat it as a black box. Starting from hand-picked gains, Nelder–Mead cuts the cost by about 4× in roughly 225 simulations and beats random search with the same budget. This is how gains are often refined on test rigs and in simulation-in-the-loop design.

🐍 Exercise 2 (research): black-box PID tuning
Implement Nelder–Mead and a simulated PID step-response cost with actuator saturation. Tune the gains and compare with random search at equal budget.

Derivative-free optimization in AI, robotics and aerospace

  • Controller and gait tuning on hardware, where every evaluation is a real experiment (Calandra et al., 2016, BO for bipedal gaits).
  • Aerodynamic shape and mission design with black-box CFD or trajectory tools: direct search and surrogate models (Conn, Scheinberg and Vicente, 2009).
  • Black-box adversarial attacks and prompt tuning use ZO gradient estimators (Chen et al., 2017, ZOO).
  • Memory-efficient fine-tuning: MeZO fine-tunes large language models with zeroth-order SGD using only forward passes (Malladi et al., 2023).

References

  1. J. Nelder, R. Mead (1965). “A simplex method for function minimization.” The Computer Journal, 7(4).
  2. A. Conn, K. Scheinberg, L. Vicente (2009). Introduction to Derivative-Free Optimization. SIAM.
  3. Y. Nesterov, V. Spokoiny (2017). “Random gradient-free minimization of convex functions.” Foundations of Computational Mathematics, 17.
  4. J. Duchi, M. Jordan, M. Wainwright, A. Wibisono (2015). “Optimal rates for zero-order convex optimization: the power of two function evaluations.” IEEE Transactions on Information Theory, 61(5).
  5. M. J. D. Powell (2009). “The BOBYQA algorithm for bound constrained optimization without derivatives.” Cambridge NA Report NA2009/06.
  6. J. Larson, M. Menickelly, S. Wild (2019). “Derivative-free optimization methods.” Acta Numerica, 28.
  7. R. Calandra, A. Seyfarth, J. Peters, M. Deisenroth (2016). “Bayesian optimization for learning gaits under uncertainty.” Annals of Mathematics and Artificial Intelligence, 76.
  8. P.-Y. Chen et al. (2017). “ZOO: zeroth order optimization based black-box attacks to deep neural networks.” AISec.
  9. S. Malladi et al. (2023). “Fine-tuning language models with just forward passes.” NeurIPS (MeZO).
  10. C. Stein (1981). “Estimation of the mean of a multivariate normal distribution.” Annals of Statistics, 9(6).