Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 Ind
 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 

5 Category of Parametrised Morphisms
 5.1 Definition
 5.2 Constructors
 5.3 Attributes
 5.4 Operations
 5.5 Available Parametrised Morphisms
 5.6 Supported CAP Operations
 5.7 Examples
 5.8 GAP Categories

5 Category of Parametrised Morphisms

5.1 Definition

Let \((C, \otimes, I)\) be a strict symmetric monoidal category. The category \(P(C)\) of parametrized morphisms is given by the following data:

their composition \(f \cdot g \colon A \to C\) is given by the pair

the pair \(\mathrm{id}_A = \left( I, (\mathrm{id}_A)_I := \mathrm{id}_A \in \mathbf{Hom}_C(A, A)) \right)\).

5.2 Constructors

5.2-1 CategoryOfParametrisedMorphisms
‣ CategoryOfParametrisedMorphisms( C )( operation )

Returns: a category

Construct the category of parametrised morphisms over the category C.

5.2-2 ObjectConstrutor
‣ ObjectConstrutor( Para, A )( operation )

Returns: an object in the category of parametrised morphisms

Construct an object in the category of parametrised morphisms.

5.2-3 MorphismConstructor
‣ 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\).

5.3 Attributes

5.3-1 UnderlyingCategory
‣ UnderlyingCategory( Para )( attribute )

Returns: a category

Returns the underlying category of a category of parametrised morphisms.

5.3-2 UnderlyingObject
‣ UnderlyingObject( A )( attribute )

Returns: an object in the underlying category

Returns the underlying object for an object in the category of parametrised morphisms.

5.3-3 UnderlyingObject
‣ UnderlyingObject( f )( attribute )

Returns: an object in the underlying category

Returns the parameter object (underlying object) of a parametrised morphism.

5.3-4 UnderlyingMorphism
‣ 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)\).

5.4 Operations

5.4-1 ReparametriseMorphism
‣ 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\).

5.4-2 FlipParameterAndSource
‣ 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\).

5.4-3 Batchify
‣ 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:

5.4-4 NaturalEmbedding
‣ 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.

5.4-5 EmbeddingIntoCategoryOfParametrisedMorphisms
‣ EmbeddingIntoCategoryOfParametrisedMorphisms( Para, Para_Lenses )( operation )

Returns: a functor

Embedding functor from category of parametrised morphisms Para into another category of parametrised morphisms Para_Lenses.

5.5 Available Parametrised Morphisms

All available smooth maps can be lifted to parametrised morphisms in the category of parametrised morphisms by using one of the following two methods:

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 ]

5.6 Supported CAP Operations

5.6-1 Category of Parametrised Smooth Maps

The following CAP operations are supported:

5.6-2 Generate Documentation
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"
> );

5.7 Examples

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

5.8 GAP Categories

5.8-1 IsCategoryOfParametrisedMorphisms
‣ IsCategoryOfParametrisedMorphisms( arg )( filter )

Returns: true or false

The GAP category of a category of parametrised morphisms.

5.8-2 IsObjectInCategoryOfParametrisedMorphisms
‣ IsObjectInCategoryOfParametrisedMorphisms( arg )( filter )

Returns: true or false

The GAP category of objects in a category of parametrised morphisms.

5.8-3 IsMorphismInCategoryOfParametrisedMorphisms
‣ IsMorphismInCategoryOfParametrisedMorphisms( arg )( filter )

Returns: true or false

The GAP category of morphisms in a category of parametrised morphisms.

 [Top of Book]  [Contents]   [Previous Chapter]   [Next Chapter] 
Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 Ind

generated by GAPDoc2HTML