Equivariant feed-forward networks, generalized convolution on quotient spaces, G-CNNs and Fourier transforms on finite groups
DefinitionEquivarianceConvolution_BasicObjects of Sections 3–5 and Appendices A, B and E of Kondor and Trivedi (2018). Throughout, is a finite group.
- Actions on functions (Section 3.1). If acts on a set , it acts on functions by .
- Equivariance (Definition 2). A map is -equivariant if for all and all .
- Feed-forward networks (Definitions 1 and 3). A network has index sets , activation spaces , linear maps and pointwise nonlinearities . Its activations are , starting from the input . The network is -equivariant if replacing by replaces every by .
- Quotient spaces and liftings (Section 3 box). For a subgroup , a function on lifts to , and a function on lifts to . A function on the double quotient is identified with its lift, a function on with for , .
- Convolution (eqs. (7)–(8), Definitions 4 and 7). . For and a matrix-valued , .
- G-CNN (Definition 5). A linear map is a generalized convolution if there is a filter on with . A network with is a -CNN if every is a generalized convolution with a filter on .
- Representations (Appendix A). A representation is a homomorphism . It is irreducible if and the only subspaces of invariant under every are and . The trivial representation is . A decomposition means that every , , is block diagonal with consecutive diagonal blocks , and each is an irreducible representation of . A block is trivial if it is one-dimensional and equals on .
- Fourier transform (eq. (13), Section 4.2). . A function on a quotient space is transformed through its lift.
- Subrepresentations (Appendices A, E). For linear actions on a complex vector space : a subspace is invariant if for all . It is irreducible if it is nonzero, invariant, and contains no invariant subspaces other than and . Two such restrictions are equivalent if a linear isomorphism intertwines them. The isotypic component of an irrep is the sum of all invariant subspaces on which the action is equivalent to .
Formalization Note The layers are indexed from : the Lean map phi ℓ is the paper's , and a network is given for all , of which an -layer statement uses . The origin of is the coset . Functions on are represented by their lifts to . The paper's filter type is read as matrices acting on , using the product of Definition 7 (3). The paper states its results for compact groups but works with finite or countable groups throughout (Section 4.1, Appendix A). A countable compact (Hausdorff) group is finite, so the statements take finite.
import Mathlib
/-!
Kondor and Trivedi, *On the Generalization of Equivariance and Convolution in Neural Networks to
the Action of Compact Groups*, arXiv:1802.03690v3 (ICML 2018): feed-forward networks and
equivariance (Section 3, Definitions 1–3), convolution on finite groups and quotient spaces
(Section 4, eqs. (7)–(12), Definition 4, Appendix B Definition 7), G-CNNs (Section 5,
Definition 5), representations and Fourier transforms (Section 4.2, eq. (13), Appendix A), and the
subrepresentations and isotypic components used in Appendix E.
The paper assumes throughout that the group is finite or countable (Section 4.1, Appendix A) and
states its results for compact groups; the statements take `G` finite.
-/
noncomputable section
namespace EquivarianceConvolution
open scoped BigOperators
section Basic
variable {G : Type*} [Group G]
/-- Section 3.1, item 3: the action of `g ∈ G` on functions `f : X → V` induced by an action on
`X`, `f' (T_g x) = f x`, i.e. `(T_g f)(x) = f (g⁻¹ x)`. -/
def translateFun {X V : Type*} [MulAction G X] (g : G) (f : X → V) : X → V :=
fun x => f (g⁻¹ • x)
/-- Definition 2: a (linear or non-linear) map `φ : L_{V₁}(X₁) → L_{V₂}(X₂)` is `G`-equivariant
if `φ (T_g f) = T'_g (φ f)` for every `f` and every `g ∈ G`. -/
def IsEquivariantMap (G : Type*) [Group G] {X₁ X₂ V₁ V₂ : Type*} [MulAction G X₁]
[MulAction G X₂] (φ : (X₁ → V₁) → (X₂ → V₂)) : Prop :=
∀ (g : G) (f : X₁ → V₁), φ (translateFun g f) = translateFun g (φ f)
/-- Definition 1: a multilayer feed-forward network with index sets `X ℓ` and activations in
`V_ℓ = ℂ^{d ℓ}`: linear maps `phi ℓ : L_{V_ℓ}(X_ℓ) → L_{V_{ℓ+1}}(X_{ℓ+1})` (the paper's
`φ_{ℓ+1}`) and pointwise nonlinearities `sigma ℓ : V_{ℓ+1} → V_{ℓ+1}` (the paper's `σ_{ℓ+1}`).
A network with `L + 1` layers uses the entries with `ℓ < L` only. -/
structure FeedForwardNet (X : ℕ → Type*) (d : ℕ → ℕ) where
/-- The linear map from layer `ℓ` to layer `ℓ + 1`. -/
phi : ∀ l : ℕ, (X l → Fin (d l) → ℂ) →ₗ[ℂ] (X (l + 1) → Fin (d (l + 1)) → ℂ)
/-- The pointwise nonlinearity of layer `ℓ + 1`. -/
sigma : ∀ l : ℕ, (Fin (d (l + 1)) → ℂ) → (Fin (d (l + 1)) → ℂ)
/-- Definition 1: the activations `f_0 ↦ f_1 ↦ … `, `f_{ℓ+1}(x) = σ(φ(f_ℓ)(x))`, as a function of
the input `f_0`. -/
def FeedForwardNet.act {X : ℕ → Type*} {d : ℕ → ℕ} (N : FeedForwardNet X d) :
(l : ℕ) → (X 0 → Fin (d 0) → ℂ) → (X l → Fin (d l) → ℂ)
| 0 => fun f => f
| l + 1 => fun f x => N.sigma l (N.phi l (N.act l f) x)
/-- Definition 3: an `L + 1` layer network is `G`-equivariant if transforming the input
`f_0 ↦ T^0_g f_0` transforms every layer `f_ℓ ↦ T^ℓ_g f_ℓ`, `0 ≤ ℓ ≤ L`, for every `g ∈ G`. -/
def IsEquivariantNet (G : Type*) [Group G] {X : ℕ → Type*} [∀ l, MulAction G (X l)]
{d : ℕ → ℕ} (L : ℕ) (N : FeedForwardNet X d) : Prop :=
∀ (g : G) (f₀ : X 0 → Fin (d 0) → ℂ) (l : ℕ), l ≤ L →
N.act l (translateFun g f₀) = translateFun g (N.act l f₀)
/-- Box "Essential definitions for quotient spaces" (Section 3): the lifting `f↑^G(g) = f([g]_X)`
of a function on `X = G/H` to `G`, with origin `x₀ = H` so that `[g]_X = gH`. -/
def liftQ {H : Subgroup G} {V : Type*} (f : G ⧸ H → V) : G → V :=
fun g => f (g : G ⧸ H)
/-- The lifting `f↑^G(g) = f(Hg)` of a function on the right quotient space `H\G` to `G`
(Section 3 box; Section 4.2). -/
def liftR {H : Subgroup G} {V : Type*} (f : Quotient (QuotientGroup.rightRel H) → V) : G → V :=
fun g => f (Quotient.mk _ g)
/-- Lifts of functions on the double quotient space `H\G/K` (Section 3 box, Case III of
Section 4.1): `χ (h v k) = χ v` for all `h ∈ H`, `k ∈ K`, `v ∈ G`. -/
def IsDoubleCosetFun (H K : Subgroup G) {V : Type*} (χ : G → V) : Prop :=
∀ h ∈ H, ∀ k ∈ K, ∀ v : G, χ (h * v * k) = χ v
/-- Eq. (7) and Definition 4 (eq. (8)) on lifted functions: `(f ∗ g)(u) = ∑_{v ∈ G} f(u v⁻¹) g(v)`. -/
def groupConv [Fintype G] (f g : G → ℂ) : G → ℂ :=
fun u => ∑ v, f (u * v⁻¹) * g v
/-- Appendix B, Definition 7 (3) (eq. (25)): for `f : G → ℂ^m` and `χ : G → ℂ^{n×m}`,
`(f ∗ χ)(u) = ∑_{v ∈ G} χ(v) f(u v⁻¹)`. -/
def vecConv [Fintype G] {m n : ℕ} (f : G → Fin m → ℂ) (χ : G → Matrix (Fin n) (Fin m) ℂ) :
G → Fin n → ℂ :=
fun u => ∑ v, Matrix.mulVec (χ v) (f (u * v⁻¹))
/-- Definitions 4, 5 and 7: `φ : L_{ℂ^m}(G/H) → L_{ℂ^n}(G/K)` is a generalized convolution
`φ(f) = f ∗ χ` with a filter `χ` on `H\G/K` (given by its lift to `G`), the result read as a
function on `G/K`. -/
def IsConvLayer [Fintype G] (H K : Subgroup G) {m n : ℕ}
(φ : (G ⧸ H → Fin m → ℂ) → (G ⧸ K → Fin n → ℂ)) : Prop :=
∃ χ : G → Matrix (Fin n) (Fin m) ℂ, IsDoubleCosetFun H K χ ∧
∀ (f : G ⧸ H → Fin m → ℂ) (u : G), liftQ (φ f) u = vecConv (liftQ f) χ u
/-- Definition 5: an `L + 1` layer network with index sets `X_ℓ = G/H_ℓ` is a `G`-CNN if every
linear map `φ_ℓ` is a generalized convolution with a filter on `H_{ℓ-1}\G/H_ℓ`. -/
def IsGCNN [Fintype G] (H : ℕ → Subgroup G) {d : ℕ → ℕ} (L : ℕ)
(N : FeedForwardNet (fun l => G ⧸ H l) d) : Prop :=
∀ l < L, IsConvLayer (H l) (H (l + 1)) (N.phi l)
/-- Appendix A ("Equivalence, reducibility and irreps"): the matrices `ρ(g)`, `g ∈ S`, acting on
`ℂ^ι` are irreducible: `ι` is nonempty and the only subspaces invariant under all of them are `0`
and `ℂ^ι`. -/
def IsIrreducibleOn {ι : Type*} [Fintype ι] (S : Set G) (ρ : G → Matrix ι ι ℂ) : Prop :=
Nonempty ι ∧ ∀ W : Submodule ℂ (ι → ℂ),
(∀ g ∈ S, ∀ w ∈ W, Matrix.mulVec (ρ g) w ∈ W) → W = ⊥ ∨ W = ⊤
/-- Appendix A: `ρ : G → ℂ^{n×n}` with `ρ(g₁)ρ(g₂) = ρ(g₁g₂)` is an irreducible representation. -/
def IsIrrep {n : ℕ} (ρ : G →* Matrix (Fin n) (Fin n) ℂ) : Prop :=
IsIrreducibleOn Set.univ (fun g => ρ g)
/-- Appendix A: `ρ` is the trivial representation `ρ_tr(g) = (1)`. -/
def IsTrivialRep {n : ℕ} (ρ : G →* Matrix (Fin n) (Fin n) ℂ) : Prop :=
n = 1 ∧ ∀ g, ρ g = 1
/-- Proposition 1 (hypothesis): on restriction to `H`, `ρ` is block diagonal,
`ρ|_H = μ_1 ⊕ ⋯ ⊕ μ_k`, with consecutive blocks; `b i` is the block containing index `i`, and each
block `μ_t` is an irreducible representation of `H`. -/
def IsRestrictionDecomp {n k : ℕ} (H : Subgroup G) (ρ : G →* Matrix (Fin n) (Fin n) ℂ)
(b : Fin n → Fin k) : Prop :=
Monotone b ∧ (∀ h ∈ H, ∀ i j, b i ≠ b j → ρ h i j = 0) ∧
∀ t : Fin k, IsIrreducibleOn (H : Set G)
(fun h => (ρ h).submatrix (fun i : {i // b i = t} => i.1) (fun i => i.1))
/-- Proposition 1: the block `μ_t` of the decomposition `b` of `ρ|_H` is the trivial
representation of `H` (one-dimensional, equal to `(1)` on `H`). -/
def IsTrivialBlock {n k : ℕ} (H : Subgroup G) (ρ : G →* Matrix (Fin n) (Fin n) ℂ)
(b : Fin n → Fin k) (t : Fin k) : Prop :=
Fintype.card {i // b i = t} = 1 ∧ ∀ h ∈ H, ∀ i, b i = t → ρ h i i = 1
/-- Eq. (13): the Fourier transform `f̂(ρ) = ∑_{u ∈ G} f(u) ρ(u)`; for a function on a quotient
space it is applied to the lifting (Section 4.2). -/
def groupFourier [Fintype G] {n : ℕ} (ρ : G →* Matrix (Fin n) (Fin n) ℂ) (f : G → ℂ) :
Matrix (Fin n) (Fin n) ℂ :=
∑ u, f u • ρ u
section Modules
variable {U V : Type*} [AddCommGroup U] [Module ℂ U] [AddCommGroup V] [Module ℂ V]
/-- Appendix E: a subspace `W ⊆ U` fixed by the linear action `{T_g}`. -/
def IsInvariantSubspace (T : Representation ℂ G U) (W : Submodule ℂ U) : Prop :=
∀ g : G, ∀ w ∈ W, T g w ∈ W
/-- Appendix E (Lemma 5): an irreducible subspace: nonzero, invariant, and with no invariant
subspaces other than `0` and itself. -/
def IsIrreducibleSubspace (T : Representation ℂ G U) (W : Submodule ℂ U) : Prop :=
W ≠ ⊥ ∧ IsInvariantSubspace T W ∧
∀ W' : Submodule ℂ U, W' ≤ W → IsInvariantSubspace T W' → W' = ⊥ ∨ W' = W
/-- Appendix E (Lemmas 5–6): a linear map `φ : U → V` equivariant with the actions `{T_g}` and
`{T'_g}`: `φ (T_g u) = T'_g (φ u)`. -/
def IsEquivariantLinear (T : Representation ℂ G U) (T' : Representation ℂ G V)
(φ : U →ₗ[ℂ] V) : Prop :=
∀ (g : G) (u : U), φ (T g u) = T' g (φ u)
/-- Appendix A and E (Lemma 5): the restriction of `{T_g}` to `W` and of `{T'_g}` to `Z` are
equivalent representations: a linear isomorphism `W ≅ Z` intertwining them. -/
def AreEquivalentSubreps (T : Representation ℂ G U) (W : Submodule ℂ U)
(T' : Representation ℂ G V) (Z : Submodule ℂ V) : Prop :=
∃ e : W ≃ₗ[ℂ] Z, ∀ (g : G) (w w' : W), (w' : U) = T g w → (e w' : V) = T' g (e w)
/-- Appendix A and E: an invariant subspace `W` on which `{T_g}` is equivalent to the matrix
representation `ρ`. -/
def IsOfType {n : ℕ} (T : Representation ℂ G U) (W : Submodule ℂ U)
(ρ : G →* Matrix (Fin n) (Fin n) ℂ) : Prop :=
IsInvariantSubspace T W ∧
∃ e : W ≃ₗ[ℂ] (Fin n → ℂ), ∀ (g : G) (w w' : W),
(w' : U) = T g w → e w' = Matrix.mulVec (ρ g) (e w)
/-- Appendix E (Lemma 6): the isotypic component `U_ρ` of `U` belonging to the irrep `ρ`, the sum
of all invariant subspaces of `U` on which the action is equivalent to `ρ`. -/
def isotypicPart {n : ℕ} (T : Representation ℂ G U) (ρ : G →* Matrix (Fin n) (Fin n) ℂ) :
Submodule ℂ U :=
⨆ (W : Submodule ℂ U) (_ : IsOfType T W ρ), W
end Modules
end Basic
end EquivarianceConvolution
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
Throughout, is an arbitrary group (not assumed finite unless stated) with identity . "Left action of on " means a map with and . denotes -tuples of complex numbers indexed by ; when it is the zero space.
Translation of functions (). Let carry a left action of and let be any set (no algebraic structure). For and , the translated function is
Equivariant map. Let carry left actions of , and let be arbitrary sets. Let be any function (not assumed linear, continuous, or otherwise structured) sending functions to functions . Then is called -equivariant exactly when
where is the translation above, using the action on on the left side and the action on on the right side.
Feed-forward network (data). Fix a sequence of sets indexed by all natural numbers . No finiteness is assumed. Fix a sequence of dimensions . A network consists of two infinite sequences, one entry for every :
- a -linear map from the space of functions to the space of functions ;
- an arbitrary function , with no linearity, continuity or other condition.
Activations of a network. Given as above and an input , the activations are defined for every by
That is, the same is applied at every point . We write for viewed as a function of the input.
Equivariant network. Suppose each () carries a left action of , and fix . The network is called -equivariant up to depth exactly when
with the translation on on the left side and on on the right side. Only the layers are constrained, so for play no role. The case holds automatically. When the condition is satisfied by every network.
Lift from a left quotient. For a subgroup and any set , a function on the left coset space is lifted to by
Lift from a right quotient. For a subgroup and any set , a function on the right coset space is lifted to by
Here and lie in the same class iff .
Double-coset function. For subgroups and any set , a function has this property exactly when
Scalar group convolution. Assume is finite. For ,
Vector-valued convolution. Assume is finite and let . For and (complex matrices),
The product is the matrix–vector product, with the matrix on the left.
Convolution layer. Assume is finite. Let be subgroups and . Let be any function (not assumed linear) from functions to functions . Then is a convolution layer exactly when there exists satisfying two conditions:
- for all , , ;
- for every and every ,
Equivalently, as functions on , with both lifts taken from left quotients. The equality is required at every , not just at coset representatives.
G-CNN. Assume is finite. Let be subgroups of , one for each , and let and . Let be a feed-forward network with index sets (left cosets). is a -CNN up to depth exactly when, for every , the underlying function of the linear map is a convolution layer from to , with and . The nonlinearities are not constrained. When the condition holds for every such network.
Irreducibility on a subset. Let be a finite index set, any subset, and any function. need not be a homomorphism and its values need not be invertible. The family is irreducible on exactly when both of the following hold:
- is nonempty;
- every complex linear subspace with for all and is either or all of .
Only the values for matter. If , every subspace is invariant, so the condition holds iff .
Irreducible representation. For , let be a monoid homomorphism from to complex matrices under multiplication, so and . Then is irreducible exactly when both of the following hold:
- ;
- the only subspaces of invariant under all , , are and .
Trivial representation. For such a homomorphism , is trivial exactly when and is the identity matrix for every .
Restriction decomposition. Let , a subgroup, a monoid homomorphism, and a function assigning each index a block label . The condition holds exactly when all three of the following are true:
- is non-decreasing: .
- For every and all indices with , the entry .
- For every label , let and let be the principal submatrix . Then the family is irreducible on the set . That is, , and the only subspaces of invariant under all , , are and .
Consequences:
- Condition 3 forces every label to be used, so is surjective and .
- If then necessarily , and all conditions hold vacuously.
- No condition is imposed on for .
Trivial block. With as above (but without assuming is a restriction decomposition) and a label , the block is trivial exactly when two conditions hold:
- exactly one index has ;
- for every and every index with , the diagonal entry .
Fourier transform. Assume is finite. For a monoid homomorphism and a function ,
is not assumed irreducible.
In the remaining definitions, and are complex vector spaces of arbitrary (possibly infinite) dimension. A representation of on is a homomorphism from to the -linear endomorphisms of , so and . Likewise is a representation of on .
Invariant subspace. A linear subspace is invariant under exactly when for all and .
Irreducible subspace. A subspace is irreducible under exactly when all three of the following hold:
- ;
- is invariant;
- every invariant subspace equals or .
Equivariant linear map. A -linear map is equivariant exactly when
Equivalent subrepresentations. Let and be subspaces. Neither is required to be invariant. They are equivalent exactly when there is a -linear isomorphism such that, for all and all ,
The condition only constrains pairs where happens to lie in . If is not invariant, it says nothing about those with . Neither nor is required to be irreducible.
Subspace of type . Let be a monoid homomorphism, not assumed irreducible. A subspace is of type exactly when both of the following hold:
- is invariant under ;
- there is a -linear isomorphism with for all and .
In particular , and when the zero subspace qualifies.
Isotypic component. For and as above, is the sum (the smallest subspace containing them all) of every subspace that is of type . Concretely, is the set of all finite sums of vectors from such subspaces. If no subspace is of type , or only is, then . Irreducibility of is not assumed.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.