VelocityGAN: velocity maps, the generated law, the generator loss (8) and the regularized-inversion objective (9)
DefinitionArxiv1809_10262_BasicObjects of Sections III-B.1, III-C and III-D of Zhang and Lin, Data-driven Seismic Waveform Inversion: A Study on the Robustness and Generalization (arXiv:1809.10262v8).
- Velocity maps. A velocity map of width and height is an array of real pixel values , , . Its norm is and its squared norm is .
- Generated law. Seismic data take values in a measurable space with distribution . A generator (inversion operator) maps seismic data to velocity maps, and is the distribution of for , the image measure .
- Adversarial loss. For a discriminator (a real function on velocity maps), the adversarial loss of is .
- Generator loss, eq. (8). For a training pair with true map and predicted map ,
Over training pairs , the training objective is the mean . 5. Regularized-inversion objective, eq. (9).
Formalization Note Pixels are indexed from . The paper writes eq. (8) for a single velocity map. Averaging it over the training pairs is the reading under which eq. (9) is a rewriting of eq. (8): the paper trains on mini-batches of pairs (Section IV-A.2) but never writes the training objective explicitly. is the image of the seismic-data distribution under . Lean's integral is when is not integrable and the image measure is when is not measurable; the statement excludes both by hypothesis.
import Mathlib
/-!
Z. Zhang and Y. Lin, *Data-driven Seismic Waveform Inversion: A Study on the Robustness and
Generalization* (VelocityGAN), arXiv:1809.10262v8 (2018): the velocity maps of Section III-B.1,
the content losses and the WGAN-GP generator loss of Section III-C (eq. (8)), and the
regularized-inversion objective of Section III-D (eq. (9)).
-/
open MeasureTheory
noncomputable section
namespace Arxiv1809_10262
/-- Section III-B.1 and eq. (8): a velocity map of width `w` and height `h`, given by its pixel
values `v(i,j)`, `1 ≤ i ≤ w`, `1 ≤ j ≤ h` (indexed from `0` here). -/
abbrev VelocityMap (w h : ℕ) : Type := Fin w → Fin h → ℝ
/-- Eq. (9): the `L_1` norm `‖m‖_1 = ∑_{i,j} |m(i,j)|` of a velocity map. -/
def l1Norm {w h : ℕ} (m : VelocityMap w h) : ℝ := ∑ i, ∑ j, |m i j|
/-- Eq. (9): the squared `L_2` norm `‖m‖_2^2 = ∑_{i,j} m(i,j)^2` of a velocity map. -/
def sqL2Norm {w h : ℕ} (m : VelocityMap w h) : ℝ := ∑ i, ∑ j, m i j ^ 2
/-- Section III-C, after eq. (7): `ℙ_g`, the distribution of the velocity maps `g(d)` predicted by
the generator `g` when the seismic data `d` has distribution `μ`. -/
def generatedLaw {Dat : Type*} [MeasurableSpace Dat] {w h : ℕ} (μ : Measure Dat)
(g : Dat → VelocityMap w h) : Measure (VelocityMap w h) :=
μ.map g
/-- Section III-C, before eq. (8): the adversarial loss `-𝔼_{x̃ ∼ ℙ_g} D(x̃)` of the generator `g`
against the discriminator `D`. -/
def adversarialLoss {Dat : Type*} [MeasurableSpace Dat] {w h : ℕ} (μ : Measure Dat)
(D : VelocityMap w h → ℝ) (g : Dat → VelocityMap w h) : ℝ :=
-∫ x, D x ∂(generatedLaw μ g)
/-- Eq. (8): the generator loss
`L_g = -𝔼_{x̃∼ℙ_g} D(x̃) + λ₁/(w·h) ∑_{i,j} |ṽ(i,j) - v(i,j)| + λ₂/(w·h) ∑_{i,j} (ṽ(i,j) - v(i,j))^2`
for one training pair `(m, d)`, with true map `v = m` and predicted map `ṽ = g(d)`. -/
def generatorLoss {Dat : Type*} [MeasurableSpace Dat] {w h : ℕ} (lam1 lam2 : ℝ)
(μ : Measure Dat) (D : VelocityMap w h → ℝ) (m : VelocityMap w h) (d : Dat)
(g : Dat → VelocityMap w h) : ℝ :=
adversarialLoss μ D g + lam1 / ((w : ℝ) * h) * ∑ i, ∑ j, |g d i j - m i j| +
lam2 / ((w : ℝ) * h) * ∑ i, ∑ j, (g d i j - m i j) ^ 2
/-- Eq. (8) over the training set (Sections III-C and IV-A.2): the generator loss of eq. (8)
averaged over the `N` training pairs `(m_k, d_k)`, as a function of the generator `g`. -/
def meanGeneratorLoss {Dat : Type*} [MeasurableSpace Dat] {w h N : ℕ} (lam1 lam2 : ℝ)
(μ : Measure Dat) (D : VelocityMap w h → ℝ) (m : Fin N → VelocityMap w h) (d : Fin N → Dat)
(g : Dat → VelocityMap w h) : ℝ :=
(1 / (N : ℝ)) * ∑ k, generatorLoss lam1 lam2 μ D (m k) (d k) g
/-- Eq. (9): the regularized-inversion objective
`λ₁ ∑_{k=1}^N ‖m_k - g(d_k)‖_1 + λ₂ ∑_{k=1}^N ‖m_k - g(d_k)‖_2^2 - 𝔼_{x̃∼ℙ_g} D(x̃)`
of the inversion operator `g` on the `N` pairs `(m_k, d_k)` of velocity maps and seismic data. -/
def regularizedInversionObjective {Dat : Type*} [MeasurableSpace Dat] {w h N : ℕ}
(lam1 lam2 : ℝ) (μ : Measure Dat) (D : VelocityMap w h → ℝ) (m : Fin N → VelocityMap w h)
(d : Fin N → Dat) (g : Dat → VelocityMap w h) : ℝ :=
lam1 * ∑ k, l1Norm (m k - g (d k)) + lam2 * ∑ k, sqL2Norm (m k - g (d k)) +
adversarialLoss μ D g
end Arxiv1809_10262
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
Setting and the velocity-map type. Fix natural numbers (width) and (height). A velocity map of size is any real-valued array
No range restriction is imposed: entries may be negative or zero. and are allowed. In those cases the index set is empty and there is exactly one (empty) velocity map. Velocity maps are added and subtracted entrywise. They carry the product σ-algebra built from the Borel σ-algebra on . Throughout, denotes an arbitrary type (the "seismic data" space) equipped with an arbitrary σ-algebra. No topology, metric or other structure on is assumed.
norm. For a velocity map of size ,
This is when or (empty sum).
Squared norm. For a velocity map of size ,
This is when or .
Generated law . The inputs are:
- an arbitrary measure on , which need not be a probability measure and may be infinite or zero;
- an arbitrary function , the "generator".
The output is the pushforward measure
on velocity maps. Edge case: by the convention used, if is not almost-everywhere measurable with respect to , then is defined to be the zero measure. has the same total mass as (when is a.e. measurable), so it is a probability measure only if is.
Adversarial loss. The inputs are and as above, plus an arbitrary function from velocity maps to (the "discriminator"). No Lipschitz, continuity, measurability or boundedness condition is placed on . The output is the real number
This is a Bochner integral with these conventions:
- If is not integrable with respect to (including when it is not suitably measurable), the integral is defined to be , so the loss is .
- If is not a.e. measurable, and the loss is again .
It is an expectation only when is a probability measure.
Generator loss for one pair. The inputs are:
- arbitrary real numbers , with no sign restriction, so they may be negative or zero;
- , and as above;
- one velocity map (the "true map");
- one data point .
Write . The output is
Points to note:
- The adversarial term is the global quantity . It does not depend on the particular pair , and the data point is not tied to in any way.
- Division follows the convention . If or , the coefficients and are (and the sums are empty), so reduces to the adversarial term.
- There are no further terms. In particular, there is no gradient-penalty term involving .
Mean generator loss over a training set. The inputs are:
- as above;
- a natural number ;
- velocity maps ;
- data points .
The output is
with the one-pair generator loss above. Because each summand contains the same adversarial term, for this equals
If , then is taken to be and the whole quantity is , including the adversarial term.
Regularized-inversion objective. The inputs are the same as for the mean generator loss: arbitrary, , , , , and pairs . The output is
Here is the entrywise difference of velocity maps, and , are the unnormalized sums defined above. Points to note:
- The sums over and over pixels are not divided by or by .
- The adversarial term appears exactly once, with the same integral conventions as above: it is if is not -integrable or is not a.e. measurable.
- If , then .
- No constraints are placed on , , , or .
- This is only a definition of a real number. No minimization, optimality or other property is asserted.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.