Search

Search papers and lessons

Expected Improvement

Level 3 · 11 min read

Expected improvement scores a candidate by the average amount it beats the best result so far, using the model's predicted mean and uncertainty, so it rewards both promise and doubt.

On this page

  • Colour = topic mix
  • Probability
  • Linear algebra
  • Discrete math
  • Calculus
  • Inference
  • Optimizers
  • ReadReady to readNot yet

TL;DR

Expected improvement is an acquisition function: a score that says how worth trying each input is. For a candidate input, it is the average amount by which the result could beat the best value seen so far, averaged over what the model thinks the true value might be. It is large when the predicted mean is already above the best value, and also when the uncertainty is large enough that a surprise is possible. Because it has a closed form for a Gaussian model, it can be computed at thousands of candidates in a moment.

Builds on: Acquisition Function, Gaussian (Normal) Distribution, Expected Value · Leads to: Bayesian Optimization

Where it's used

Tuning machine learning models. A team training a neural network has budget for about 30 runs, each taking hours. After each run, a Gaussian process models validation accuracy against the settings. Expected improvement picks the next setting to try, so that the runs are spent where a better result is most likely to come from.

Designing a physical process. A chemist choosing reaction temperatures and times wants the highest yield from a few dozen experiments. The model suggests the next condition by expected improvement over the best yield so far, which favours both conditions near the best and conditions the model knows least about.

Engineering simulations. An aircraft designer tunes a few shape parameters against a simulator that takes hours per run. Expected improvement is one of the standard scores in the software that runs these loops, as described in Bayesian Optimization.

How it works

Here is one tiny case. We are maximising a function. The best value so far is f* = 1.0. The model predicts, for two candidates, a mean and a standard deviation.

  • Candidate A: mean μ = 1.0, standard deviation σ = 0.5.
  • Candidate B: mean μ = 0.8, standard deviation σ = 0.5.
flowchart LR
  A[Predicted mean and sd] --> B[Gap from best so far]
  B --> C[Standardise to Z]
  C --> D[Two Gaussian terms]
  D --> E[Expected improvement]
  E --> F[Pick the largest]
  1. Find the gap. The gap is how far the predicted mean sits above the best value so far: μ − f*. For A, the gap is 1.0 − 1.0 = 0. For B, it is 0.8 − 1.0 = −0.2. Check: a negative gap means the model expects the candidate to fall short of the best.
  2. Standardise the gap. Divide the gap by the uncertainty: Z = (μ − f*) / σ. For A, Z = 0. For B, Z = −0.2 / 0.5 = −0.4. Check: Z says how many standard deviations the mean sits above the best value. A negative Z means the mean is below it.
  3. Read the probability of beating the best. The standard normal distribution function Φ(Z) gives the chance that the true value exceeds f*. Φ(0) = 0.5 for A, and Φ(−0.4) ≈ 0.345 for B. Check: a candidate centred on the best has an even chance of beating it.
  4. Read the density at Z. The standard normal density φ(Z) measures how much probability sits near the threshold. φ(0) ≈ 0.399 for A, and φ(−0.4) ≈ 0.368 for B. Check: the density is largest at Z = 0 and falls off on both sides.
  5. Combine into the score. EI = (μ − f*) × Φ(Z) + σ × φ(Z). For A, EI = 0 × 0.5 + 0.5 × 0.399 ≈ 0.20. For B, EI = −0.2 × 0.345 + 0.5 × 0.368 ≈ −0.069 + 0.184 ≈ 0.12. Check: A scores higher than B, and both are positive.
  6. Pick the largest. The next trial goes to A. Check: A has the same uncertainty as B but a higher mean, and that is what the first term rewards.

Candidate A's score comes entirely from its uncertainty: its expected gain is zero on average in the first term, but a spread of 0.5 means it could easily land above 1.0. That is the idea in one sentence. Expected improvement is the average of the positive part of a surprise, so spread counts as much as height.

The math

Definition: Expected improvement

Let f(x)f(x) be the unknown value at input xx (to maximise), f∗f^* the best value observed so far, and suppose the model says f(x)∼N(μ,σ2)f(x) \sim \mathcal{N}(\mu, \sigma^2). The expected improvement at xx is the average of the amount by which f(x)f(x) beats f∗f^*, counting zero when it does not: EI⁡(x)=E[max⁡(f(x)−f∗,0)].\operatorname{EI}(x) = \mathbb{E}\big[\max(f(x) - f^*, 0)\big].

Step 1 in symbols: the improvement

The improvement is I=max⁡(f(x)−f∗,0)I = \max(f(x) - f^*, 0). It is zero whenever the value falls at or below the best so far, and it is the excess otherwise. Taking the expectation averages both cases.

Step 2 in symbols: the Gaussian model

The model's belief about f(x)f(x) is a Gaussian with mean μ\mu and standard deviation σ\sigma, so its density is p(f)=ϕ((f−μ)/σ)/σp(f) = \phi\big((f - \mu)/\sigma\big)/\sigma, where ϕ\phi is the standard normal density, and its distribution function is Φ\Phi (see Probability Density Function and Cumulative Distribution Function). Write f=μ+σzf = \mu + \sigma z with zz standard normal, and let z0=(f∗−μ)/σz_0 = (f^* - \mu)/\sigma. The improvement is positive only when z>z0z > z_0.

