WISER refinement objectives: constrained form (eq. 1), weak form (eq. 2) and Algorithm 1 losses
DefinitionArxiv2405_10327_BasicObjects of Section 3 (physics-based refinements), eq. (1), eq. (2) and Algorithm 1 of Yin, Orozco and Herrmann (2024).
- Spaces. Velocity models and latent codes are vectors of , seismic data are vectors of , and the weights of the refinement network are vectors , all with the Euclidean norm .
- Given maps. is the forward operator, the observed data, and the noise standard deviation. is the inverse of the trained conditional normalizing flow at the common-image gathers . is the refinement network with weights , and are the latent draws of Algorithm 1.
- Terms. The data misfit is . The latent terms are , where is the Jacobian of at . The corrected velocity model is .
- Constrained objective (eq. 1), sample form. . This is the integrand of eq. (1) averaged over the draws instead of integrated against .
- Weak objective (eq. 2). For , .
- Weak objective at . takes values in . It equals the -independent terms of eq. (2) when for every , and otherwise. The penalty is at and elsewhere, which is the pointwise limit of as .
- Algorithm 1 losses. The inner-loop loss (line 29) is . The outer-loop step (line 25) is the gradient of at .
Formalization Note The forward operator, the inverse flow and the refinement networks are arbitrary given maps, because the paper's statements about eqs. (1) and (2) do not depend on their form. The paper writes without an argument; here the Jacobian is taken at the latent draw (at in eq. (1)). Where the paper's term would be ; the formal term is then . It enters both sides of every statement identically. The weak objective is used for only, and its value is the separate extended-real objective of item 6.
import Mathlib
/-!
Yin, Orozco and Herrmann, *WISER: multimodal variational inference for full-waveform inversion
without dimensionality reduction*, arXiv:2405.10327v2 (2024): the objects of Section 3
(physics-based refinements), eq. (1), eq. (2) and Algorithm 1, lines 22-32.
Velocity models, latent codes and seismic data are vectors of Euclidean spaces; the forward
operator `F`, the inverse of the trained conditional normalizing flow at a fixed conditioning
`fInv (·) c` and the refinement networks `h φ` (weights `φ ∈ ℝ^p`) are given maps.
-/
noncomputable section
namespace Arxiv2405_10327
/-- Euclidean space `ℝ^n` with the `ℓ₂` norm, used for velocity models, latent codes, seismic
data and network weights (Section 1 and Section 3). -/
abbrev Vec (n : ℕ) : Type := EuclideanSpace ℝ (Fin n)
/-- `log |det J_h(z)|`, the log-absolute-determinant of the Jacobian of a map `h : ℝ^d → ℝ^d` at
`z` (the term `log |det J_{h_φ}|` of eq. (1), eq. (2) and Algorithm 1 line 29, Section 3). -/
def logAbsDetJac {d : ℕ} (h : Vec d → Vec d) (z : Vec d) : ℝ :=
Real.log |(fderiv ℝ h z).det|
/-- The data-misfit term `‖F(x) - y_obs‖₂² / (2σ²)` of eq. (2) and Algorithm 1 line 25
(Section 3). -/
def dataMisfit {d m : ℕ} (σ : ℝ) (F : Vec d → Vec m) (yobs : Vec m) (x : Vec d) : ℝ :=
‖F x - yobs‖ ^ 2 / (2 * σ ^ 2)
/-- The latent terms `½‖h_φ(z)‖₂² - log |det J_{h_φ}(z)|` of eq. (1), eq. (2) and Algorithm 1
line 29 (Section 3). -/
def latentTerm {d : ℕ} (h : Vec d → Vec d) (z : Vec d) : ℝ :=
‖h z‖ ^ 2 / 2 - logAbsDetJac h z
/-- The corrected velocity model `f_{θ*}^{-1}(h_φ(z); ȳ_obs)`: the refinement network `h_φ`
followed by the inverse `fInv` of the trained CNF conditioned on the CIGs `ȳ_obs`
(Algorithm 1 lines 19 and 34, Section 3). -/
def corrected {d : ℕ} {C : Type*} (fInv : Vec d → C → Vec d) (ybar : C)
(h : Vec d → Vec d) (z : Vec d) : Vec d :=
fInv (h z) ybar
/-- The integrand of eq. (1) (Section 3, p. 4):
`‖F ∘ f_{θ*}^{-1}(h_φ(z); ȳ_obs) - y_obs‖₂²/(2σ²) + ½‖h_φ(z)‖₂² - log |det J_{h_φ}(z)|`. -/
def strongIntegrand {d m : ℕ} {C : Type*} (σ : ℝ) (F : Vec d → Vec m) (yobs : Vec m)
(fInv : Vec d → C → Vec d) (ybar : C) (h : Vec d → Vec d) (z : Vec d) : ℝ :=
dataMisfit σ F yobs (corrected fInv ybar h z) + latentTerm h z
/-- The constrained objective of eq. (1) evaluated with the latent draws `z_1, …, z_M` of
Algorithm 1 line 18 in place of the expectation over `z ∼ N(0, I)`:
`φ ↦ (1/M) ∑ᵢ [integrand of eq. (1) at zᵢ]` (Section 3, p. 4). -/
def strongSampleObjective {d m p M : ℕ} {C : Type*} (σ : ℝ) (F : Vec d → Vec m) (yobs : Vec m)
(fInv : Vec d → C → Vec d) (ybar : C) (h : Vec p → Vec d → Vec d) (z : Fin M → Vec d)
(φ : Vec p) : ℝ :=
(1 / (M : ℝ)) * ∑ i, strongIntegrand σ F yobs fInv ybar (h φ) (z i)
/-- The weak (penalty) objective of eq. (2) (Section 3, p. 4), for `γ > 0`:
`(1/M) ∑ᵢ [‖F(xᵢ) - y_obs‖₂²/(2σ²) + ‖xᵢ - f_{θ*}^{-1}(h_φ(zᵢ); ȳ_obs)‖₂²/(2γ²)
+ ½‖h_φ(zᵢ)‖₂² - log |det J_{h_φ}(zᵢ)|]`. (At `γ = 0` the formula is not defined by the paper;
see `weakObjectiveHard`.) -/
def weakObjective {d m p M : ℕ} {C : Type*} (σ γ : ℝ) (F : Vec d → Vec m) (yobs : Vec m)
(fInv : Vec d → C → Vec d) (ybar : C) (h : Vec p → Vec d → Vec d) (z : Fin M → Vec d)
(x : Fin M → Vec d) (φ : Vec p) : ℝ :=
(1 / (M : ℝ)) * ∑ i, (dataMisfit σ F yobs (x i)
+ ‖x i - corrected fInv ybar (h φ) (z i)‖ ^ 2 / (2 * γ ^ 2)
+ latentTerm (h φ) (z i))
/-- The hard penalty that replaces `‖v‖₂²/(2γ²)` at `γ = 0` (Section 3, p. 4, "Setting `γ` to
`0`"): `0` if `v = 0` and `+∞` otherwise, i.e. the pointwise limit of `‖v‖₂²/(2γ²)` as
`γ → 0⁺` in the extended reals. -/
def hardPenalty {d : ℕ} (v : Vec d) : EReal :=
if v = 0 then 0 else ⊤
/-- The weak objective of eq. (2) with `γ` set to `0` (Section 3, p. 4), with values in the
extended reals: the `γ`-independent terms of eq. (2) plus the hard penalty
`∑ᵢ hardPenalty (xᵢ - f_{θ*}^{-1}(h_φ(zᵢ); ȳ_obs))`. -/
def weakObjectiveHard {d m p M : ℕ} {C : Type*} (σ : ℝ) (F : Vec d → Vec m) (yobs : Vec m)
(fInv : Vec d → C → Vec d) (ybar : C) (h : Vec p → Vec d → Vec d) (z : Fin M → Vec d)
(x : Fin M → Vec d) (φ : Vec p) : EReal :=
(((1 / (M : ℝ)) * ∑ i, (dataMisfit σ F yobs (x i) + latentTerm (h φ) (z i)) : ℝ) : EReal)
+ ∑ i, hardPenalty (x i - corrected fInv ybar (h φ) (z i))
/-- The inner-loop loss `𝓛(φ)` of Algorithm 1 line 29 (Algorithm 1 on p. 3; Section 3, p. 4):
`∑ᵢ [‖xᵢ - f_{θ*}^{-1}(h_φ(zᵢ); ȳ_obs)‖₂²/(2γ²) + ½‖h_φ(zᵢ)‖₂² - log |det J_{h_φ}(zᵢ)|]`,
for fixed velocity models `x₁, …, x_M`. It does not involve the forward operator. -/
def innerLoss {d p M : ℕ} {C : Type*} (γ : ℝ) (fInv : Vec d → C → Vec d) (ybar : C)
(h : Vec p → Vec d → Vec d) (z : Fin M → Vec d) (x : Fin M → Vec d) (φ : Vec p) : ℝ :=
∑ i, (‖x i - corrected fInv ybar (h φ) (z i)‖ ^ 2 / (2 * γ ^ 2) + latentTerm (h φ) (z i))
/-- The function whose gradient in `xᵢ` is the outer-loop step `gᵢ` of Algorithm 1 line 25
(Algorithm 1 on p. 3; Section 3, p. 4): `‖F(v) - y_obs‖₂²/(2σ²) + ‖v - f_{θ*}^{-1}(h_φ(zᵢ); ȳ_obs)‖₂²/(2γ²)`. -/
def outerLoss {d m : ℕ} {C : Type*} (σ γ : ℝ) (F : Vec d → Vec m) (yobs : Vec m)
(fInv : Vec d → C → Vec d) (ybar : C) (hφ : Vec d → Vec d) (zi : Vec d) (v : Vec d) : ℝ :=
dataMisfit σ F yobs v + ‖v - corrected fInv ybar hφ zi‖ ^ 2 / (2 * γ ^ 2)
end Arxiv2405_10327
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
Throughout, denotes the Euclidean space of real -tuples with the usual norm , for any (the case , the zero-dimensional space , is permitted everywhere). Dimensions are arbitrary natural numbers, is an arbitrary type of "conditioning" values, and all maps below are arbitrary functions. No continuity, differentiability, invertibility or neural-network structure is assumed for any of them unless stated. The bundle makes no claims; it only defines the following quantities.
Log-absolute-Jacobian-determinant. For a map and a point ,
where is the Fréchet derivative of at . The following conventions apply:
- If is not differentiable at , then is taken to be the zero map. Its determinant is when , and when .
- The logarithm satisfies .
So whenever is non-differentiable at , whenever the Jacobian is singular, and always when .
Data misfit. For , a map , a vector and ,
is any real number. Only enters, so negative behaves like . Division by zero yields , so for the misfit is identically .
Latent term. For and ,
with the conventions above for .
Corrected model. Given an arbitrary map , a value , a map and , the corrected model is
Despite the name, is not required to be the inverse of anything.
Strong integrand. With as above and ,
The misfit summand is when .
Strong sample objective. The ingredients are:
- a parametrized family , written ;
- an -tuple of points , which are arbitrary fixed points with no distributional assumption;
- a parameter .
The objective is
For , both (division by zero) and the empty sum equal , so the value is .
Weak objective. The ingredients are real numbers , the data above, and additionally an -tuple . The objective is
No positivity of is required. For , the second summand is by the division-by-zero convention; it does not become a hard constraint. Likewise, the first summand vanishes for , and the whole expression is for .
Hard penalty. For , the extended-real value
Hard weak objective. This takes values in the extended reals . With the same data as the weak objective, except that no is used,
The first part is a finite real number. The penalty sum is not divided by . The penalty sum is if for every , and otherwise. Hence:
- equals the real first part when all equalities hold;
- otherwise;
- for , the value is .
Inner loss. With , as above and ,
This is a plain sum with no factor. It involves neither , nor . The first summand is when , and when .
Outer loss. The ingredients are:
- real numbers , and the data ;
- a single map , not parametrized by weights;
- a single point .
The outer loss is the function of
The first term is when , and the second is when . No gradient is taken or asserted in this definition.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.