Let (C, \otimes, I) be a strict symmetric monoidal category. The category P(C) of parametrized morphisms is given by the following data:
Objects: \mathrm{Obj}(P(C)) := \mathrm{Obj}(C)
Morphisms: For two objects A and B in P(C), a morphism f \colon A \to B in P(C) consists of:
A parameter object P \in \mathrm{Obj}(C)
A morphism f_P \colon P \otimes A \to B in C
Composition: Given two morphisms f=(P,f_P) \colon A \to B and g =(Q,g_Q) \colon B \to C in P(C),
their composition f \cdot g \colon A \to C is given by the pair
Identity morphisms: For each object A in P(C), the identity morphism is given by
the pair \mathrm{id}_A = \left( I, (\mathrm{id}_A)_I := \mathrm{id}_A \in \mathbf{Hom}_C(A, A)) \right).
‣ CategoryOfParametrisedMorphisms( C ) | ( operation ) |
Returns: a category
Construct the category of parametrised morphisms over the category C.
‣ ObjectConstrutor( Para, A ) | ( operation ) |
Returns: an object in the category of parametrised morphisms
Construct an object in the category of parametrised morphisms.
‣ MorphismConstructor( Para, A, datum, B ) | ( operation ) |
Returns: a morphism in the category of parametrised morphisms
Construct a morphism in the category of parametrised morphisms. The datum is a pair consisting of the parameter object P and the underlying morphism f_P \colon P \otimes A \to B.
‣ UnderlyingCategory( Para ) | ( attribute ) |
Returns: a category
Returns the underlying category of a category of parametrised morphisms.
‣ UnderlyingObject( A ) | ( attribute ) |
Returns: an object in the underlying category
Returns the underlying object for an object in the category of parametrised morphisms.
‣ UnderlyingObject( f ) | ( attribute ) |
Returns: an object in the underlying category
Returns the parameter object (underlying object) of a parametrised morphism.
‣ UnderlyingMorphism( f ) | ( attribute ) |
Returns: a morphism in the underlying category
Returns the underlying morphism f_p:P \otimes A \to B \in C in C of a parametrised morphism f = (P, f_p:P \otimes A \to B):A \to B in P(C).
‣ ReparametriseMorphism( f, r ) | ( operation ) |
Returns: a parametrised morphism
The input is a parametrised morphism f=(P,f_P: P\otimes A \to B): A \to B and a morphism r: Q \to P in C. The output is the reparametrised morphism \hat{f}=(Q,\hat{f}_Q: Q \otimes A \to B): A \to B where \hat{f}_Q := (r \otimes \mathrm{id}_A) \cdot f_P \colon Q \otimes A \to B.
‣ FlipParameterAndSource( f ) | ( operation ) |
Returns: a parametrised morphism
The input is a parametrised morphism f=(P,f_P: P\otimes A \to B): A \to B. The output is the parametrised morphism \hat{f}=(A,\hat{f}_A: A \otimes P \to B): P \to A where \hat{f}_A := \sigma_{A,P} \cdot f_P \colon A \otimes P \to B, with \sigma_{A,P}: A \otimes P \to P \otimes A being the symmetry isomorphism (braiding) in the underlying symmetric monoidal category C.
‣ Batchify( f, n ) | ( operation ) |
Returns: a parametrised morphism
Adjusts a parametrised morphism to process a batch of n inputs simultaneously. Given a parametrised morphism f = (P, f_P \colon P \otimes A \to B): A \to B where the target B has rank 1, this operation produces a new parametrised morphism that can handle n copies of A at once (a batch of size n).
The construction works as follows:
The source becomes the direct product of n copies of A: A^n = A \times \cdots \times A
The parameter object remains P
The underlying morphism is constructed by: \alpha \cdot f_P^{(n)} \cdot \mu_n \colon P \otimes A^n \to B where:
\alpha:P \otimes A^n \to (P \otimes A)^n is the morphism that reuses the parameter P across the n components. For example, when n=2, \alpha sends (p, a_1, a_2) \in P \otimes A^2 to (p, a_1, p, a_2) \in (P \otimes A)^2, i.e., the same parameter p is paired with each input (training example) a_i.
f_P^{(n)}: (P \otimes A)^n \to B^n is the direct product of n copies of f_P,
\mu_n: B^n \to B is the mean aggregator that averages the n outputs into a single output in B (since B has rank 1).
‣ NaturalEmbedding( C, P ) | ( operation ) |
Returns: a functor
Natural embedding functor from category C into category of parametrised morphisms P (of C). Objects are mapped to themselves, and a morphism f: A \to B in C is mapped to the parametrised morphism (I, f_I: I \otimes A \xrightarrow{f} B): A \to B in P. Note that I \otimes A = A by the strict monoidal unit property. This functor reflects the fact that ordinary morphisms can be viewed as parametrised morphisms with a trivial (unit) parameter.
‣ EmbeddingIntoCategoryOfParametrisedMorphisms( Para, Para_Lenses ) | ( operation ) |
Returns: a functor
Embedding functor from category of parametrised morphisms Para into another category of parametrised morphisms Para_Lenses.
All available smooth maps can be lifted to parametrised morphisms in the category of parametrised morphisms by using one of the following two methods:
Using the natural embedding functor from the category of smooth maps into the category of parametrised morphisms, which associates to each smooth map f: A \to B the parametrised morphism (I, f_I: I \otimes A \xrightarrow{f} B): A \to B where I is the monoidal unit. For example, \mathrm{Cos}, \mathrm{Exp}, \mathrm{Log} etc.
Constructing parametrised morphisms directly by specifying the parameter object and the underlying morphism. For instance, the construction of an affine transformation as a parametrised morphism:
gap> Smooth := SkeletalCategoryOfSmoothMaps( ); SkeletalSmoothMaps gap> Para := CategoryOfParametrisedMorphisms( Smooth ); CategoryOfParametrisedMorphisms( SkeletalSmoothMaps ) gap> Display( Para.Relu( 2 ) ); ℝ^2 -> ℝ^2 defined by: Underlying Object: ----------------- ℝ^0 Underlying Morphism: ------------------- ℝ^2 -> ℝ^2 ‣ Relu( x1 ) ‣ Relu( x2 ) gap> dummy_input := DummyInputForAffineTransformation( 3, 2, "w", "b", "z" ); [ w1_1, w2_1, w3_1, b_1, w1_2, w2_2, w3_2, b_2, z1, z2, z3 ] gap> affine_transformation := Para.AffineTransformation( 3, 2 );; gap> Display( affine_transformation : dummy_input := dummy_input ); ℝ^3 -> ℝ^2 defined by: Underlying Object: ----------------- ℝ^8 Underlying Morphism: ------------------- ℝ^11 -> ℝ^2 ‣ w1_1 * z1 + w2_1 * z2 + w3_1 * z3 + b_1 ‣ w1_2 * z1 + w2_2 * z2 + w3_2 * z3 + b_2 gap> "Let us convert these 2 togits to probabilities via softmax layer.";; gap> softmax_layer := Para.Softmax( 2 );; gap> Display( softmax_layer ); ℝ^2 -> ℝ^2 defined by: Underlying Object: ----------------- ℝ^0 Underlying Morphism: ------------------- ℝ^2 -> ℝ^2 ‣ Exp( x1 ) / (Exp( x1 ) + Exp( x2 )) ‣ Exp( x2 ) / (Exp( x1 ) + Exp( x2 )) gap> probs := PreCompose( affine_transformation, softmax_layer );; gap> Display( probs : dummy_input := dummy_input ); ℝ^3 -> ℝ^2 defined by: Underlying Object: ----------------- ℝ^8 Underlying Morphism: ------------------- ℝ^11 -> ℝ^2 ‣ Exp( w1_1 * z1 + w2_1 * z2 + w3_1 * z3 + b_1 ) / (Exp( w1_1 * z1 + w2_1 * z2 + w3_1 * z3 + b_1 ) + Exp( w1_2 * z1 + w2_2 * z2 + w3_2 * z3 + b_2 )) ‣ Exp( w1_2 * z1 + w2_2 * z2 + w3_2 * z3 + b_2 ) / (Exp( w1_1 * z1 + w2_1 * z2 + w3_1 * z3 + b_1 ) + Exp( w1_2 * z1 + w2_2 * z2 + w3_2 * z3 + b_2 )) gap> parameters := [ 0.91, 0.24, 0.88, 0.59, 0.67, 0.05, 0.85, 0.31 ];; gap> logits := [ 1.0, 2.0, 3.0 ];; gap> Eval( probs, [ parameters, logits ] ); [ 0.729088, 0.270912 ]
The following CAP operations are supported:
IdentityMorphism (CAP: IdentityMorphism for IsCapCategoryObject)
IsCongruentForMorphisms (CAP: IsCongruentForMorphisms for IsCapCategoryMorphism, IsCapCategoryMorphism)
IsEndomorphism (CAP: IsEndomorphism for IsCapCategoryMorphism)
IsEqualForMorphisms (CAP: IsEqualForMorphisms for IsCapCategoryMorphism, IsCapCategoryMorphism)
IsEqualForMorphismsOnMor (CAP: IsEqualForMorphismsOnMor for IsCapCategoryMorphism, IsCapCategoryMorphism)
IsEqualForObjects (CAP: IsEqualForObjects for IsCapCategoryObject, IsCapCategoryObject)
IsEqualToIdentityMorphism (CAP: IsEqualToIdentityMorphism for IsCapCategoryMorphism)
IsIdempotent (CAP: IsIdempotent for IsCapCategoryMorphism)
IsWellDefinedForMorphisms (CAP: IsWellDefinedForMorphisms for IsCapCategoryMorphism)
IsWellDefinedForMorphismsWithGivenSourceAndRange (CAP: IsWellDefinedForMorphismsWithGivenSourceAndRange for IsCapCategoryObject, IsCapCategoryMorphism, IsCapCategoryObject)
IsWellDefinedForObjects (CAP: IsWellDefinedForObjects for IsCapCategoryObject)
MorphismConstructor (CAP: MorphismConstructor for IsCapCategoryObject, IsObject, IsCapCategoryObject)
MorphismDatum (CAP: MorphismDatum for IsCapCategoryMorphism)
ObjectConstructor (CAP: ObjectConstructor for IsCapCategory, IsObject)
ObjectDatum (CAP: ObjectDatum for IsCapCategoryObject)
PostCompose (CAP: PostCompose for IsCapCategoryMorphism, IsCapCategoryMorphism)
PostComposeList (CAP: PostComposeList for IsCapCategoryObject, IsList, IsCapCategoryObject)
PreCompose (CAP: PreCompose for IsCapCategoryMorphism, IsCapCategoryMorphism)
PreComposeList (CAP: PreComposeList for IsCapCategoryObject, IsList, IsCapCategoryObject)
SimplifyMorphism (CAP: SimplifyMorphism for IsCapCategoryMorphism, IsObject)
gap> LoadPackage( "GradientBasedLearningForCAP", false ); true gap> Para := CategoryOfParametrisedMorphisms( SkeletalSmoothMaps );; gap> CAP_INTERNAL_GENERATE_DOCUMENTATION_FOR_CATEGORY_INSTANCES( > [ > [ Para, "Category of Parametrised Smooth Maps", 0 ], > ], > "GradientBasedLearningForCAP", > "CategoryOfParametrisedMorphisms.autogen.gd", > "Category of Parametrised Morphisms", > "Supported CAP Operations" > ); gap> Lenses := CategoryOfLenses( SkeletalSmoothMaps );; gap> CAP_INTERNAL_GENERATE_DOCUMENTATION_FOR_CATEGORY_INSTANCES( > [ > [ Lenses, "Category of Lenses of Smooth Maps", 0 ], > ], > "GradientBasedLearningForCAP", > "CategoryOfLenses.autogen.gd", > "Category of Lenses", > "Supported CAP Operations" > );
gap> Smooth := SkeletalCategoryOfSmoothMaps( ); SkeletalSmoothMaps gap> Para := CategoryOfParametrisedMorphisms( Smooth ); CategoryOfParametrisedMorphisms( SkeletalSmoothMaps ) gap> Display( Para ); A CAP category with name CategoryOfParametrisedMorphisms( SkeletalSmoothMaps ): 12 primitive operations were used to derive 21 operations for this category gap> R1 := Smooth.( 1 ); ℝ^1 gap> R2 := Smooth.( 2 ); ℝ^2 gap> R3 := Smooth.( 3 ); ℝ^3 gap> R1 / Para; ℝ^1 gap> Para.( 1 ); ℝ^1 gap> Para.( 1 ) = R1 / Para; true gap> f := Para.Sin;; gap> Display( f ); ℝ^1 -> ℝ^1 defined by: Underlying Object: ----------------- ℝ^0 Underlying Morphism: ------------------- ℝ^1 -> ℝ^1 ‣ Sin( x1 ) gap> p1 := ProjectionInFactorOfDirectProduct( Smooth, [ R3, R3 ], 1 );; gap> Display( p1 ); ℝ^6 -> ℝ^3 ‣ x1 ‣ x2 ‣ x3 gap> p2 := ProjectionInFactorOfDirectProduct( Smooth, [ R3, R3 ], 2 );; gap> Display( p2 ); ℝ^6 -> ℝ^3 ‣ x4 ‣ x5 ‣ x6 gap> m := MultiplicationForMorphisms( p1, p2 ); ℝ^6 -> ℝ^3 gap> Display( m ); ℝ^6 -> ℝ^3 ‣ x1 * x4 ‣ x2 * x5 ‣ x3 * x6 gap> h := MorphismConstructor( Para, Para.(3), [ R3, m ], Para.(3) );; gap> Display( h ); ℝ^3 -> ℝ^3 defined by: Underlying Object: ----------------- ℝ^3 Underlying Morphism: ------------------- ℝ^6 -> ℝ^3 ‣ x1 * x4 ‣ x2 * x5 ‣ x3 * x6 gap> dummy_input := CreateContextualVariables( > [ "w1", "w2", "w3", "z1", "z2", "z3" ] ); [ w1, w2, w3, z1, z2, z3 ] gap> Display( h : dummy_input := dummy_input ); ℝ^3 -> ℝ^3 defined by: Underlying Object: ----------------- ℝ^3 Underlying Morphism: ------------------- ℝ^6 -> ℝ^3 ‣ w1 * z1 ‣ w2 * z2 ‣ w3 * z3 gap> r := DirectProductFunctorial( Smooth, > [ Smooth.Sqrt, Smooth.Log, Smooth.Exp ] );; gap> Display( r ); ℝ^3 -> ℝ^3 ‣ Sqrt( x1 ) ‣ Log( x2 ) ‣ Exp( x3 ) gap> g := ReparametriseMorphism( h, r );; gap> Display( g : dummy_input := dummy_input ); ℝ^3 -> ℝ^3 defined by: Underlying Object: ----------------- ℝ^3 Underlying Morphism: ------------------- ℝ^6 -> ℝ^3 ‣ Sqrt( w1 ) * z1 ‣ Log( w2 ) * z2 ‣ Exp( w3 ) * z3
Let us illustrate the natural embedding functor from the category of smooth maps into the category of parametrised morphisms.
gap> Smooth := SkeletalCategoryOfSmoothMaps( ); SkeletalSmoothMaps gap> Para := CategoryOfParametrisedMorphisms( Smooth ); CategoryOfParametrisedMorphisms( SkeletalSmoothMaps ) gap> iota := NaturalEmbedding( Smooth, Para ); Natural embedding into category of parametrised morphisms gap> ApplyFunctor( iota, Smooth.( 1 ) ); ℝ^1 gap> psi := ApplyFunctor( iota, Smooth.Sum( 2 ) ); ℝ^2 -> ℝ^1 defined by: Underlying Object: ----------------- ℝ^0 Underlying Morphism: ------------------- ℝ^2 -> ℝ^1 gap> Display( psi ); ℝ^2 -> ℝ^1 defined by: Underlying Object: ----------------- ℝ^0 Underlying Morphism: ------------------- ℝ^2 -> ℝ^1 ‣ x1 + x2
‣ IsCategoryOfParametrisedMorphisms( arg ) | ( filter ) |
Returns: true or false
The GAP category of a category of parametrised morphisms.
‣ IsObjectInCategoryOfParametrisedMorphisms( arg ) | ( filter ) |
Returns: true or false
The GAP category of objects in a category of parametrised morphisms.
‣ IsMorphismInCategoryOfParametrisedMorphisms( arg ) | ( filter ) |
Returns: true or false
The GAP category of morphisms in a category of parametrised morphisms.
generated by GAPDoc2HTML