Step 3 in symbols: the integral

The expectation becomes

EI⁡=∫z0∞(μ+σz−f∗) ϕ(z) dz=(μ−f∗)∫z0∞ϕ(z) dz+σ∫z0∞z ϕ(z) dz.\operatorname{EI} = \int_{z_0}^{\infty} (\mu + \sigma z - f^*)\, \phi(z)\, dz = (\mu - f^*) \int_{z_0}^{\infty} \phi(z)\, dz + \sigma \int_{z_0}^{\infty} z\, \phi(z)\, dz.

Each integral has a known value. The first is the probability that zz exceeds z0z_0, which by symmetry of ϕ\phi is Φ(−z0)\Phi(-z_0). The second uses the fact that zϕ(z)z\phi(z) is minus the derivative of ϕ(z)\phi(z), so its integral from z0z_0 to infinity is ϕ(z0)\phi(z_0). Since −z0=(μ−f∗)/σ=Z-z_0 = (\mu - f^*)/\sigma = Z and ϕ\phi is symmetric, ϕ(z0)=ϕ(Z)\phi(z_0) = \phi(Z).

Step 4 in symbols: the closed form

Putting the two pieces together,

EI⁡(x)=(μ−f∗) Φ(Z)+σ ϕ(Z),Z=μ−f∗σ.\operatorname{EI}(x) = (\mu - f^*)\, \Phi(Z) + \sigma\, \phi(Z), \qquad Z = \frac{\mu - f^*}{\sigma}.

This is the formula used in the walkthrough. The first term is the expected gain weighted by the chance of beating f∗f^*, and the second is the expected gain from the spread. The second term is never negative. The first is negative whenever μ\mu is below f∗f^*, and then the spread term must make up the difference. When σ=0\sigma = 0 the value of the candidate is known, and EI is max⁡(μ−f∗,0)\max(\mu - f^*, 0).

The next trial is the input that maximises this score: xn+1=arg⁡max⁡xEI⁡(x)x_{n+1} = \arg\max_x \operatorname{EI}(x). In practice the maximisation is done over many candidate inputs, since the formula is cheap to evaluate.

Worked examples

Example
Example 1: a candidate exactly at the best (tiny)

Setup: f∗=2f^* = 2, a candidate with μ=2\mu = 2 and σ=1\sigma = 1.

  1. The gap is μ−f∗=0\mu - f^* = 0, so Z=0Z = 0.
  2. Φ(0)=0.5\Phi(0) = 0.5 and ϕ(0)≈0.399\phi(0) \approx 0.399.
  3. EI =0×0.5+1×0.399≈0.40= 0 \times 0.5 + 1 \times 0.399 \approx 0.40.

Interpretation: a candidate whose mean equals the best value scores exactly σϕ(0)\sigma \phi(0). The only source of expected gain is the uncertainty.

Example
Example 2: a candidate below the best, with some doubt (standard)

Setup: f∗=0.9f^* = 0.9, a candidate with μ=0.7\mu = 0.7 and σ=0.2\sigma = 0.2.

  1. The gap is 0.7−0.9=−0.20.7 - 0.9 = -0.2.
  2. Z=−0.2/0.2=−1.0Z = -0.2 / 0.2 = -1.0.
  3. Φ(−1)≈0.1587\Phi(-1) \approx 0.1587, so the chance of beating the best is about 16 percent. ϕ(−1)=ϕ(1)≈0.2420\phi(-1) = \phi(1) \approx 0.2420.
  4. The first term is −0.2×0.1587≈−0.0317-0.2 \times 0.1587 \approx -0.0317.
  5. The second term is 0.2×0.2420≈0.04840.2 \times 0.2420 \approx 0.0484.
  6. EI =−0.0317+0.0484≈0.017= -0.0317 + 0.0484 \approx 0.017.

Interpretation: the candidate is expected to fall short, but its doubt keeps its score positive. A candidate with a higher mean and no uncertainty would score more, and one with larger uncertainty and the same mean would also score more.

Example
Example 3: choosing the next learning rate (realistic)

Setup: a tuning run has reached 91 percent validation accuracy at its best so far, so f∗=0.91f^* = 0.91. A Gaussian process predicts, for a new learning rate, a mean accuracy of 0.93 with standard deviation 0.02.

  1. The gap is 0.93−0.91=0.020.93 - 0.91 = 0.02.
  2. Z=0.02/0.02=1.0Z = 0.02 / 0.02 = 1.0.
  3. Φ(1)≈0.8413\Phi(1) \approx 0.8413, so the chance of beating 91 percent is about 84 percent. ϕ(1)≈0.2420\phi(1) \approx 0.2420.
  4. The first term is 0.02×0.8413≈0.01680.02 \times 0.8413 \approx 0.0168.
  5. The second term is 0.02×0.2420≈0.00480.02 \times 0.2420 \approx 0.0048.
  6. EI =0.0168+0.0048≈0.022= 0.0168 + 0.0048 \approx 0.022.

