Factorized latent laws and the entangling maps , , , of Theorem 1
DefinitionDisentanglementImpossibility_BasicObjects of Theorem 1 (Section 3, p. 3) and of its proof (Appendix A, p. 12) in Locatello et al. (2019).
- Factorized latent law. A latent variable has independent coordinates , where each is a probability measure on with a density with respect to Lebesgue measure. Its law therefore has the density . is the support of , the set of points all of whose neighbourhoods have positive probability.
- The map . , where is the cumulative distribution function of .
- Quantiles. For a law on with distribution function and , the quantile is . It is the inverse of wherever is strictly increasing.
- The map . is the standard normal distribution function, its quantile function, and .
- Reference laws. The uniform law on is the product of copies of Lebesgue measure on . The standard normal law on is the product of copies of .
- Householder matrix. For , and for . The matrix is .
- Entangling map. For a matrix , , that is, .
- Partial derivatives. is the derivative at of . For a map defined on a set , the variable ranges over those values for which .
Formalization Note Lean's deriv and derivWithin return where the derivative does not exist, so a statement that a partial derivative is nonzero also asserts that it exists. The quantile is the infimum of a set of reals. For that set is unbounded below or empty, and the value is a default. Such arguments occur only on null sets. In Lean the first coordinate of the Householder vector has index .
import Mathlib
/-!
Locatello, Bauer, Lucic, Rätsch, Gelly, Schölkopf and Bachem, *Challenging Common Assumptions in
the Unsupervised Learning of Disentangled Representations*, ICML 2019, arXiv:1811.12359v4:
the factorized latent law of Theorem 1 (Section 3, p. 3) and the maps `g`, `h`, `A`, `f` built in
its proof (Appendix A, p. 12).
-/
open MeasureTheory ProbabilityTheory
noncomputable section
namespace DisentanglementImpossibility
variable {d : ℕ}
/-- Section 3, Theorem 1 (p. 3): `z ∼ P` admits a density `p(z) = ∏ᵢ p(zᵢ)`. The law is given by
its marginals `μ i`, each a probability measure on `ℝ` with a density (absolutely continuous with
respect to Lebesgue measure); the law of `z` is their product `latentLaw μ`. -/
def IsFactorizedDensity (μ : Fin d → Measure ℝ) : Prop :=
∀ i, IsProbabilityMeasure (μ i) ∧ μ i ≪ volume
/-- Section 3, Theorem 1 (p. 3): the law `P` of `z = (z₁, …, z_d)` with independent coordinates
`zᵢ ∼ μ i`, i.e. the product measure. Its support `(latentLaw μ).support` is `supp(z)`. -/
def latentLaw (μ : Fin d → Measure ℝ) : Measure (Fin d → ℝ) :=
Measure.pi μ
/-- Appendix A (p. 12): the map `g : supp(z) → [0,1]^d`, `gᵢ(v) = P(zᵢ ≤ vᵢ)`, applying the
cumulative distribution function of each marginal to its coordinate. -/
def cdfMap (μ : Fin d → Measure ℝ) (v : Fin d → ℝ) : Fin d → ℝ :=
fun i => cdf (μ i) (v i)
/-- Appendix A (p. 12): the inverse of a cumulative distribution function, used for `g⁻¹` and for
`ψ⁻¹`. For a law `ν` on `ℝ` and `w ∈ (0,1)`, `quantile ν w = inf {x | w ≤ P_ν(X ≤ x)}`; when the
cumulative distribution function is strictly increasing this is its inverse. Values at
`w ∉ (0,1)` are a default and only occur on null sets. -/
def quantile (ν : Measure ℝ) (w : ℝ) : ℝ :=
sInf {x : ℝ | w ≤ cdf ν x}
/-- Appendix A (p. 12): `ψ`, the cumulative distribution function of the standard normal law. -/
def stdNormalCdf (x : ℝ) : ℝ :=
cdf (gaussianReal 0 1) x
/-- Appendix A (p. 12): `ψ⁻¹`, the inverse of the standard normal cumulative distribution
function on `(0,1)`. -/
def stdNormalQuantile (w : ℝ) : ℝ :=
quantile (gaussianReal 0 1) w
/-- Appendix A (p. 12): the map `h`, `hᵢ(v) = ψ⁻¹(vᵢ)`. -/
def gaussMap (v : Fin d → ℝ) : Fin d → ℝ :=
fun i => stdNormalQuantile (v i)
/-- Appendix A (p. 12): the independent `d`-dimensional uniform distribution, the law of `g(z)`:
the product of `d` copies of Lebesgue measure on `[0,1]`. -/
def uniformCube (d : ℕ) : Measure (Fin d → ℝ) :=
Measure.pi fun _ : Fin d => volume.restrict (Set.Icc (0 : ℝ) 1)
/-- Appendix A (p. 12): the `d`-dimensional standard normal distribution, the law of `h(g(z))`:
the product of `d` copies of the standard normal law `N(0,1)`. -/
def stdGaussian (d : ℕ) : Measure (Fin d → ℝ) :=
Measure.pi fun _ : Fin d => gaussianReal 0 1
/-- Appendix A (p. 12): the Householder vector `v` with `v₁ = √α` and `vᵢ = √((1-α)/(d-1))` for
`i = 2, …, d` (the first coordinate is index `0` here). -/
def householderVec (d : ℕ) (α : ℝ) : Fin d → ℝ :=
fun i => if i.val = 0 then Real.sqrt α else Real.sqrt ((1 - α) / ((d : ℝ) - 1))
/-- Appendix A (p. 12): the Householder matrix `A = I_d - 2 v vᵀ` built from `householderVec`. -/
def householderMat (d : ℕ) (α : ℝ) : Matrix (Fin d) (Fin d) ℝ :=
1 - (2 : ℝ) • Matrix.vecMulVec (householderVec d α) (householderVec d α)
/-- Appendix A (p. 12): the entangling map `f(u) = g⁻¹(h⁻¹(A h(g(u))))` for a matrix `A`:
coordinate `i` of `f(u)` is `quantile (μ i) (ψ((A h(g(u)))ᵢ))`. -/
def entanglingMap (μ : Fin d → Measure ℝ) (A : Matrix (Fin d) (Fin d) ℝ) (u : Fin d → ℝ) :
Fin d → ℝ :=
fun i => quantile (μ i) (stdNormalCdf ((A.mulVec (gaussMap (cdfMap μ u))) i))
/-- Section 3, Theorem 1 (p. 3): the partial derivative `∂fᵢ(u)/∂u_j`, the derivative at `u_j` of
`t ↦ fᵢ(u₁, …, t, …, u_d)` (`t` in position `j`). Lean's `deriv` is `0` where this derivative
does not exist, so `partialDeriv f i j u ≠ 0` asserts that it exists and is nonzero. -/
def partialDeriv (f : (Fin d → ℝ) → Fin d → ℝ) (i j : Fin d) (u : Fin d → ℝ) : ℝ :=
deriv (fun t => f (Function.update u j t) i) (u j)
/-- Section 3, Theorem 1 (p. 3): the partial derivative `∂fᵢ(u)/∂u_j` of a map `f : S → S`
defined on a set `S` (the support `supp(z)`): the derivative at `u_j` of
`t ↦ fᵢ(u₁, …, t, …, u_d)` along those `t` for which `(u₁, …, t, …, u_d) ∈ S`. Lean's
`derivWithin` is `0` where this derivative does not exist (or `u_j` is isolated), so a nonzero
value asserts that it exists and is nonzero. -/
def partialDerivWithin (f : (Fin d → ℝ) → Fin d → ℝ) (S : Set (Fin d → ℝ)) (i j : Fin d)
(u : Fin d → ℝ) : ℝ :=
derivWithin (fun t => f (Function.update u j t) i) {t | Function.update u j t ∈ S} (u j)
end DisentanglementImpossibility
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
IsFactorizedDensity. Fix a natural number , possibly . Let be a family of measures on , one for each index . The property holds exactly when, for every index :
- is a probability measure, i.e. ;
- is absolutely continuous with respect to Lebesgue measure on , i.e. .
The property places conditions on each marginal separately. It does not itself mention a joint law, a product, a density function, or a support. When there are no indices, so the property holds vacuously.
latentLaw. For any family of measures on , no hypotheses assumed, is the product measure on :
When every is -finite (for instance, a probability measure), this is the unique measure with
Otherwise it is the measure induced by the product outer measure, and that box formula is not guaranteed. When , is a single point and is the unit point mass there. The definition itself does not involve supports.
cdfMap. Let be measures on and . Then is the vector with coordinates
Here is Mathlib's cumulative distribution function attached to :
- If is a probability measure, then .
- For other measures, is still some non-decreasing, right-continuous function with values in , with limits at and at . It need not equal .
The map is defined on all of , not only on a support.
quantile. For a measure on with cumulative distribution function (as described for cdfMap) and any real , define
using the convention that the infimum of an empty set, or of a set unbounded below, is . This gives the following cases:
- : the set is nonempty and bounded below, and the infimum is attained. This is the usual generalized inverse of , and it equals when is a strictly increasing bijection onto its range.
- : the set is all of , so .
- : the set is empty, so .
- : the value is if that set is nonempty, and if everywhere.
stdNormalCdf. For real , , where is the standard normal law on . Its values lie strictly in .
stdNormalQuantile. For real , , with .
- For , this is the true inverse of .
- For every and every (including , since never reaches ), the value is .
gaussMap. For , is the vector with coordinates
Here is as in stdNormalQuantile. In particular, whenever .
uniformCube. For a natural number , is the product measure
on , where is Lebesgue measure restricted to the closed interval . It is a probability measure that gives the cube full mass. When , it is the unit point mass on the single point of .
stdGaussian. For a natural number , is the product of copies of the standard normal law: a probability measure on . When , it is the unit point mass on .
householderVec. For a natural number and any real (no restriction on ), has coordinates indexed :
The square root of a negative number is taken to be . This produces the following edge cases:
- If , then .
- If , then for all .
- For , the vector is just .
- For , the vector is empty.
- When and , one has ; outside that range, the norm need not be .
householderMat. For a natural number and real , with as in householderVec, define the real matrix
No condition is imposed on . In particular, nothing in the definition ensures . The matrix is an orthogonal reflection only when ; it is the identity when .
entanglingMap. Let be any family of measures on , let be any real matrix (not required to be orthogonal or invertible), and let . Then has coordinates
In words, the map proceeds in four steps:
- Apply the marginal distribution functions coordinatewise (, from
cdfMap). - Apply coordinatewise (, from
gaussMap). - Multiply by .
- Apply , then the -th marginal's quantile (from
quantile).
The map is defined for all . If some , the corresponding coordinate of is the default . The final step evaluates only at values in , since takes values there.
partialDeriv. Let be any map, let be indices, and let . Write for the vector with its -th coordinate replaced by . Define
when this ordinary one-variable derivative exists, and when it does not. Consequently:
- implies that the derivative exists and is nonzero.
- does not distinguish a zero derivative from a nonexistent one.
partialDerivWithin. Let be any map (defined on all of ), let be any set, let be indices, and let . Let
The value is the derivative at of taken within , that is, as a limit along points approaching . It is set to in two cases:
- the derivative within does not exist;
- is not an accumulation point of (for example, is empty or is isolated in ).
Further points:
- itself is not required to lie in .
- The value at the base point enters the difference quotient whether or not .
- A nonzero value implies that this one-sided-or-two-sided restricted derivative exists and is nonzero.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.