Skip to content

L2 (least-squares) misfit

Definition

For canonical-layout tensors \(d_{\mathrm{syn}}, d_{\mathrm{obs}} \in \mathbb{R}^{n_s\times n_t\times n_r\times n_c}\),

\[ \mathcal{J}_{L_2}(m) \;=\; \tfrac{1}{2}\; \sum_{s,t,r,c}\bigl(d_{\mathrm{syn}}[s,t,r,c] - d_{\mathrm{obs}}[s,t,r,c]\bigr)^{2}. \]

The leading \(\tfrac{1}{2}\) is conventional in the FWI literature so that the gradient with respect to the synthetic data is exactly the residual \(r = d_{\mathrm{syn}} - d_{\mathrm{obs}}\); set half=False to drop it (then the elementwise loss matches torch.nn.functional.mse_loss up to the reduction).

When to use

  • Default, well-understood, convex misfit. Works for high-frequency / good initial models.
  • Sensitive to outliers, traveltime shifts and cycle skipping — prefer L1 / Huber / OT-type misfits when those issues dominate.

API

from sweep_loss import L2Loss, l2_loss

loss_fn = L2Loss(reduction="mean", half=True)
loss = loss_fn(syn, obs)
# or functional:
loss = l2_loss(syn, obs, reduction="mean", half=True)

Tests

tests/test_l2.py checks:

  • identity property L(d,d) = 0,
  • numerical agreement with F.mse_loss (up to the 1/2 factor),
  • analytic gradient dJ/dsyn = syn - obs for half=True, reduction='sum',
  • shape promotion for 1D/2D/3D inputs,
  • mask handling,
  • module == functional alias.

References

  • Lailly, P. (1983). The seismic inverse problem as a sequence of before-stack migrations. In: Conference on Inverse Scattering: Theory and Application, SIAM, Philadelphia, 206-220. (no DOI)
  • Tarantola, A. (1984). Inversion of seismic reflection data in the acoustic approximation. Geophysics 49 (8), 1259-1266. doi:10.1190/1.1441754
  • Virieux, J. & Operto, S. (2009). An overview of full-waveform inversion in exploration geophysics. Geophysics 74 (6), WCC1-WCC26. doi:10.1190/1.3238367