Interpretation: this is a strong candidate. The model expects it to win, and it is confident enough that the gain is likely to be real.

Try it: a second learning rate has predicted mean 0.90, standard deviation 0.02, with the same best value f∗=0.91f^* = 0.91. Compute its expected improvement to three decimal places. Answer: the gap is −0.01-0.01, so Z=−0.5Z = -0.5. Φ(−0.5)≈0.3085\Phi(-0.5) \approx 0.3085 and ϕ(0.5)≈0.3521\phi(0.5) \approx 0.3521. EI =−0.01×0.3085+0.02×0.3521≈−0.0031+0.0070≈0.004= -0.01 \times 0.3085 + 0.02 \times 0.3521 \approx -0.0031 + 0.0070 \approx 0.004. The candidate scores well below the first, but not zero, because its uncertainty still leaves a chance of a surprise.

Common mistakes and tradeoffs

It is tempting to think expected improvement simply picks the candidate with the highest predicted mean. In fact it trades that off against uncertainty. A candidate with a lower mean and a larger standard deviation can win, because it offers more chance of a surprise. Picking the highest mean is pure exploitation and can get stuck near a local best.

It is tempting to think expected improvement is the probability of beating the best. That quantity is probability of improvement, Φ(Z)\Phi(Z), which ignores how large the gain would be. Expected improvement weights each possible gain by its size, so a candidate that wins by a lot scores more than one that wins by a little.

It is tempting to think f∗f^* is a fixed fact about the function. In fact it is the best value observed so far, and it changes as the search proceeds. With noisy measurements, f∗f^* is often taken as the largest predicted mean at the observed inputs, because a single noisy reading can be a lucky high.

Use expected improvement when the model gives a Gaussian belief at each input, as a Gaussian process does, and when each evaluation is expensive. It needs no tuning parameters, which is one reason it is a common default. Do not use it without checking that the model's uncertainty is calibrated, since the score is only as good as the standard deviations it uses. Alternatives include upper confidence bound, which adds a fixed multiple of the standard deviation to the mean, and probability of improvement, which is simpler but ignores gain size. For many parallel evaluations, batch variants of expected improvement exist.

History

In the 1960s, Harold Kushner proposed choosing the next trial of a noisy one-dimensional function by a probability-of-improvement rule. Jonas Mockus and colleagues, in the 1970s, framed the same problem as Bayesian decision-making and introduced expected improvement. For decades the idea was used mainly in engineering design and geostatistics.

It caught on in machine learning in the 2000s and early 2010s, when hyperparameter tuning became expensive. Jones, Schonlau and Welch (1998) gave the widely used "efficient global optimization" method, which pairs a Gaussian process with expected improvement. Snoek, Larochelle and Adams (2012) showed that the approach works for tuning neural networks in practice.

Recap

  • Setup: a model gives a mean and standard deviation at each candidate, and the best value so far is f∗f^*.
  • Gap and standardise: Z=(μ−f∗)/σZ = (\mu - f^*)/\sigma says how far the candidate is above the best, in standard deviations.
  • Two terms: (μ−f∗)Φ(Z)(\mu - f^*)\Phi(Z) is the expected gain from the mean, and σϕ(Z)\sigma\phi(Z) is the expected gain from the spread.
  • Choice: the next trial is the candidate with the largest score.
  • Read next: Bayesian Optimization for the full loop that uses this score, and Gaussian Process Regression for where the mean and spread come from.

Check yourself

QuestionWhy does expected improvement give a positive score to a candidate whose predicted mean is below the best value so far?Show answer

Because the model is uncertain. The standard deviation leaves a chance that the true value exceeds the best, and the term sigma times phi of Z counts the expected gain from that chance. A candidate with no uncertainty and a mean below the best would score zero.

QuestionComputation: the best value so far is 0.5. A candidate has mean 0.5 and standard deviation 0.1. What is its expected improvement, to two decimal places?Show answer

The gap is 0, so Z = 0. The first term is 0. The second term is 0.1 times phi of 0, which is 0.1 times 0.399, about 0.04. The expected improvement is about 0.04.

QuestionWhy does a large standard deviation alone not guarantee a high expected improvement score?Show answer

The score is σϕ(Z)+(μ−f∗)Φ(Z)\sigma\phi(Z) + (\mu - f^*)\Phi(Z). When μ\mu is well below f∗f^*, ZZ is very negative, so ϕ(Z)\phi(Z) is small and the negative first term pulls the score down. The spread helps, but only in proportion to the gap, so a candidate far below the best needs a very large σ\sigma to compete with a moderate candidate whose mean is near the best.

QuestionApplied: a team using expected improvement sees the search keep sampling the same region with small improvements, and never try a distant one. What could explain this, and what would you check?Show answer

A likely cause is that the model's standard deviations are too small in the distant region, so the spread term looks negligible there, or that the best value is noisy and has been inflated by a lucky measurement. Check whether the model's uncertainty is calibrated by comparing predicted and observed errors, and check how f* is defined under noise. Adding a small exploration bonus or a different kernel length scale are common fixes.

Sources