Algorithmadvanced
Full waveform inversion
Also called FWI, waveform tomography.
Estimate the subsurface velocity by minimizing the misfit between recorded and simulated full wavefields, with gradients from the adjoint-state method.
- Time
- O(k e s g) totalO(s g) gradient_per_shot
- Space
- O(s g) stored_forward_field
- Where
- e = the number of shots; g = the number of grid points; k = the number of iterations; s = the number of time steps
- Model
- Real RAM
- Properties
- deterministicexact discrete gradientlocal optimizationnonlinear
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Albert Tarantola, Patrick Lailly, 1984
Full waveform inversion (FWI) estimates the velocity of the subsurface by fitting whole recorded seismograms. It simulates the data for a model with the wave equation, measures the misfit , and lowers it with a gradient method. The gradient comes from the adjoint-state method at the cost of one forward and one backward simulation per shot, and it is a reverse-time migration of the data residuals. FWI looks like 4D-Var of weather forecasting, which also fits a time-dependent model to observations with an adjoint. The difference is in the unknowns: 4D-Var fits the initial state of the forecast over a time window and adds a background term, while FWI fits the coefficients of the wave equation (the velocity), with a known source and zero initial state. is not convex, so FWI is a local method: it needs a starting model whose predicted events are within half a period of the recorded ones, or it fails by cycle skipping (a heuristic rule that is a theorem for one shifted sinusoid).
In plain words
FWI guesses a model of the wave speeds in the ground, simulates the seismograms that this model would give, and compares them with the real ones, sample by sample. Then it changes the model a little in the direction that makes the difference smaller, and repeats. The direction comes from playing the differences backward in time from the receivers and comparing them with the forward simulation, which costs about two simulations. Because it uses every wiggle of the seismograms, FWI can find much finer detail than methods that use only arrival times. The catch is that the first guess must be close: if a simulated wiggle is off by more than half a wiggle, the method matches it to the wrong one.
The problem
Given the recorded data of one or more shots, a known source , and a starting model , find
where solves the wave equation with . This is a nonlinear inverse problem and a nonlinear least-squares problem with a very large number of unknowns.
The algorithm
The scheme is with the second difference , and the CFL condition. The gradient of the discrete comes from the adjoint state of this scheme.
FWI-GRADIENT(m, f, receivers, d, Δt, h) ▷ one shot; L: the second difference- 1
u^0, ..., u^N ← the forward run of the scheme with the source f; store all fields - 2
res^n_r ← u^n_r - d^n_r for every step n and receiver r; J ← (1/2) Σ (res^n_r)² - 3
λ1 ← 0; λ2 ← 0; g ← 0 ▷ the adjoint field at the steps k + 1 and k + 2 - 4
for k ← N down to 1 do λ ← 2 λ1 - λ2 + (Δt² / m) L λ1 - 5
λ[r] ← λ[r] + res^k_r / m[r] for every receiver r ▷ inject the residuals - 6
g ← g - λ · (u^k - 2 u^(k-1) + u^(k-2)); λ2 ← λ1; λ1 ← λ - 7
return J, g
The outer loop is gradient descent: compute , take the trial step with chosen so that the largest change is 5 percent of , and halve until the model stays positive and the Armijo condition holds (backtracking line search). Line L1 is one forward simulation with all fields stored. Line L2 forms the residuals. Lines L4 and L5 run the transposed scheme backward in time with the residuals as the source; this is the same backward run as reverse-time migration. Line L6 correlates the adjoint field with the second time difference of the forward field, which is the derivative of the scheme with respect to .
Example
The half-period rule by hand. In the 1D test, the source and the receiver are 550 m apart and the true velocity is 2000 m/s, so the direct wave arrives after 0.275 s. A 15 Hz wavelet has the period 0.0667 s. For a constant starting velocity , the predicted arrival is , and the half-period rule asks for s, which gives m/s. The measured misfit has its barrier at about 1800 m/s and a false minimum at 1625 m/s, where the predicted pulse is about one period late; see cycle skipping.
A 1D inversion. The test model has 60 cells of 10 m, 2000 m/s over 2400 m/s below cell 25, and a Gaussian bump of 300 m/s at cell 40. The source is at cell 2, the receivers are at cells 2 and 57, and the wavelet is a 15 Hz Ricker wavelet over 300 steps of 2 ms. From a constant 2200 m/s, 10 iterations of the descent loop lower the misfit from 2392.8 to 75.05, 3.1 percent of the start, and every iteration lowers it (measurements on this case). The adjoint gradient agrees with centered finite differences to a relative error of about .
Correctness
The full proof is in proofs/correctness.md.
- Exact discrete gradient (theorem). Line L7 returns and , where solves the transposed scheme with . This is the exact gradient of the discrete misfit, with no gap between the continuous and the discrete adjoint. A loop invariant matches line L4 to this recursion.
- The descent loop (theorem). The loop keeps every model positive and the misfit history non-increasing, and it uses at most extra forward runs per iteration plus one at the end. For a small enough step the Armijo condition holds whenever .
- Zero residual (theorem). At the true model the residual is zero, so the adjoint source and the gradient are zero.
That the descent reaches the true model is not a theorem. It needs a starting model within the basin of attraction, which the half-period rule estimates (a heuristic).
Proof: Correctness of full waveform inversionfull
Setting. The model is a vector of squared slownesses on the cells of a 1D grid. is the second difference with zero values outside the grid, a real symmetric matrix; ; samples a field at the receiver cells. The forward scheme of line L1 is, for ,
where does not depend on . Put . The data residual is for , and the misfit is . Each is a rational function of without poles on , so is smooth there.
Theorem 1 (the exact gradient). Let and, for ,
Then
and the function gradient returns and this vector at line L7.
Proof. Differentiate the scheme in a direction , with the derivative of . Since is fixed,
Collect . This is the block lower-triangular system with
for (terms with an index below 1 are zero). has the invertible block on its diagonal. Its transpose is
with , because is diagonal and is symmetric. The recursion of the theorem is solved for from down to 1. The derivative of is
where the term is 0 because . Read off the coefficient of .
Now the code. Line L1 runs the scheme and stores . Line L2 forms , and is computed from it. Line L3 sets . Loop invariant: at the start of the pass for at line L4, lam1 , lam2 , and g . In the pass, line L4 computes , and line L5 adds (a cell that holds two receivers gets both terms, as requires), so lam . Line L6 subtracts , with for . The shift gives the invariant for . After passes, line L7 returns and the full sum.
So the gradient costs one forward and one backward propagation, whatever the number of cells. It is the gradient of the discrete misfit, so a central-difference check agrees with it up to the truncation and rounding error of the check.
Theorem 2 (the descent loop). In full_waveform_inversion, every accepted model is positive, the list of misfits is non-increasing, and the loop stops after at most iters gradient evaluations and iters extra forward runs. If , the Armijo condition with holds for every small enough .
Proof. A trial is accepted only if all its entries are positive and . If no trial is accepted in 30 halvings, the loop stops with unchanged. So consecutive entries of the history do not increase, and the last entry is of the returned model. The counts follow from the two loop bounds. For the last claim, is smooth near , so , which is below for small since ; also for small .
What is not claimed. Theorem 2 gives decrease, not convergence to the true model. is not convex in : if the predicted arrival differs from the observed one by more than about half a period, the descent moves toward a wrong local minimum (cycle skipping). The test with a constant true velocity of 2000 m/s shows such a minimum near 1625 m/s. Starting from a good model, or inverting the low frequencies first, are heuristics that reduce this risk, not theorems. The 30 halvings may also end before the Armijo condition holds, and then the loop stops early.
Complexity
- Real-ram. One gradient costs one forward and one backward simulation, each, per shot. With shots and iterations and a bounded number of line-search runs, the total is .
- Against finite differences. A gradient by finite differences needs one simulation per model parameter, simulations per shot, which is out of reach for to unknowns. The adjoint state needs two.
- Memory. Line L1 stores the forward field, ; checkpointing or boundary storage reduces this, as in reverse-time migration.
Properties
- High resolution. The gradient uses the whole waveform, so FWI can resolve features of about half a wavelength, much finer than traveltime tomography (a common estimate, not a theorem).
- Local. The misfit has many local minima. Gradient methods converge to the minimum of the basin that holds the starting model.
- Low frequencies first. The basin is wider at low frequencies, because the period is longer.
- Exact gradient of the discrete problem. Differentiating the discrete scheme, as here, gives a gradient that passes the finite-difference check to rounding; differentiating the continuous equation first and then discretizing does not.
- Shots are independent. The gradient is a sum over shots, so shots run in parallel.
Variants and improvements
- Quasi-Newton and Gauss-Newton steps. L-BFGS uses past gradients to approximate the Hessian, and the Gauss-Newton algorithm solves a linearized problem at each step, often with CG.
- Frequency domain. Pratt (1999) solved the Helmholtz equation for a few frequencies and inverted them from low to high.
- Multiscale inversion. Bunks et al. (1995) inverted low-pass filtered data first and added higher frequencies as the model improved, which widens the basin (a heuristic).
- Other misfits. Misfits based on cross-correlation traveltimes, envelopes, or optimal transport (Engquist and Froese 2014) are more convex with respect to time shifts (a heuristic).
- Extended models. Allow a model that depends on the shot or on a time lag, and penalize the extension, so that the data can be fitted far from the true model.
- Elastic and anisotropic FWI. Invert for several parameters with the elastic or anisotropic wave equation.
When to use it
Use FWI when a good starting model is available, for example from traveltime tomography, and the data have low frequencies and long offsets, so that diving waves and refractions sample the deep model. It gives the highest-resolution velocity models in exploration and in global seismology. Without low frequencies or a good start, use tomography first, or a cycle-skipping-resistant misfit.
Pitfalls
- A poor starting model. Starting with arrivals more than half a period off makes the inversion converge to a false model with a small misfit. Check the predicted and recorded first arrivals before line L1.
- Inconsistent adjoints. Using the continuous adjoint equation with a different discretization in line L4 gives a gradient that is only approximate, and the line search fails near convergence. Check the gradient against finite differences, as in the test.
- No positivity. A gradient step can make negative, and the next simulation fails. Reject such trial steps in the line search.
- A CFL violation during the line search. A trial model with a higher velocity can break the CFL condition for the fixed . Check for every trial model.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/full-waveform-inversion/. The authors are listed in prov/H0DMN3.jsonl.
"""Full waveform inversion (FWI) of 1D acoustic data with the adjoint-state gradient.
Conventions (the imaging and inverse problems pages):
- The 1D constant density acoustic wave equation m u_tt - u_zz = f with the
model m = 1 / v^2 per grid cell (s^2/m^2) and u = 0 for t <= 0.
- The scheme, for n = 0 .. N - 1, with u^0 = u^{-1} = 0:
u^{n+1} = 2 u^n - u^{n-1} + (dt^2 / m) (L u^n + f^n),
L u_i = (u_{i-1} - 2 u_i + u_{i+1}) / h^2 and u = 0 outside the grid
(Dirichlet ends). It is stable for v dt / h <= 1 (CFL condition in 1D).
- The data are u^n at the receiver cells for n = 0 .. N. The misfit is
J(m) = (1/2) sum_n sum_r (u^n_r - d^n_r)^2.
- The gradient comes from the adjoint state of the discrete scheme:
lam^k = 2 lam^{k+1} - lam^{k+2} + (dt^2 / m) L lam^{k+1} + (1 / m) R^T res^k,
for k = N .. 1 with lam^{N+1} = lam^{N+2} = 0, and
dJ/dm_i = - sum_{n=0}^{N-1} lam^{n+1}_i (u^{n+1} - 2 u^n + u^{n-1})_i.
This is the exact gradient of the discrete misfit (no discretization gap).
- The FWI loop is gradient descent with a backtracking (Armijo) line search.
Cost per iteration: one forward and one adjoint propagation, O(N n) each for
n cells and N steps, plus a few forward runs in the line search; the forward
field is stored, O(N n) memory.
"""
import math
def second_diff(u, h):
"""L u with u = 0 outside the grid."""
n = len(u)
c = 1.0 / (h * h)
return [c * ((u[i - 1] if i > 0 else 0.0) - 2.0 * u[i] + (u[i + 1] if i < n - 1 else 0.0)) for i in range(n)]
def forward(m, src_cell, wavelet, recs, dt, h):
"""Run the scheme for len(wavelet) steps; the source adds wavelet[n] / h at src_cell.
Returns (fields, data): fields[n] = u^n for n = 0 .. N, data[n][r] = u^n at recs[r].
"""
n = len(m)
prev, cur = [0.0] * n, [0.0] * n
fields = [cur]
for k in range(len(wavelet)):
lap = second_diff(cur, h)
lap[src_cell] += wavelet[k] / h
nxt = [2.0 * cur[i] - prev[i] + dt * dt * lap[i] / m[i] for i in range(n)]
fields.append(nxt)
prev, cur = cur, nxt
return fields, [[u[c] for c in recs] for u in fields]
def misfit(m, src_cell, wavelet, recs, dobs, dt, h):
"""J(m) = (1/2) sum over times and receivers of the squared data residual."""
_, d = forward(m, src_cell, wavelet, recs, dt, h)
return 0.5 * sum((a - b) ** 2 for ra, rb in zip(d, dobs) for a, b in zip(ra, rb))
def gradient(m, src_cell, wavelet, recs, dobs, dt, h):
"""The misfit J(m) and its exact gradient by the adjoint-state method."""
n = len(m)
fields, d = forward(m, src_cell, wavelet, recs, dt, h) # @line L1
res = [[a - b for a, b in zip(ra, rb)] for ra, rb in zip(d, dobs)] # @line L2
j = 0.5 * sum(x * x for row in res for x in row)
nsteps = len(wavelet)
lam1, lam2 = [0.0] * n, [0.0] * n # @line L3
g = [0.0] * n
zero = [0.0] * n
for k in range(nsteps, 0, -1): # @line L4
lap = second_diff(lam1, h)
lam = [2.0 * lam1[i] - lam2[i] + dt * dt * lap[i] / m[i] for i in range(n)]
for r, c in enumerate(recs):
lam[c] += res[k][r] / m[c] # @line L5
u_next = fields[k]
u_cur = fields[k - 1]
u_prev = fields[k - 2] if k >= 2 else zero
for i in range(n):
g[i] -= lam[i] * (u_next[i] - 2.0 * u_cur[i] + u_prev[i]) # @line L6
lam1, lam2 = lam, lam1
return j, g # @line L7
def full_waveform_inversion(m0, src_cell, wavelet, recs, dobs, dt, h, iters, max_rel_step=0.05):
"""Gradient descent with backtracking on J(m), started at m0.
The first trial step changes m by max_rel_step times max(m) at the cell of
the largest gradient entry; it is halved until the Armijo condition
J(m - a g) <= J(m) - 1e-4 a ||g||^2 holds (at most 30 halvings).
Returns the final model and the list of misfits.
"""
m = list(m0)
history = []
for _ in range(iters):
j, g = gradient(m, src_cell, wavelet, recs, dobs, dt, h)
history.append(j)
gmax = max(abs(x) for x in g)
gg = sum(x * x for x in g)
if gmax == 0.0:
break
a = max_rel_step * max(m) / gmax
for _ in range(30):
trial = [mi - a * gi for mi, gi in zip(m, g)]
if min(trial) > 0.0 and misfit(trial, src_cell, wavelet, recs, dobs, dt, h) <= j - 1e-4 * a * gg:
m = trial
break
a *= 0.5
else:
break
history.append(misfit(m, src_cell, wavelet, recs, dobs, dt, h))
return m, history
def ricker(t, f0):
"""The Ricker wavelet (1 - 2 a) exp(-a) with a = (pi f0 t)^2, peak frequency f0."""
a = (math.pi * f0 * t) ** 2
return (1.0 - 2.0 * a) * math.exp(-a)
test_full_waveform_inversion.py 73 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/full-waveform-inversion/. The authors are listed in prov/H0DMN3.jsonl.
import math
import unittest
from full_waveform_inversion import forward, full_waveform_inversion, gradient, misfit, ricker
N_CELLS, H, DT, STEPS, F0 = 60, 10.0, 0.002, 300, 15.0 # v dt / h <= 0.5
SRC = 2
WAVELET = [ricker(k * DT - 1.2 / F0, F0) for k in range(STEPS)]
def v_true(i):
base = 2000.0 if i < 25 else 2400.0
return base + 300.0 * math.exp(-(((i - 40) / 4.0) ** 2))
M_TRUE = [1.0 / v_true(i) ** 2 for i in range(N_CELLS)]
def observed(recs):
return forward(M_TRUE, SRC, WAVELET, recs, DT, H)[1]
class TestFullWaveformInversion(unittest.TestCase):
def test_gradient_matches_finite_differences(self):
recs = [2, 57]
dobs = observed(recs)
m0 = [1.0 / 2200.0 ** 2] * N_CELLS
_, g = gradient(m0, SRC, WAVELET, recs, dobs, DT, H)
for c in (10, 30, 45):
step = 1e-3 * m0[c]
mp, mm = list(m0), list(m0)
mp[c] += step
mm[c] -= step
fd = (misfit(mp, SRC, WAVELET, recs, dobs, DT, H) - misfit(mm, SRC, WAVELET, recs, dobs, DT, H)) / (2.0 * step)
self.assertLess(abs(fd - g[c]), 1e-5 * abs(g[c]))
def test_misfit_decreases(self):
recs = [2, 57]
dobs = observed(recs)
m0 = [1.0 / 2200.0 ** 2] * N_CELLS
_, hist = full_waveform_inversion(m0, SRC, WAVELET, recs, dobs, DT, H, 10)
for a, b in zip(hist, hist[1:]):
self.assertLessEqual(b, a)
self.assertLess(hist[-1], 0.05 * hist[0])
def test_zero_residual_gives_zero_gradient(self):
recs = [2, 57]
dobs = observed(recs)
j, g = gradient(M_TRUE, SRC, WAVELET, recs, dobs, DT, H)
self.assertEqual(j, 0.0)
self.assertEqual(max(abs(x) for x in g), 0.0)
def test_cycle_skipping_local_minimum(self):
# A constant true velocity of 2000 m/s, constant trial velocities and
# one transmission receiver: the misfit has a local minimum near
# 1625 m/s, where the predicted pulse is about one period late.
recs = [57]
dobs = forward([1.0 / 2000.0 ** 2] * N_CELLS, SRC, WAVELET, recs, DT, H)[1]
def j_of(v):
return misfit([1.0 / v ** 2] * N_CELLS, SRC, WAVELET, recs, dobs, DT, H)
a, b, c = j_of(1600.0), j_of(1625.0), j_of(1650.0)
self.assertLess(b, a)
self.assertLess(b, c)
self.assertGreater(j_of(1800.0), b) # a barrier between it and the true model
self.assertEqual(j_of(2000.0), 0.0)
if __name__ == "__main__":
unittest.main()
History
Lailly (1983) and Tarantola (1984) posed the inversion of seismic waveforms as least-squares fitting and showed that the gradient is a migration of the residuals, using the adjoint-state method that Chavent had introduced for distributed parameter systems. Early tests on reflection data were limited by local minima and computing power. Pratt and coworkers in the 1990s developed frequency-domain inversion, and Bunks et al. (1995) proposed the multiscale strategy. With long-offset data, low frequencies and parallel computers, FWI became a standard tool for velocity model building in the 2000s and 2010s; Virieux and Operto (2009) reviewed it.
References
- Albert Tarantola, Inversion of seismic reflection data in the acoustic approximation, Geophysics 49(8), 1984, 1259 to 1266, the least-squares waveform misfit and its gradient by back-propagation of the residuals
- Patrick Lailly, The seismic inverse problem as a sequence of before stack migrations, in Conference on Inverse Scattering: Theory and Application, SIAM, 1983, the gradient of the waveform misfit as a prestack migration of the residuals
- R. Gerhard Pratt, Seismic waveform inversion in the frequency domain, Part 1, Theory and verification in a physical scale model, Geophysics 64(3), 1999, 888 to 901, waveform inversion one frequency at a time with the frequency-domain wave equation
- Carey Bunks, Fatimetou M. Saleck, S. Zaleski and Guy Chavent, Multiscale seismic waveform inversion, Geophysics 60(5), 1995, 1457 to 1473, inversion from low to high frequencies to avoid local minima
- Jean Virieux and Stephane Operto, An overview of full-waveform inversion in exploration geophysics, Geophysics 74(6), 2009, WCC1 to WCC26, the review of the method, its gradient, its local minima and its practice
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag H0DMN3 Edit this page History Report an error Markdown