Conditionally factorial exponential-family latent model, observed law and the relations , ,
DefinitionIdentifiableVAE_BasicObjects of Sections 3.1 and 4 of Khemakhem, Kingma, Monti and Hyvärinen (AISTATS 2020).
- Parameters. A parameter consists of a mixing function , base measures , sufficient statistics and natural parameters , for and . The paper writes .
- Prior (eq. 7). and . The prior law of given is Lebesgue measure on with this density.
- Observations (eqs. 5, 6). , where the noise is independent of . The conditional law is the convolution of the push-forward of the prior by with .
- Admissible parameters. Let be the support of . Then describes a model on if is measurable and injective, every is measurable and positive, every is measurable, and every factor of the prior is integrable, so that for every .
- Relations (Definition 2, eq. 13). Write . Then if there are an matrix and such that for every there is with and . This is for all . The relation requires invertible. The relation requires invertible and block-permutation: for some permutation , the rows of block vanish outside the columns of block . The almost-everywhere versions of ask the same for Lebesgue-almost every only.
- Identifiability (Definition 1). is identifiable up to a relation within a class if every with for all satisfies .
- Assumptions.
- (i): is Lebesgue-null, where is the characteristic function of the noise.
- (iii): each is differentiable almost everywhere, and no nonzero makes constant on a set of positive measure.
- (iv), eq. (14): there are distinct such that is invertible.
- (2.i): each is twice differentiable.
- (2.ii): has all first partial derivatives and all second cross derivatives , .
- (3.i): no is strictly increasing or strictly decreasing.
- (3.ii): all partial derivatives of exist and are continuous.
- Proof of Theorem 3: is a embedding with injective differential at every point. A function has isolated turning points if every has a punctured neighbourhood on each side of which is strictly monotonic.
Formalization Note The latent domain is , the default domain of Appendix A. Observations live in EuclideanSpace ℝ (Fin d) so that Mathlib's characteristic function applies. The base measures are part of the parameter because the proofs let differ from . Assumption (iii) is read as linear independence of together with the constant function, on subsets of the latent coordinate line. The almost-everywhere relations are what the proofs establish.
import Mathlib
/-!
Khemakhem, Kingma, Monti and Hyvärinen, *Variational Autoencoders and Nonlinear ICA: A Unifying
Framework*, AISTATS 2020, arXiv:1907.04809v4: the conditional generative model (5)-(7) of
Section 3.1, its observed conditional law, the assumptions of Theorems 1-3 and 6, identifiability
up to an equivalence relation (Definition 1) and the relations `∼`, `∼_A`, `∼_P` of Definition 2
(Section 4.1).
Latent vectors are `z : Fin n → ℝ` (the latent domain is `ℝⁿ`, the default domain of
Appendix A), observations live in `EuclideanSpace ℝ (Fin d)`, auxiliary variables are
`u : Fin m → ℝ`, and the vector of sufficient statistics is indexed by `Fin n × Fin k`.
-/
open MeasureTheory
noncomputable section
namespace IdentifiableVAE
/-- Section 3.1, eqs. (5)-(7), and Section 4 "Notations": the parameters of the conditional
generative model `p_θ(x, z | u) = p_f(x | z) p_{T,λ}(z | u)`: the mixing function
`f : ℝⁿ → ℝᵈ`, the base measures `Q_i`, the sufficient statistics `T_{i,j}` and the natural
parameters `λ_{i,j}(u)`. The paper writes `θ = (f, T, λ)`; the base measures `Q_i` of eq. (7)
are carried with the parameter because the proofs (eq. (29)) allow `Q̃_i ≠ Q_i`. -/
structure Param (n d m k : ℕ) where
/-- The mixing function `f` of eq. (6). -/
f : (Fin n → ℝ) → EuclideanSpace ℝ (Fin d)
/-- The base measures `Q_i` of eq. (7). -/
Q : Fin n → ℝ → ℝ
/-- The sufficient statistics `T_{i,j}` of eq. (7). -/
T : Fin n → Fin k → ℝ → ℝ
/-- The natural parameters `λ_{i,j}(u)` of eq. (7). -/
lam : (Fin m → ℝ) → Fin n → Fin k → ℝ
variable {n d m k : ℕ}
/-- Eq. (7): the exponent `∑_j T_{i,j}(t) λ_{i,j}(u)` of the `i`-th latent factor. -/
def expoTerm (θ : Param n d m k) (u : Fin m → ℝ) (i : Fin n) (t : ℝ) : ℝ :=
∑ j, θ.T i j t * θ.lam u i j
/-- Eq. (7): the unnormalised `i`-th factor `Q_i(t) exp(∑_j T_{i,j}(t) λ_{i,j}(u))`. -/
def unnormFactor (θ : Param n d m k) (u : Fin m → ℝ) (i : Fin n) (t : ℝ) : ℝ :=
θ.Q i t * Real.exp (expoTerm θ u i t)
/-- Eq. (7): the normalising constant `Z_i(u) = ∫ Q_i(t) exp(∑_j T_{i,j}(t) λ_{i,j}(u)) dt`. -/
def normConst (θ : Param n d m k) (u : Fin m → ℝ) (i : Fin n) : ℝ :=
∫ t, unnormFactor θ u i t
/-- Eq. (7): the conditionally factorial exponential-family prior density
`p_{T,λ}(z | u) = ∏_i Q_i(z_i) / Z_i(u) · exp(∑_j T_{i,j}(z_i) λ_{i,j}(u))`. -/
def priorDensity (θ : Param n d m k) (u : Fin m → ℝ) (z : Fin n → ℝ) : ℝ :=
∏ i, unnormFactor θ u i (z i) / normConst θ u i
/-- Eq. (7): the prior law of `z` given `u`, i.e. Lebesgue measure on `ℝⁿ` with density
`p_{T,λ}(z | u)`. -/
def priorMeasure (θ : Param n d m k) (u : Fin m → ℝ) : Measure (Fin n → ℝ) :=
volume.withDensity fun z => ENNReal.ofReal (priorDensity θ u z)
/-- Eqs. (5), (6), (21) and (24): the conditional law `p_θ(x | u)` of the observation
`x = f(z) + ε`, with `z ∼ p_{T,λ}(· | u)` and the noise `ε ∼ P_ε` independent of `z`: the
convolution of the push-forward of the prior by `f` with the noise law. -/
def obsLaw (Pε : Measure (EuclideanSpace ℝ (Fin d))) (θ : Param n d m k) (u : Fin m → ℝ) :
Measure (EuclideanSpace ℝ (Fin d)) :=
Measure.conv ((priorMeasure θ u).map θ.f) Pε
/-- Section 3.1 and Section 4 "Notations": `θ` describes a model (5)-(7) when the auxiliary
variable ranges over its support `U`: `f` is measurable and injective, each `Q_i` is measurable
and positive (the proofs take `log Q_i` in eq. (29)), each `T_{i,j}` is measurable, and every
factor of eq. (7) is integrable, so that `Z_i(u)` is finite for every `u ∈ U`. -/
structure IsParam (θ : Param n d m k) (U : Set (Fin m → ℝ)) : Prop where
measurable_f : Measurable θ.f
injective_f : Function.Injective θ.f
measurable_Q : ∀ i, Measurable (θ.Q i)
pos_Q : ∀ i t, 0 < θ.Q i t
measurable_T : ∀ i j, Measurable (θ.T i j)
integrable_factor : ∀ u ∈ U, ∀ i, Integrable (unnormFactor θ u i)
/-- Section 4 "Notations": the vector of sufficient statistics
`T(z) = (T_{1,1}(z_1), …, T_{n,k}(z_n)) ∈ ℝ^{nk}`, indexed by `Fin n × Fin k`. -/
def suffStat (θ : Param n d m k) (z : Fin n → ℝ) : Fin n × Fin k → ℝ :=
fun p => θ.T p.1 p.2 (z p.1)
/-- Definition 2, eq. (13): `T(f⁻¹(x)) = A T̃(f̃⁻¹(x)) + c` for every `x ∈ X = f(ℝⁿ)`,
written over `z = f⁻¹(x)`: for every latent `z` there is `z̃ = f̃⁻¹(f(z))` with
`T(z) = A T̃(z̃) + c`. -/
def LinRel (θ θ' : Param n d m k) (A : Matrix (Fin n × Fin k) (Fin n × Fin k) ℝ)
(c : Fin n × Fin k → ℝ) : Prop :=
∀ z, ∃ z', θ'.f z' = θ.f z ∧ suffStat θ z = A.mulVec (suffStat θ' z') + c
/-- The almost-everywhere form of eq. (13), which is what the proofs of Theorems 1-3 and 6 in
Appendices B and E establish: for Lebesgue-almost every latent `z` there is `z̃ = f̃⁻¹(f(z))`
with `T(z) = A T̃(z̃) + c`. -/
def LinRelAE (θ θ' : Param n d m k) (A : Matrix (Fin n × Fin k) (Fin n × Fin k) ℝ)
(c : Fin n × Fin k → ℝ) : Prop :=
∀ᵐ z ∂(volume : Measure (Fin n → ℝ)), ∃ z', θ'.f z' = θ.f z ∧
suffStat θ z = A.mulVec (suffStat θ' z') + c
/-- Definition 2, footnote 4: `A` is a block permutation matrix, i.e. there is a permutation
`σ` of `{1, …, n}` such that the block of rows of `T_i` only has nonzero entries in the block of
columns of `T̃_{σ(i)}`. -/
def IsBlockPerm (A : Matrix (Fin n × Fin k) (Fin n × Fin k) ℝ) : Prop :=
∃ σ : Equiv.Perm (Fin n), ∀ i l a b, a ≠ σ i → A (i, l) (a, b) = 0
/-- Definition 2, eq. (13): the relation `∼` (an arbitrary `nk × nk` matrix `A`). -/
def Sim (θ θ' : Param n d m k) : Prop :=
∃ A c, LinRel θ θ' A c
/-- Definition 2: the relation `∼_A` (eq. (13) with `A` invertible). -/
def SimA (θ θ' : Param n d m k) : Prop :=
∃ A c, IsUnit A ∧ LinRel θ θ' A c
/-- Definition 2: the relation `∼_P` (eq. (13) with `A` an invertible block permutation
matrix). -/
def SimP (θ θ' : Param n d m k) : Prop :=
∃ A c, IsUnit A ∧ IsBlockPerm A ∧ LinRel θ θ' A c
/-- The relation `∼` of Definition 2 in the almost-everywhere form established by the proofs. -/
def SimAE (θ θ' : Param n d m k) : Prop :=
∃ A c, LinRelAE θ θ' A c
/-- The relation `∼_A` of Definition 2 in the almost-everywhere form established by the
proofs. -/
def SimAAE (θ θ' : Param n d m k) : Prop :=
∃ A c, IsUnit A ∧ LinRelAE θ θ' A c
/-- The relation `∼_P` of Definition 2 in the almost-everywhere form established by the
proofs. -/
def SimPAE (θ θ' : Param n d m k) : Prop :=
∃ A c, IsUnit A ∧ IsBlockPerm A ∧ LinRelAE θ θ' A c
/-- Definition 1, eq. (12), for one parameter: `θ` is identifiable up to `rel` within the
parameter class `Θ` if every `θ̃ ∈ Θ` with the same observed conditional laws
`p_θ(x | u) = p_θ̃(x | u)` for all `u ∈ U` is related to `θ`. -/
def IdentifiableUpTo (Pε : Measure (EuclideanSpace ℝ (Fin d))) (U : Set (Fin m → ℝ))
(Θ : Set (Param n d m k)) (rel : Param n d m k → Param n d m k → Prop)
(θ : Param n d m k) : Prop :=
∀ θ' ∈ Θ, (∀ u ∈ U, obsLaw Pε θ u = obsLaw Pε θ' u) → rel θ θ'
/-- Theorem 1, assumption (i): the zero set `{ω | φ_ε(ω) = 0}` of the characteristic function
of the noise has Lebesgue measure zero. -/
def CharFunZeroNull (Pε : Measure (EuclideanSpace ℝ (Fin d))) : Prop :=
volume {ω : EuclideanSpace ℝ (Fin d) | charFun Pε ω = 0} = 0
/-- Theorem 1, assumption (iii): every `T_{i,j}` is differentiable almost everywhere, and for
every `i` the statistics `T_{i,1}, …, T_{i,k}` are linearly independent, together with the
constants, on every subset of `ℝ` of positive measure: no nonzero `α` makes
`∑_j α_j T_{i,j}` constant on such a set. -/
def SuffStatRegular (θ : Param n d m k) : Prop :=
(∀ i j, ∀ᵐ t ∂(volume : Measure ℝ), DifferentiableAt ℝ (θ.T i j) t) ∧
∀ i (S : Set ℝ), 0 < volume S → ∀ (α : Fin k → ℝ) (α₀ : ℝ),
(∀ t ∈ S, ∑ j, α j * θ.T i j t = α₀) → α = 0
/-- Theorem 1, assumption (iv), eq. (14): there are `nk + 1` distinct points
`u⁰, …, u^{nk}` of `U` such that the `nk × nk` matrix
`L = (λ(u¹) - λ(u⁰), …, λ(u^{nk}) - λ(u⁰))` is invertible. The points `u¹, …, u^{nk}` are
indexed by `Fin n × Fin k`, and so are the columns of `L`. -/
def HasInvertibleL (θ : Param n d m k) (U : Set (Fin m → ℝ)) : Prop :=
∃ (u₀ : Fin m → ℝ) (u : Fin n × Fin k → Fin m → ℝ), u₀ ∈ U ∧ (∀ p, u p ∈ U) ∧
Function.Injective u ∧ (∀ p, u p ≠ u₀) ∧
(Matrix.of fun r p : Fin n × Fin k => θ.lam (u p) r.1 r.2 - θ.lam u₀ r.1 r.2).det ≠ 0
/-- Theorem 2, assumption (2.i): every sufficient statistic `T_{i,j}` is twice
differentiable. -/
def TwiceDiffStats (θ : Param n d m k) : Prop :=
∀ i j, Differentiable ℝ (θ.T i j) ∧ Differentiable ℝ (deriv (θ.T i j))
/-- Theorem 2, assumption (2.ii): the mixing function `f` has all first partial derivatives
and all second-order cross derivatives `∂²f / ∂z_s ∂z_t`, `s ≠ t`, at every point. -/
def HasSecondCrossPartials (f : (Fin n → ℝ) → EuclideanSpace ℝ (Fin d)) : Prop :=
(∀ t z, LineDifferentiableAt ℝ f z (Pi.single t 1)) ∧
∀ s t z, s ≠ t →
LineDifferentiableAt ℝ (fun w => lineDeriv ℝ f w (Pi.single t 1)) z (Pi.single s 1)
/-- Theorem 3, assumption (3.ii): all partial derivatives `∂f / ∂z_t` of the mixing function
exist everywhere and are continuous. -/
def HasContinuousPartials (f : (Fin n → ℝ) → EuclideanSpace ℝ (Fin d)) : Prop :=
∀ t, (∀ z, LineDifferentiableAt ℝ f z (Pi.single t 1)) ∧
Continuous fun z => lineDeriv ℝ f z (Pi.single t 1)
/-- Theorem 3, assumption (3.i) with footnote 5: no sufficient statistic `T_{i,1}` is monotonic,
where monotonic means strictly increasing or strictly decreasing. -/
def NotMonotoneStats (θ : Param n d m 1) : Prop :=
∀ i, ¬ StrictMono (θ.T i 0) ∧ ¬ StrictAnti (θ.T i 0)
/-- Proof of Theorem 3 (Appendix B.4: "by hypothesis, `v_i` is of class `C¹`, and its Jacobian
is non-zero everywhere"): `f` is a `C¹` embedding with injective differential. For two such
mixing functions with the same image, `f̃⁻¹ ∘ f` is a `C¹` diffeomorphism of `ℝⁿ`. -/
def IsC1Embedding (f : (Fin n → ℝ) → EuclideanSpace ℝ (Fin d)) : Prop :=
ContDiff ℝ 1 f ∧ Topology.IsEmbedding f ∧ ∀ z, Function.Injective (fderiv ℝ f z)
/-- Proof of Theorem 3 (Appendix B.4: "we can choose `U` such that `T_i` has only one minimum"):
the turning points of `g` are isolated, i.e. every `t` has a punctured neighbourhood on each side
of which `g` is strictly monotone. -/
def IsolatedTurningPoints (g : ℝ → ℝ) : Prop :=
∀ t, ∃ δ > 0,
(StrictMonoOn g (Set.Ioo (t - δ) t) ∨ StrictAntiOn g (Set.Ioo (t - δ) t)) ∧
(StrictMonoOn g (Set.Ioo t (t + δ)) ∨ StrictAntiOn g (Set.Ioo t (t + δ)))
end IdentifiableVAE
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
Parameter . Fix natural numbers , any of which may be . A parameter is an arbitrary quadruple with no constraints of any kind:
- a function , the "mixing function";
- functions , the "base measures";
- functions for , , the "sufficient statistics";
- a function , written , the "natural parameters".
No measurability, positivity, injectivity or integrability is part of a parameter. When a second parameter appears, it is written .
Exponent. For , , and :
When the sum is empty and .
Unnormalised factor. With the same inputs:
Since is unconstrained, this may be zero or negative.
Normalising constant. This is the Lebesgue integral over the real line:
By convention it equals whenever is not Lebesgue-integrable. It may also be or negative for integrable when takes negative values.
Prior density. For and :
Division by zero is defined to give . So if some , including the non-integrable case above, then . When the product is empty and . The value may be negative.
Prior measure. For , is the measure on having density with respect to Lebesgue measure. Negative density values are replaced by . Nothing forces to be a probability measure: it may be the zero measure, or have any total mass. When , is a single point carrying mass .
Observed law. Given an arbitrary measure on (not required to be a probability measure), a parameter and :
Here:
- is the push-forward of the prior measure by . By convention it is the zero measure if is not almost-everywhere measurable for .
- is convolution, i.e. the push-forward of the product measure under .
Admissible parameter on . Given a set , is admissible on when all of the following hold:
- is (Borel) measurable;
- is injective;
- each is measurable;
- each is strictly positive at every point of ;
- each is measurable;
- for every and every , the function is Lebesgue-integrable on .
Nothing is required of (not even measurability), and nothing is required at points . If , condition 6 is vacuous. Injectivity of with forces .
Sufficient-statistic vector. For , is the vector in , indexed by pairs , with entries
Linear relation (everywhere). For parameters , a real matrix (rows and columns indexed by pairs ) and , the relation holds when, for every , there exists with
In particular this requires . The point need not be unique, and neither nor is assumed injective.
Linear relation (almost everywhere). This is the same condition, except that it is required only for Lebesgue-almost every . For each such there exists with and . The condition may fail on a Lebesgue-null set of .
Block permutation matrix. An matrix , indexed by pairs, has this property when there is a permutation of such that
for all and . The blocks are not required to be nonzero. The zero matrix qualifies, and when or every matrix qualifies.
Relations , , (everywhere).
- means there exist a real matrix and satisfying the everywhere linear relation.
- additionally requires to be invertible ().
- requires to be both invertible and a block permutation matrix as above.
None of these relations is asserted to be symmetric, reflexive or transitive.
Relations , , (almost everywhere). These are defined identically, with the almost-everywhere linear relation in place of the everywhere one:
- existence of ;
- existence of with ;
- existence of with and a block permutation matrix.
Identifiability up to a relation. Fix:
- a measure on ;
- a set ;
- a set of parameters;
- an arbitrary binary relation on parameters;
- a parameter .
Then is identifiable up to when, for every ,
Equality is equality of measures on . The parameter itself is not required to lie in or to be admissible. If , the hypothesis is vacuous and the condition says for every .
Null zero set of the characteristic function. For a measure on , define
The condition is that has Lebesgue measure . If has infinite total mass, the integrand is not integrable and is by convention, so the condition fails. It also fails for the zero measure. When , it holds exactly when has finite nonzero total mass.
Regularity of the sufficient statistics. satisfies this when both of the following hold:
- (a) every is differentiable at Lebesgue-almost every ;
- (b) for every , every set of positive Lebesgue (outer) measure, every and every ,
is not required to be measurable. When , part (b) holds trivially.
Invertible matrix . Given and , the condition is that there exist a point and a family of points indexed by pairs such that:
- ;
- every ;
- the are pairwise distinct;
- each ;
- the matrix with entries
(row , column ) has .
When , is the empty matrix with determinant , and the condition reduces to .
Twice-differentiable statistics. For every , the function is differentiable at every point of , and its derivative is also differentiable at every point of . Continuity of is not required.
Second cross partials of . For , write for the -th standard basis vector. Two conditions are required:
- (a) For every coordinate and every , the partial derivative exists.
- (b) For all coordinates and every , the function has a partial derivative in direction at , i.e. exists.
Nothing is required of the diagonal second derivatives , nor of any continuity or full (Fréchet) differentiability. When , part (b) is vacuous.
Continuous partials of . For every coordinate , the partial derivative , taken along the line , exists at every , and the map is continuous from to .
Non-monotone statistics (case ). For a parameter with , for every , the single statistic is not strictly increasing on and is not strictly decreasing on . Functions that are monotone but not strictly so, e.g. constants, satisfy this condition.
embedding. For , the condition is the conjunction of:
- is continuously (Fréchet) differentiable;
- is a topological embedding, i.e. injective, continuous, and a homeomorphism onto its image with the subspace topology;
- at every , the derivative is an injective linear map.
Condition 3 forces . No statement about or diffeomorphisms is part of this definition.
Isolated turning points. For , the condition is that for every there is such that:
- on the open interval , is strictly increasing or strictly decreasing;
- on the open interval , is strictly increasing or strictly decreasing.
No continuity of is required, and nothing is said about the value itself.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.