brainhops.datamodel.kinds
This module defines a transformation
The class A is a subclass of B if A can be converted to B without loss. For example, Linear is a subclass of Affine. This is akin to set theory in mathematics.
This differs from the usual "type hierarchy", where inheriting classes can be more specialized then their parents.
We implement both types of hierarchy, so that users can easily check whether a transformation can be conceptually thought as a given class of transformation (e.g. "is this transformation a linear transform?"), without it being conflated with type inheritance (e.g. "is this transformation an instance of the Linear type?").
In our hierarchy, transformation kinds correspond to sets, and
inheritance describes set inclusion: issubclass(A, B) implies
A ⊆ B. Transformations map from ℝⁿ to ℝᵐ and can be composed when
their domains and codomains match. Homeomorphisms require n = m.
Some of these transformation sets (but not all!) are groups under the
composition operator. This is indicated by the group decorator.
The group structure refers to transformations of a fixed space ℝⁿ under
composition; these groups act on ℝⁿ. If a set A is a subset of set B,
and both A and B are groups, then A is a subgroup of B.
Many linear transformations, when constrained to be invertible, can
be thought of as members of a Lie group, i.e. of a smooth manifold,c
and their group operations (composition and inversion) are smooth maps.
This is indicated by the liegroup decorator. Note that the set A
may be a subgroup of a Lie group B without being a Lie group itself!
Lie groups
G | > 0 | = 1 | ⋉ T
======================
GL ------------- Aff General Linear | Affine
| \ |
| GL+ ------- Aff+ Positive Linear | Positive Affine
| | \ |
| | SL ---- SAff Special Linear | Special Affine
| | | |
CO ------------- Sim Conformal | Affine Conformal
| \ | | |
| CO+ ------- Sim+ Special Conformal | Special Affine Conformal
| | | |
O ------------- E Orthogonal | Euclidean
| \ | / |
S SO -------- SE Special Orthogonal | Special Euclidean
| / |
I ------------- T Identity | Translation
General Lie groups (GL/CO/O) are in general not "connected", and instead composed of two disconnected components. One that contains the identity, and one that does not (the "flipped" version).
Positive Lie groups (SO/CO+/GL+) are restricted to transformations with positive determinant, and therefore exclude flips. They can be defined as the component from the corresponding general group that contains the identity transform.
All classical linear group can be extended with the translation group (⋉ T) to define affine groups.
Info
-
The Special Euclidean group (SE) contains transformations that are classicaly referred to as "rigid-body" transformations. They preserve angles and volumes.
-
The Special Conformal Euclidean group (Sim+) contains transformations that are classicaly referred to as "similitude" (or conformal) transformations. They only preserve (oriented) angles.
Warning
Python preserves the declared order of bases in the method resolution order (MRO), whereas set inclusion imposes no order between unrelated supersets. These ordering constraints can conflict, even when the inclusion hierarchy is acyclic. Resolving a conflict may require reordering bases throughout the hierarchy or explicitly listing ancestors that are already inherited indirectly. Neither change alters the intended set inclusions.
Classes
TransformationFamily
magic
Bases: Sequence, Magic
A parametric family of transformations.
A family is parameterized by a base type and, optionally, input and/or output dimensions.
Attributes
ndim
class-attribute
instance-attribute
The dimensionality of the transformations in this family, if known.
odim
class-attribute
instance-attribute
The output dimensionality of the transformations in this family, if known.
fsymbol
property
fsymbol: str | None
The symbol of the transformation family, with its dimension.
If the family dimensionality is unknown, the dimension is the
placeholder {n}.
Methods:
parse
classmethod
parse(
repr: FamilyLike,
ndim: Dim = MISSING,
odim: Dim = MISSING,
) -> Self
Return a transformation family from its name, symbol or type.
An explicit ndim wins over one carried by repr; ndim=None
means "whatever repr says", so parsing a family is idempotent.
The cases are ordered so that no branch is reached with a value it
cannot type-check: a bare issubclass would raise on an int or a
str.
from_tuple
classmethod
from_tuple(
values: FamilyTupleLike,
ndim: Dim = MISSING,
odim: Dim = MISSING,
) -> Self
Return a transformation family from its (kind, ndim) pair.
from_name
classmethod
Return a transformation family from its name.
TransformationKind
Bases: ABC
The root of the transformation
A subclass declares its SYMBOL (a short mathematical symbol, such
as "SO") and its FSYMBOL (the same symbol with a dimension
placeholder, such as "SO({n})"), and its ALIAS (one or more
plain-text names). These are recorded automatically on subclassing,
and are what TransformationFamily.parse resolves a string against.
The class name is automatically registered as a name, and is the preferred name of the transformation kind.
Aliases can also be registered with the alias decorator.
Transformation
VolumePreserving
Bases: Transformation
A transformation that preserves volumes locally .
If the map is smooth, this means |det Df| = 1.
OrientationPreserving
Bases: Transformation
A transformation that preserves orientation.
If the map is smooth, this means det Df > 0.
AnglePreserving
Bases: Transformation
A transformation that preserves angles.
If the map is smooth, this means (Df).T @ (Df) = λ(x) I.
alias: Conformal
wiki: https://en.wikipedia.org/wiki/Conformal_map
Injection
Bases: Transformation
A one-to-one transformation (distinct inputs map to distinct outputs).
alias: Injective
wiki: https://en.wikipedia.org/wiki/Injective_function
Surjection
Bases: Transformation
An onto transformation (every output is reached).
alias: Surjective
wiki: https://en.wikipedia.org/wiki/Surjective_function
Bijection
Bases: Injection, Surjection
An invertible transformation.
A bijection is both injective and surjective.
alias: Bijective, Invertible
wiki: https://en.wikipedia.org/wiki/Bijection
Homeomorphism
Bases: Bijection
A continuous bijection with a continuous inverse.
wiki: https://en.wikipedia.org/wiki/Homeomorphism
Diffeomorphism
Bases: Homeomorphism
A smooth homeomorphism, with a smooth inverse.
wiki: https://en.wikipedia.org/wiki/Diffeomorphism
VolumePreservingDiffeomorphism
Bases: VolumePreserving, Diffeomorphism
A diffeomorphism that preserves volumes.
OrientationPreservingDiffeomorphism
Bases: OrientationPreserving, Diffeomorphism
A diffeomorphism that preserves orientation.
ConformalDiffeomorphism
Bases: AnglePreserving, Diffeomorphism
A diffeomorphism that preserves angles.
SpecialDiffeomorphism
Bases: VolumePreservingDiffeomorphism, OrientationPreservingDiffeomorphism
A diffeomorphism that preserves both volume and orientation.
Preserves the standard volume form: det(Df(x)) = 1 everywhere. Includes all connected components satisfying this condition.
Matrix
Bases: Transformation
Transformation that can be represented as a matrix.
This includes linear operators, as well as more general affine operators that can be represented as linear operators acting on homogeneous coordinates.
wiki: https://en.wikipedia.org/wiki/Transformation_matrix
InvertibleMatrix
Bases: Matrix, Diffeomorphism
A matrix transformation that is invertible.
A matrix map is smooth, and an invertible one has a smooth (matrix) inverse, so this is where the smooth end of the lattice attaches: every invertible affine transformation is a diffeomorphism, and a volume preserving one (SL, SAff) is one of those.
wiki: https://en.wikipedia.org/wiki/Invertible_matrix
OrientationPreservingMatrix
Bases: OrientationPreservingDiffeomorphism, InvertibleMatrix
An invertible matrix transformation with positive determinant.
VolumePreservingMatrix
Bases: VolumePreservingDiffeomorphism, InvertibleMatrix
An invertible matrix transformation with determinant ± 1.
Affine
Bases: Matrix
An affine transformation. May not be invertible.
wiki: https://en.wikipedia.org/wiki/Affine_transformation
InvertibleAffine
Bases: Affine, InvertibleMatrix
An invertible affine transformation
Invertible affine transformations form a Lie group, named Aff.
This group includes reflections, and has therefore two connected components.
symbol: Aff = GL ⋉ T
wiki: https://en.wikipedia.org/wiki/Affine_group
PositiveAffine
Bases: InvertibleAffine, OrientationPreservingMatrix
Affine transformation with a positive determinant.
This group does not include reflections, and has therefore a single connected component.
symbol: Aff+ = GL+ ⋉ T
wiki: https://en.wikipedia.org/wiki/Affine_group
VolumePreservingAffine
Bases: InvertibleAffine, VolumePreservingMatrix
An affine transformation with determinant ±1 -- preserves volumes.
SpecialAffine
Bases: PositiveAffine, VolumePreservingAffine, SpecialDiffeomorphism
An affine transformation with determinant +1 -- preserves volumes
This group does not include reflections, and has therefore a single connected component.
symbol: SAff = SL ⋉ T
wiki: https://en.wikipedia.org/wiki/Affine_group#Special_affine_group
ConformalEuclidean
Bases: InvertibleAffine, ConformalDiffeomorphism
An affine transformation that preserves angles.
This group includes reflections, and has therefore two connected components.
symbol: Sim = CO ⋉ T
alias: Similarity, Similitude
wiki: https://en.wikipedia.org/wiki/Similarity_(geometry)#In_Euclidean_space
SpecialConformalEuclidean
Bases: ConformalEuclidean, PositiveAffine
An affine transformation that preserves angles and orientation.
This group does not include reflections, and has therefore a single connected component.
symbol: Sim+ = CO+ ⋉ T
alias: DirectSimilarity, DirectSimilitude
wiki: https://en.wikipedia.org/wiki/Similarity_(geometry)#In_Euclidean_space
Euclidean
Bases: ConformalEuclidean, VolumePreservingAffine
A euclidean transformation with determinant ± 1
symbol: E = O ⋉ T
wiki: https://en.wikipedia.org/wiki/Euclidean_group
SpecialEuclidean
Bases: SpecialConformalEuclidean, Euclidean, SpecialAffine
A euclidean transformation with determinant +1
symbol: SE = SO ⋉ T
alias: RigidTransformation
wiki: https://en.wikipedia.org/wiki/Euclidean_group#Direct_and_indirect_isometries
Dilation
Bases: ConformalEuclidean
A dilation is a scaling and a translation.
symbol: ℝ* ⋉ T
alias: HomothetyTranslation
wiki: https://en.wikipedia.org/wiki/Homothety wiki: https://en.wikipedia.org/wiki/Dilation_(metric_space)
PositiveDilation
Bases: Dilation, SpecialConformalEuclidean
A dilation with a positive scaling factor.
symbol: ℝ+ ⋉ T
wiki: https://en.wikipedia.org/wiki/Dilation_(metric_space)
Translation
Bases: PositiveDilation, SpecialEuclidean
A translation.
symbol: T
wiki: https://en.wikipedia.org/wiki/Translation_(geometry)#As_a_group
Linear
InvertibleLinear
Bases: Linear, InvertibleAffine
An invertible linear transformation.
Invertible linear transformation form a Lie group, named the General Linear group (GL).
This group includes reflections, and has therefore two connected components.
symbol: GL
wiki: https://en.wikipedia.org/wiki/General_linear_group
PositiveLinear
Bases: InvertibleLinear, PositiveAffine
Linear transformation with a positive determinant.
This group does not include reflections, and has therefore a single connected component.
symbol: GL+
SpecialLinear
Bases: PositiveLinear, SpecialAffine
A linear transformation with determinant 1 -- preserves volumes .
A linear map is an affine map whose translation vanishes, so SL sits
inside SAff = SL ⋉ T -- the horizontal link of the diagram above -- and
reaches VolumePreservingDiffeomorphism through it.
symbol: SL
wiki: https://en.wikipedia.org/wiki/Special_linear_group
ConformalOrthogonal
Bases: InvertibleLinear, ConformalEuclidean
A linear transformation that preserves angles (CO)
symbol: CO = O x ℝ+
wiki: https://en.wikipedia.org/wiki/Orthogonal_group#Conformal_group
SpecialConformalOrthogonal
Bases: ConformalOrthogonal, PositiveLinear, SpecialConformalEuclidean
A linear transformation that preserves angles and orientation (CO+)
symbol: CO+ = SO x ℝ+
wiki: https://en.wikipedia.org/wiki/Orthogonal_group#Conformal_group
Note
A scaled rotation c R has determinant c**n, which is positive
but only equal to one when c is. CO+ therefore sits under GL+
(PositiveLinear), in the positive-determinant column of the
diagram above, and not under SL: it does not preserve volumes.
The rotations do -- see SpecialOrthogonal, which declares SL
for itself.
Orthogonal
Bases: ConformalOrthogonal, Euclidean
A orthogonal matrix (AA' = I) with determinant ±1
symbol: O
wiki: https://en.wikipedia.org/wiki/Orthogonal_group
SpecialOrthogonal
Bases: Orthogonal, SpecialConformalOrthogonal, SpecialEuclidean, SpecialLinear
A orthogonal matrix (AA' = I) with determinant +1
symbol: SO
alias: Rotation
wiki: https://en.wikipedia.org/wiki/Orthogonal_group#Special_orthogonal_group
Note
SL is declared here rather than inherited: a rotation preserves
volumes, but the conformal group it also belongs to does not (see
SpecialConformalOrthogonal), so no ancestor can carry the
fact.
GeneralizedPermutation
Bases: InvertibleLinear
A generalized permutation.
Permutations are invertible by definition.
The generalized permutation group is the semidirect product of the symmetric group (permutations) and the group of invertible diagonal matrices.
symbol: Δ ⋊ S
wiki: https://en.wikipedia.org/wiki/Generalized_permutation_matrix
SignedPermutation
Bases: GeneralizedPermutation, Orthogonal
A signed permutation.
A generalized permutation with non-zero entries ±1.
symbol: B = C₂ⁿ ⋊ S
alias: HyperoctahedralGroup
wiki: https://en.wikipedia.org/wiki/Generalized_permutation_matrix#Signed_permutation_group
Permutation
Bases: SignedPermutation, Orthogonal
A permutation.
A generalized permutation with non-zero entries +1.
Permutations form the symmetric group, named S.
symbol: S
wiki: https://en.wikipedia.org/wiki/Permutation_group
EvenPermutation
Bases: Permutation, SpecialOrthogonal
An even permutation.
A permutation with determinant +1.
A permutation matrix is orthogonal, and an even one has determinant +1, so the even permutations are exactly the permutations that lie in SO(n). That edge is what makes SO(n) closed under composition with an even permutation -- and hence what lets a subspace transform that reindexes its axes by an even permutation stay a rotation.
Even permutations form the (finite discrete) Alternating Group A.
symbol: A
wiki: https://en.wikipedia.org/wiki/Alternating_group
OddPermutation
Bases: Permutation
An odd permutation.
A permutation with determinant -1.
Note
This is the coset S \ A, not a group: composing two odd
permutations gives an even one, so the set is not closed under
composition and does not contain the identity.
symbol: S \ A
wiki: https://en.wikipedia.org/wiki/Permutation_group wiki: https://en.wikipedia.org/wiki/Alternating_group
Diagonal
Bases: Linear
A diagonal matrix, may not be invertible.
wiki: https://en.wikipedia.org/wiki/Diagonal_matrix wiki: https://en.wikipedia.org/wiki/Scaling_(geometry)
InvertibleDiagonal
Bases: Diagonal, GeneralizedPermutation
An invertible diagonal matrix.
Invertible diagonal matrices form a Lie group.
This group includes reflections, and has therefore 2**n connected components.
symbol: Δ
PositiveDiagonal
Bases: InvertibleDiagonal, PositiveLinear
A diagonal matrix with positive entries.
This group does not include reflections, and has therefore a single connected component.
symbol: Δ+
SpecialDiagonal
OrthogonalDiagonal
SpecialOrthogonalDiagonal
Bases: OrthogonalDiagonal, SpecialDiagonal, SpecialOrthogonal
An orthogonal diagonal matrix with determinant +1.
symbol: Δ_SO
Multiplicative
InvertibleMultiplicative
Bases: Multiplicative, InvertibleDiagonal, ConformalOrthogonal
A scaling with the same nonzero factor in all dimensions.
An isotropic scaling preserves angles: c I is |c| times the
orthogonal sign(c) I, so ℝ* lies in CO.
symbol: ℝ = {c I : c ∈ ℝ}
alias: Homothety, HomogeneousDilation
wiki: https://en.wikipedia.org/wiki/Multiplicative_group wiki: https://en.wikipedia.org/wiki/Homothety
PositiveMultiplicative
Bases: InvertibleMultiplicative, PositiveDiagonal, SpecialConformalOrthogonal
A scaling with the same positive factor in all dimensions.
A positive factor is a non-zero one, so this is a subgroup of ℝ*
(InvertibleMultiplicative) and not merely a subset of ℝ
(Multiplicative), which it reaches through it.
symbol: ℝ+ = {c I : c ∈ ℝ+*}
alias: PositiveHomothety
wiki: https://en.wikipedia.org/wiki/Scaling_(geometry)
Identity
Bases: Translation, EvenPermutation, SpecialOrthogonalDiagonal, PositiveMultiplicative, SpecialOrthogonal
The identity transformation.
symbol: I
wiki: https://en.wikipedia.org/wiki/Identity_function
Functions:
is_group
is_group(cls: _Type) -> bool
is_lie_group
is_lie_group(cls: _Type) -> bool
Return whether a set of transformations forms a Lie group.
A class is recognized as a Lie group when it was marked with the
liegroup decorator.
is_connected
is_connected(cls: _Type) -> bool
Return whether a set of transformations is connected.
A class is recognized as connected when it was marked with the
connected or simplyconnected decorator.
is_simplyconnected
is_simplyconnected(cls: _Type) -> bool
Return whether a set of transformations is simply connected.
A class is recognized as simply connected when it was marked with
the simplyconnected decorator.
is_invertible
is_invertible(cls: _Type) -> bool
Return whether a set of transformations is known to be invertible.
is_closedunder
cached
is_closedunder(cls: _Type, subcls: _Type) -> bool
Return whether a set of transformations is closed under composition with another set.
This is always the case when subcls is a subgroup of cls, or
when subcls is a subset of cls and cls is closed.
There can be more special cases, which are registered with the
closedunder decorator.
is_closed
is_closed(cls: _Type) -> bool
Return whether a set of transformations is closed under composition.
is_transformation_set
Return whether an object is a node of this hierarchy, i.e. whether it denotes a set of maps rather than a representation of one.
True for a class defined in this module (a real subclass of
TransformationKind), False for a concrete transformation, a
field, a wrapper or a container. A concrete transformation is
only ever a virtual subclass of the node it registered to, and
virtual registration does not touch the MRO, so the test separates
the two cleanly.
is_embeddable
is_embeddable(cls: _Type) -> bool
Return whether a set of transformations is known to embed into a higher-dimensional space by padding with the identity.
The embedding is T -> T ⊕ I, block-diagonal: T acts on the axes
it already acted on, and the new ones pass through. The set is
embeddable when the result stays in the same set one dimension up,
G(n) ⊕ I ⊆ G(n+k). For example:
- Every element of SO(3) is an element of SO(4) that way;
- Most elements of ℝ(3) (a scaling by the same factor along every
axis) are not elements of ℝ(4), since e.g.
diag(2, 2, 2, 1)is not isotropic in ℝ⁴.
Note
This is an embedding: an injective homomorphism placing one group inside a bigger one.
as_invertible
Return the invertible subset of a set of transformations, if any.
Raises:
| Type | Description |
|---|---|
TypeError
|
If the set is not invertible and has no known invertible subset. |
as_unrestricted
Return the superset of a set of transformations that does not eclude non-invertible transformations (if any).
group
Mark the set of transformations as forming a group under composition.
wiki: https://en.wikipedia.org/wiki/Group_(mathematics)
liegroup
Mark the set of transformations as forming a Lie group under composition.
wiki: https://en.wikipedia.org/wiki/Lie_group
connected
Mark the set of transformations as being connected.
wiki: https://en.wikipedia.org/wiki/Connected_space
simplyconnected
Mark the set of transformations as being simply connected.
wiki: https://en.wikipedia.org/wiki/Simply_connected_space
invertible_subset_of
Mark the set of transformations as the invertible subset of another set.
wiki: https://en.wikipedia.org/wiki/Inverse_element
closedunder
Mark the set of transformations as being closed under compatible composition with another set.
The argument is a set of transformations that is a superset of cls.
wiki: https://en.wikipedia.org/wiki/Closure_(mathematics)
closed
Mark the set of transformations as being closed under compatible composition.
wiki: https://en.wikipedia.org/wiki/Closure_(mathematics)
nonembeddable
Mark the set of transformations as not embedding into a higher-dimensional space by padding with the identity.
See is_embeddable for what the embedding is.
alias
alias(cls: _Type, *names: str) -> _Type
Register a transformation set under an additional name.
This is useful for sets that have multiple common names.