Slotted latent model: compositional and irreducible generators, slot identifiability, compositional contrast
DefinitionObjectCentric_BasicObjects of Sections 2-3 and Appendix A of Brady, Zimmermann, Sharma, Schölkopf, von Kügelgen and Brendel (ICML 2023).
- Latent and observation spaces. A scene with objects has latent representation , where each slot space is . Observations are images with pixels, .
- Diffeomorphisms. A generator with inverse is a diffeomorphism: is , is on , and for all . A diffeomorphism is a bijection with inverse.
- Jacobian and index sets (eq. 3). has rows indexed by pixels and columns by the latent coordinates . For a pixel , is its gradient with respect to slot , and .
- Compositionality (Definition 1). is compositional if for all and all .
- Mechanisms (Definitions 2-4). For , is the submatrix of formed by the rows in . The sub-mechanisms for are independent if and dependent if the left side is strictly smaller.
- Irreducibility (Definition 5). is irreducible if for all , all , and every partition of into two nonempty disjoint sets , the sub-mechanisms and are dependent.
- Slot identifiability (Definition 6). slot-identifies if for every there is a unique and a diffeomorphism with for all .
- Slot blocks. For a map , , the block of .
- Compositional contrast (Definition 7, eq. 6). .
- Objective (eq. 7). For a latent law on , an encoder , a decoder and , with , .
Formalization Note "Diffeomorphism" and "differentiable" are read as continuously differentiable (). The observation space is a subset of , and differentiability of a map defined on is differentiability relative to . Partial derivatives are taken from the Fréchet derivative, which is at points where a map is not differentiable. Every statement that uses these notions therefore assumes the required differentiability. The objective is the expectation in of of the integrand, written as an integral over with . This is the expectation under the push-forward .
import Mathlib
/-!
Brady, Zimmermann, Sharma, Schölkopf, von Kügelgen and Brendel, *Provably Learning Object-Centric
Representations*, ICML 2023, arXiv:2305.14229v1: the slotted latent space and the pixel space of
Section 2 (eq. (1), (2)), the index sets `I_k(z)` (eq. (3)), compositionality (Definition 1),
mechanisms, sub-mechanisms and their (in)dependence (Definitions 2-4), irreducibility
(Definition 5), slot identifiability (Definition 6), the compositional contrast (Definition 7,
eq. (6)) and the auto-encoder objective (eq. (7)) of Section 3.
Throughout, "diffeomorphism" and "differentiable" are read as continuously differentiable (`C¹`).
-/
open MeasureTheory
noncomputable section
namespace ObjectCentric
/-- Section 2.1: the latent space `Z = Z_1 × ... × Z_K` with `Z_k = ℝ^M`; a scene representation
`z` assigns to each slot `k ∈ [K]` its latent vector `z_k = z k ∈ ℝ^M`. -/
abbrev Lat (K M : ℕ) : Type := Fin K → Fin M → ℝ
/-- Section 2 and Appendix A (Notation): the ambient pixel space `ℝ^N` containing the observation
space `X`; pixel `n ∈ [N]` of an observation `x` is `x n`. -/
abbrev Obs (N : ℕ) : Type := Fin N → ℝ
variable {K M N : ℕ}
/-- Section 2: `f : Z → X` is a (`C¹`) diffeomorphism onto the observation space `X ⊆ ℝ^N`, with
inverse `g : X → Z`: `f` is `C¹`, `g` is `C¹` on `X`, `f(Z) = X`, and `g (f z) = z` for all `z`
(so also `f (g x) = x` for all `x ∈ X`). Footnote 1: a differentiable bijection with
differentiable inverse. -/
def IsDiffeoWithInv (f : Lat K M → Obs N) (g : Obs N → Lat K M) (X : Set (Obs N)) : Prop :=
ContDiff ℝ 1 f ∧ ContDiffOn ℝ 1 g X ∧ Set.range f = X ∧ ∀ z, g (f z) = z
/-- Definition 6: a (`C¹`) diffeomorphism `h : Z_k → Z_j` between two slot spaces `ℝ^M`. -/
def IsSlotDiffeo (h : (Fin M → ℝ) → (Fin M → ℝ)) : Prop :=
ContDiff ℝ 1 h ∧ ∃ h' : (Fin M → ℝ) → (Fin M → ℝ),
ContDiff ℝ 1 h' ∧ Function.LeftInverse h' h ∧ Function.RightInverse h' h
/-- The Jacobian matrix `J f (z) = (∂f_n/∂z_{k,m}(z))`, with rows indexed by pixels `n ∈ [N]` and
columns by pairs (slot `k`, slot coordinate `m`). -/
def jac (f : Lat K M → Obs N) (z : Lat K M) : Matrix (Fin N) (Fin K × Fin M) ℝ :=
fun n c => fderiv ℝ f z (Pi.single c.1 (Pi.single c.2 1)) n
/-- The partial derivative `∂f_n/∂z_k (z) ∈ ℝ^M` of pixel `n` with respect to slot `k`. -/
def slotGrad (f : Lat K M → Obs N) (z : Lat K M) (n : Fin N) (k : Fin K) : Fin M → ℝ :=
fun m => jac f z n (k, m)
/-- Eq. (3): `I_k(z) = {n ∈ [N] : ∂f_n/∂z_k (z) ≠ 0}`, the pixels that functionally depend on
slot `k` at `z`. -/
def indexSet (f : Lat K M → Obs N) (z : Lat K M) (k : Fin K) : Set (Fin N) :=
{n | slotGrad f z n k ≠ 0}
/-- Definition 1 (Compositionality), eq. (4): for all `z` and all slots `k ≠ j`,
`I_k(z) ∩ I_j(z) = ∅`. (The paper requires `f` differentiable; that hypothesis is stated
separately wherever this notion is used.) -/
def IsCompositional (f : Lat K M → Obs N) : Prop :=
∀ z : Lat K M, ∀ k j : Fin K, k ≠ j → Disjoint (indexSet f z k) (indexSet f z j)
/-- Definitions 2-3: the rank of the (sub-)mechanism `J f_S (z)`, the submatrix of the Jacobian
formed by the rows (pixels) in `S ⊆ [N]`. -/
def subRank (f : Lat K M → Obs N) (z : Lat K M) (S : Set (Fin N)) : ℕ :=
((jac f z).submatrix (fun n : S => (n : Fin N)) id).rank
/-- Definition 4, eq. (5) (first display): the sub-mechanisms `J f_{S₁}(z)` and `J f_{S₂}(z)` are
independent: `rank J f_{S₁ ∪ S₂}(z) = rank J f_{S₁}(z) + rank J f_{S₂}(z)`. -/
def SubmechIndependent (f : Lat K M → Obs N) (z : Lat K M) (S₁ S₂ : Set (Fin N)) : Prop :=
subRank f z (S₁ ∪ S₂) = subRank f z S₁ + subRank f z S₂
/-- Definition 4 (second display): the sub-mechanisms `J f_{S₁}(z)` and `J f_{S₂}(z)` are
dependent: `rank J f_{S₁ ∪ S₂}(z) < rank J f_{S₁}(z) + rank J f_{S₂}(z)`. -/
def SubmechDependent (f : Lat K M → Obs N) (z : Lat K M) (S₁ S₂ : Set (Fin N)) : Prop :=
subRank f z (S₁ ∪ S₂) < subRank f z S₁ + subRank f z S₂
/-- Definition 5 (Irreducibility): for all `z`, all slots `k` and every partition of `I_k(z)` into
two sets `S₁, S₂` (nonempty, as sub-mechanisms are by Definition 3, disjoint, with union
`I_k(z)`), the sub-mechanisms `J f_{S₁}(z)` and `J f_{S₂}(z)` are dependent. -/
def IsIrreducible (f : Lat K M → Obs N) : Prop :=
∀ (z : Lat K M) (k : Fin K) (S₁ S₂ : Set (Fin N)), S₁.Nonempty → S₂.Nonempty →
Disjoint S₁ S₂ → S₁ ∪ S₂ = indexSet f z k → SubmechDependent f z S₁ S₂
/-- Definition 6 (Slot identifiability): the inference model `ĝ` slot-identifies `z = g(x)` via
`ẑ = ĝ(f(z))` if for every slot `k` there is a unique slot `j` and a diffeomorphism
`h_k : Z_k → Z_j` with `ẑ_j = h_k(z_k)` for all `z ∈ Z`. -/
def SlotIdentifies (f : Lat K M → Obs N) (ghat : Obs N → Lat K M) : Prop :=
∀ k : Fin K, ∃! j : Fin K, ∃ h : (Fin M → ℝ) → (Fin M → ℝ),
IsSlotDiffeo h ∧ ∀ z : Lat K M, ghat (f z) j = h (z k)
/-- Appendix A, Propositions 1 and 3: the `M × M` block `∂ẑ_j/∂z_i (z)` of the Jacobian of a map
`h : Z → Z`, `z ↦ ẑ` (applied there to `h = ĝ ∘ f`). -/
def slotBlock (h : Lat K M → Lat K M) (z : Lat K M) (j i : Fin K) : Matrix (Fin M) (Fin M) ℝ :=
fun a b => fderiv ℝ h z (Pi.single i (Pi.single b 1)) j a
/-- Euclidean (`L²`) norm of a vector of `ℝ^M`. -/
def l2norm (v : Fin M → ℝ) : ℝ := Real.sqrt (∑ m, v m ^ 2)
/-- Definition 7 (Compositional contrast), eq. (6):
`C_comp(f, z) = ∑_{n=1}^N ∑_{k=1}^K ∑_{j=k+1}^K ‖∂f_n/∂z_k (z)‖ ‖∂f_n/∂z_j (z)‖`. -/
def compContrast (f : Lat K M → Obs N) (z : Lat K M) : ℝ :=
∑ n, ∑ k, ∑ j ∈ Finset.Ioi k, l2norm (slotGrad f z n k) * l2norm (slotGrad f z n j)
/-- Squared Euclidean distance `‖x - y‖₂²` in pixel space. -/
def sqDist (x y : Obs N) : ℝ := ∑ n, (x n - y n) ^ 2
/-- Theorem 2, eq. (7): the objective
`E_{x ∼ p_x}[‖f̂(ĝ(x)) - x‖₂² + λ C_comp(f̂, ĝ(x))]` with `x = f(z)`, `z ∼ p_z`, as an expectation
in `[0, ∞]` of a nonnegative quantity (written over `z ∼ p_z`, i.e. against `p_x = f_* p_z`). -/
def aeObjective (f : Lat K M → Obs N) (pz : Measure (Lat K M)) (ghat : Obs N → Lat K M)
(fhat : Lat K M → Obs N) (lam : ℝ) : ENNReal :=
∫⁻ z, ENNReal.ofReal (sqDist (fhat (ghat (f z))) (f z) + lam * compContrast fhat (ghat (f z)))
∂pz
end ObjectCentric
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
Latent space . For natural numbers , this is the type of all functions assigning to each slot index a vector . Equivalently it is , with entries for and . Either or is allowed, and in that case the space is a single point. It has the product topology and the corresponding differentiable structure.
Pixel space . For a natural number , this is . A point has coordinates for , and is allowed.
. Here and are arbitrary functions defined everywhere, and is a set. The proposition holds exactly when all four of the following are true:
- is continuously differentiable () on all of .
- is on in the relative sense: derivatives are taken within the set , which need not be open.
- The image of is exactly : .
- for every .
Consequences and gaps:
- Condition 4 makes injective. Together with condition 3 it gives for .
- No condition is placed on the values of outside .
- No relation between and is stated as an assumption.
. For , this holds when:
- is on all of , and
- there exists a map with and for all .
That is, is a bijection of all of onto all of with a inverse. When , the unique map qualifies.
Jacobian . For and a point , this is the real matrix with rows indexed by pixels and columns indexed by pairs :
where is the latent vector with a in slot , coordinate , and elsewhere. If is not differentiable at , the derivative is taken to be the zero map, so is the zero matrix there.
Slot gradient. For , , a pixel and a slot , the slot gradient is the vector in
It is the zero vector wherever is not differentiable, and it is the empty vector when .
Index set . For , and a slot :
These are the pixels for which at least one partial derivative with respect to a coordinate of slot is nonzero. The set is empty in two cases:
- at every where is not differentiable;
- always, when .
. For , this holds when, for every and every pair of distinct slots ,
- No differentiability of is assumed. At points where is not differentiable all index sets are empty, so the condition holds there automatically.
- The condition is vacuously true when .
Sub-mechanism rank . For , and any set of pixels, this is the rank over of the submatrix of consisting of the rows indexed by , keeping all columns. It equals when .
. For arbitrary pixel sets , this holds when
and are not required to be disjoint or nonempty.
. For arbitrary pixel sets (again not required to be disjoint or nonempty), this holds when there is strict inequality:
. This holds when the following is true for every , every slot , and all pixel sets such that:
- and ,
- , and
- .
For every such choice,
Whenever has at most one element, no such exist, and the condition is vacuous for that . This includes:
- all where is not differentiable;
- all when ;
- the whole condition when .
. For and , this holds when, for every slot , there is exactly one slot satisfying the following: there exists some with (a bijection of with inverse) such that
Points to note:
- Uniqueness is asserted only for , not for .
- It is not stated explicitly that distinct give distinct .
- No regularity of or is assumed.
- Only the values of on the image of matter.
- Edge cases:
- : the condition is vacuously true.
- and : every qualifies, so uniqueness fails and the condition is false.
Slot block . For a map , a point and slots , this is the matrix with entries
It is the zero matrix if is not differentiable at .
Euclidean norm. For :
which equals when .
Compositional contrast . For and :
This is a sum over all unordered pairs of distinct slots, using the natural order on slot indices. It is always , and it equals in each of these cases:
- , , or ;
- at points where is not differentiable.
Squared distance. For :
This is the squared distance, with no square root taken.
Auto-encoder objective . The inputs are:
- functions , and ;
- an arbitrary measure on with its Borel structure, which need not be a probability measure, finite, or have a density;
- an arbitrary real number , which may be negative.
The objective is the value in of the lower Lebesgue integral
Points to note:
- The compositional contrast is that of , evaluated at the point .
- Negative values of the integrand, which are possible when , are truncated to .
- No measurability or integrability of the integrand is assumed.
- No relationship among , , is assumed.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.