Let \(C\) be a cartesian category. The category of lenses \(\mathbf{Lenses}(C)\) has:
Objects: pairs of objects \((S_1, S_2)\) in \(C\).
Morphisms: a morphism from \(f:(S_1, S_2) \to (T_1, T_2)\) is given by a pair of morphisms in \(C\):
A "get" (or "forward") morphism \(f_g: S_1 \to T_1\) in \(C\).
A "put" (or "backward") morphism \(f_p: S_1 \times T_2 \to S_2\) in \(C\).
Composition: given lenses \(f: (S_1, S_2) \to (T_1, T_2)\) and \(h: (T_1, T_2) \to (U_1, U_2)\), their composition \(f \cdot h: (S_1, S_2) \to (U_1, U_2)\) is defined by:
Get morphism: \(f_g \cdot h_g: S_1 \to U_1\).
Put morphism: \(\langle \pi_{S_1}, (f_g \times U_2)\cdot h_p\rangle \cdot f_p:S_1 \times U_2 \to S_2\), where \(\langle -, -\rangle\) denotes the universal morphism into the product object.
Identity: the identity lens on \((S_1, S_2)\) has:
Get morphism: \(id_{S_1}: S_1 \to S_1\).
Put morphism: the projection morphism \(\pi_{S_2}: S_1 \times S_2 \to S_2\).
‣ CategoryOfLenses( C ) | ( operation ) |
Returns: a category
Construct the category of lenses over the category C. A lens is a pair of morphisms: a "get" morphism and a "put" morphism, which together model bidirectional data flow used in automatic differentiation.
‣ ObjectConstructor( Lens, obj_list ) | ( operation ) |
Returns: an object in the category of lenses
Construct an object in the category of lenses given a pair of objects.
‣ MorphismConstructor( Lens, source_obj, morphism_list, target_obj ) | ( operation ) |
Returns: a morphism in the category of lenses
Construct a morphism in the category of lenses given a pair of morphisms: a "get" morphism and a "put" morphism.
‣ UnderlyingPairOfObjects( obj ) | ( attribute ) |
Returns: a pair of objects
Returns the underlying pair of objects \((S_1, S_2)\) for an object in the category of lenses. This operation is a synonym for ObjectDatum.
‣ UnderlyingPairOfMorphisms( f ) | ( attribute ) |
Returns: a pair of morphisms
Returns the underlying pair of morphisms for a morphism in the category of lenses. This operation is a synonym for MorphismDatum.
‣ GetMorphism( f ) | ( attribute ) |
Returns: a morphism
Returns the "get" morphism of a lens. For a lens \(f: (S_1, S_2) \to (T_1, T_2)\), the output is the get morphism \(S_1 \to T_1\).
‣ PutMorphism( f ) | ( attribute ) |
Returns: a morphism
Returns the "put" morphism of a lens. For a lens \(f: (S_1, S_2) \to (T_1, T_2)\), the output is the put morphism \(S_1 \times T_2 \to S_2\).
‣ ReverseDifferentialLensFunctor( Smooth, Lenses ) | ( operation ) |
Returns: a functor
Embedding functor from the category Smooth of smooth maps into its category of lenses Lenses. An object \(\mathbb{R}^m\) in Smooth is mapped to the lens \((\mathbb{R}^m, \mathbb{R}^m)\), and a morphism \(f: \mathbb{R}^m \to \mathbb{R}^n\) is mapped to the lens with get morphism \(f: \mathbb{R}^m \to \mathbb{R}^n\) and put morphism \(Rf: \mathbb{R}^m \times \mathbb{R}^n \to \mathbb{R}^m\) given by \((u,v) \mapsto vJ_f(u)\), where \(J_f(u) \in \mathbb{R}^{n \times m}\) is the Jacobian matrix of \(f\) evaluated at \(u \in \mathbb{R}^m\). This functor might be defined for any cartesian reverse-differentiable category, but the category of smooth maps is the only such category currently implemented in this package. For example, if \(f: \mathbb{R}^2 \to \mathbb{R}\) is defined by \(f(x_1, x_2) = (x_1^3 + x_2^2)\), the the corresponding \(Rf:\mathbb{R}^2 \times \mathbb{R} \to \mathbb{R}^2\) is given by \(Rf((x_1, x_2), y) = y(3x_1^2, 2x_2) = (3x_1^2y, 2x_2y)\).
gap> Smooth := SkeletalCategoryOfSmoothMaps( ); SkeletalSmoothMaps gap> Lenses := CategoryOfLenses( Smooth ); CategoryOfLenses( SkeletalSmoothMaps ) gap> R := ReverseDifferentialLensFunctor( Smooth, Lenses ); Embedding functor into category of lenses gap> SourceOfFunctor( R ); SkeletalSmoothMaps gap> RangeOfFunctor( R ); CategoryOfLenses( SkeletalSmoothMaps ) gap> f := DirectProductFunctorial( [ Smooth.Power(3), Smooth.Power(2) ] ); ℝ^2 -> ℝ^2 gap> Display( f ); ℝ^2 -> ℝ^2 ‣ x1 ^ 3 ‣ x2 ^ 2 gap> f := PreCompose( f, Smooth.Sum(2) ); ℝ^2 -> ℝ^1 gap> Display( f ); ℝ^2 -> ℝ^1 ‣ x1 ^ 3 + x2 ^ 2 gap> Rf := ApplyFunctor( R, f );; gap> Display( Rf ); (ℝ^2, ℝ^2) -> (ℝ^1, ℝ^1) defined by: Get Morphism: ------------ ℝ^2 -> ℝ^1 ‣ x1 ^ 3 + x2 ^ 2 Put Morphism: ------------ ℝ^3 -> ℝ^2 ‣ x3 * (1 * (3 * x1 ^ 2) + 0) ‣ x3 * (0 + 1 * (2 * x2 ^ 1))
gap> Smooth := SkeletalCategoryOfSmoothMaps( ); SkeletalSmoothMaps gap> Lenses := CategoryOfLenses( Smooth ); CategoryOfLenses( SkeletalSmoothMaps ) gap> optimizer := Lenses.GradientDescentOptimizer( :learning_rate := 0.01 )( 2 ); (ℝ^2, ℝ^2) -> (ℝ^2, ℝ^2) defined by: Get Morphism: ------------ ℝ^2 -> ℝ^2 Put Morphism: ------------ ℝ^4 -> ℝ^2 gap> dummy_input := [ "theta_1", "theta_2", "g1", "g2" ];; gap> dummy_input := CreateContextualVariables( dummy_input ); [ theta_1, theta_2, g1, g2 ] gap> Display( optimizer : dummy_input := dummy_input ); (ℝ^2, ℝ^2) -> (ℝ^2, ℝ^2) defined by: Get Morphism: ------------ ℝ^2 -> ℝ^2 ‣ theta_1 ‣ theta_2 Put Morphism: ------------ ℝ^4 -> ℝ^2 ‣ theta_1 + 0.01 * g1 ‣ theta_2 + 0.01 * g2 gap> optimizer := Lenses.GradientDescentWithMomentumOptimizer( > :learning_rate := 0.01, momentum := 0.9 )( 2 ); (ℝ^4, ℝ^4) -> (ℝ^2, ℝ^2) defined by: Get Morphism: ------------ ℝ^4 -> ℝ^2 Put Morphism: ------------ ℝ^6 -> ℝ^4 gap> dummy_input := [ "s1", "s2", "theta_1", "theta_2", "g1", "g2" ];; gap> dummy_input := CreateContextualVariables( dummy_input ); [ s1, s2, theta_1, theta_2, g1, g2 ] gap> Display( optimizer : dummy_input := dummy_input ); (ℝ^4, ℝ^4) -> (ℝ^2, ℝ^2) defined by: Get Morphism: ------------ ℝ^4 -> ℝ^2 ‣ theta_1 ‣ theta_2 Put Morphism: ------------ ℝ^6 -> ℝ^4 ‣ 0.9 * s1 + 0.01 * g1 ‣ 0.9 * s2 + 0.01 * g2 ‣ theta_1 + (0.9 * s1 + 0.01 * g1) ‣ theta_2 + (0.9 * s2 + 0.01 * g2) gap> optimizer := Lenses.AdagradOptimizer( :learning_rate := 0.01 )( 2 ); (ℝ^4, ℝ^4) -> (ℝ^2, ℝ^2) defined by: Get Morphism: ------------ ℝ^4 -> ℝ^2 Put Morphism: ------------ ℝ^6 -> ℝ^4 gap> Display( optimizer : dummy_input := dummy_input ); (ℝ^4, ℝ^4) -> (ℝ^2, ℝ^2) defined by: Get Morphism: ------------ ℝ^4 -> ℝ^2 ‣ theta_1 ‣ theta_2 Put Morphism: ------------ ℝ^6 -> ℝ^4 ‣ s1 + g1 ^ 2 ‣ s2 + g2 ^ 2 ‣ theta_1 + 0.01 * g1 / (1.e-07 + Sqrt( s1 + g1 ^ 2 )) ‣ theta_2 + 0.01 * g2 / (1.e-07 + Sqrt( s2 + g2 ^ 2 )) gap> optimizer := Lenses.AdamOptimizer( > :learning_rate := 0.01, beta_1 := 0.9, beta_2 := 0.999 )( 2 ); (ℝ^7, ℝ^7) -> (ℝ^2, ℝ^2) defined by: Get Morphism: ------------ ℝ^7 -> ℝ^2 Put Morphism: ------------ ℝ^9 -> ℝ^7 gap> dummy_input := > [ "t", "m1", "m2", "v1", "v2", "theta_1", "theta_2", "g1", "g2" ];; gap> dummy_input := CreateContextualVariables( dummy_input ); [ t, m1, m2, v1, v2, theta_1, theta_2, g1, g2 ] gap> Display( optimizer : dummy_input := dummy_input ); (ℝ^7, ℝ^7) -> (ℝ^2, ℝ^2) defined by: Get Morphism: ------------ ℝ^7 -> ℝ^2 ‣ theta_1 ‣ theta_2 Put Morphism: ------------ ℝ^9 -> ℝ^7 ‣ t + 1 ‣ 0.9 * m1 + 0.1 * g1 ‣ 0.9 * m2 + 0.1 * g2 ‣ 0.999 * v1 + 0.001 * g1 ^ 2 ‣ 0.999 * v2 + 0.001 * g2 ^ 2 ‣ theta_1 + 0.01 / (1 - 0.999 ^ t) * ((0.9 * m1 + 0.1 * g1) / (1.e-07 + Sqrt( (0.999 * v1 + 0.001 * g1 ^ 2) / (1 - 0.999 ^ t) ))) ‣ theta_2 + 0.01 / (1 - 0.999 ^ t) * ((0.9 * m2 + 0.1 * g2) / (1.e-07 + Sqrt( (0.999 * v2 + 0.001 * g2 ^ 2) / (1 - 0.999 ^ t) )))
The following CAP operations are supported:
AssociatorLeftToRight (MonoidalCategories: AssociatorLeftToRight for IsCapCategoryObject, IsCapCategoryObject, IsCapCategoryObject)
AssociatorLeftToRightWithGivenTensorProducts (MonoidalCategories: AssociatorLeftToRightWithGivenTensorProducts for IsCapCategoryObject, IsCapCategoryObject, IsCapCategoryObject, IsCapCategoryObject, IsCapCategoryObject)
AssociatorRightToLeft (MonoidalCategories: AssociatorRightToLeft for IsCapCategoryObject, IsCapCategoryObject, IsCapCategoryObject)
AssociatorRightToLeftWithGivenTensorProducts (MonoidalCategories: AssociatorRightToLeftWithGivenTensorProducts for IsCapCategoryObject, IsCapCategoryObject, IsCapCategoryObject, IsCapCategoryObject, IsCapCategoryObject)
Braiding (MonoidalCategories: Braiding for IsCapCategoryObject, IsCapCategoryObject)
BraidingInverse (MonoidalCategories: BraidingInverse for IsCapCategoryObject, IsCapCategoryObject)
BraidingInverseWithGivenTensorProducts (MonoidalCategories: BraidingInverseWithGivenTensorProducts for IsCapCategoryObject, IsCapCategoryObject, IsCapCategoryObject, IsCapCategoryObject)
BraidingWithGivenTensorProducts (MonoidalCategories: BraidingWithGivenTensorProducts for IsCapCategoryObject, IsCapCategoryObject, IsCapCategoryObject, IsCapCategoryObject)
IdentityMorphism (CAP: IdentityMorphism for IsCapCategoryObject)
IsEndomorphism (CAP: IsEndomorphism for IsCapCategoryMorphism)
IsEqualForObjects (CAP: IsEqualForObjects for IsCapCategoryObject, IsCapCategoryObject)
IsWellDefinedForMorphisms (CAP: IsWellDefinedForMorphisms for IsCapCategoryMorphism)
IsWellDefinedForMorphismsWithGivenSourceAndRange (CAP: IsWellDefinedForMorphismsWithGivenSourceAndRange for IsCapCategoryObject, IsCapCategoryMorphism, IsCapCategoryObject)
IsWellDefinedForObjects (CAP: IsWellDefinedForObjects for IsCapCategoryObject)
LeftUnitor (MonoidalCategories: LeftUnitor for IsCapCategoryObject)
LeftUnitorInverse (MonoidalCategories: LeftUnitorInverse for IsCapCategoryObject)
LeftUnitorInverseWithGivenTensorProduct (MonoidalCategories: LeftUnitorInverseWithGivenTensorProduct for IsCapCategoryObject, IsCapCategoryObject)
LeftUnitorWithGivenTensorProduct (MonoidalCategories: LeftUnitorWithGivenTensorProduct for IsCapCategoryObject, 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)
RandomMorphismWithFixedSourceAndRangeByInteger (CAP: RandomMorphismWithFixedSourceAndRangeByInteger for IsCapCategoryObject, IsCapCategoryObject, IsInt)
RightUnitor (MonoidalCategories: RightUnitor for IsCapCategoryObject)
RightUnitorInverse (MonoidalCategories: RightUnitorInverse for IsCapCategoryObject)
RightUnitorInverseWithGivenTensorProduct (MonoidalCategories: RightUnitorInverseWithGivenTensorProduct for IsCapCategoryObject, IsCapCategoryObject)
RightUnitorWithGivenTensorProduct (MonoidalCategories: RightUnitorWithGivenTensorProduct for IsCapCategoryObject, IsCapCategoryObject)
SimplifyMorphism (CAP: SimplifyMorphism for IsCapCategoryMorphism, IsObject)
TensorProductOnMorphisms (MonoidalCategories: TensorProductOnMorphisms for IsCapCategoryMorphism, IsCapCategoryMorphism)
TensorProductOnMorphismsWithGivenTensorProducts (MonoidalCategories: TensorProductOnMorphismsWithGivenTensorProducts for IsCapCategoryObject, IsCapCategoryMorphism, IsCapCategoryMorphism, IsCapCategoryObject)
TensorProductOnObjects (MonoidalCategories: TensorProductOnObjects for IsCapCategoryObject, IsCapCategoryObject)
TensorUnit (MonoidalCategories: TensorUnit for IsCapCategory)
gap> Smooth := SkeletalCategoryOfSmoothMaps( ); SkeletalSmoothMaps gap> Lenses := CategoryOfLenses( Smooth ); CategoryOfLenses( SkeletalSmoothMaps ) gap> A := ObjectConstructor( Lenses, [ Smooth.( 1 ), Smooth.( 2 ) ] ); (ℝ^1, ℝ^2) gap> IsWellDefined( A ); true gap> CapCategory( A ); CategoryOfLenses( SkeletalSmoothMaps ) gap> A_datum := ObjectDatum( A ); [ ℝ^1, ℝ^2 ] gap> CapCategory( A_datum[1] ); SkeletalSmoothMaps gap> B := ObjectConstructor( Lenses, [ Smooth.( 3 ), Smooth.( 4 ) ] ); (ℝ^3, ℝ^4) gap> get := RandomMorphism( Smooth.( 1 ), Smooth.( 3 ), 5 ); ℝ^1 -> ℝ^3 gap> put := RandomMorphism( Smooth.( 1 + 4 ), Smooth.( 2 ), 5 ); ℝ^5 -> ℝ^2 gap> f := MorphismConstructor( Lenses, A, [ get, put ], B ); (ℝ^1, ℝ^2) -> (ℝ^3, ℝ^4) defined by: Get Morphism: ------------ ℝ^1 -> ℝ^3 Put Morphism: ------------ ℝ^5 -> ℝ^2 gap> MorphismDatum( f ); [ ℝ^1 -> ℝ^3, ℝ^5 -> ℝ^2 ] gap> IsWellDefined( f ); true gap> Display( f ); (ℝ^1, ℝ^2) -> (ℝ^3, ℝ^4) defined by: Get Morphism: ------------ ℝ^1 -> ℝ^3 ‣ 0.766 * x1 ^ 4 + 0.234 ‣ 1. * x1 ^ 4 + 0.388 ‣ 0.459 * x1 ^ 4 + 0.278 Put Morphism: ------------ ℝ^5 -> ℝ^2 ‣ 0.677 * x1 ^ 5 + 0.19 * x2 ^ 4 + 0.659 * x3 ^ 4 + 0.859 * x4 ^ 5 + 0.28 * x5 ^ 1 + 0.216 ‣ 0.37 * x1 ^ 5 + 0.571 * x2 ^ 4 + 0.835 * x3 ^ 4 + 0.773 * x4 ^ 5 + 0.469 * x5 ^ 1 + 0.159 gap> id_A := IdentityMorphism( Lenses, A ); (ℝ^1, ℝ^2) -> (ℝ^1, ℝ^2) defined by: Get Morphism: ------------ ℝ^1 -> ℝ^1 Put Morphism: ------------ ℝ^3 -> ℝ^2 gap> Display( id_A ); (ℝ^1, ℝ^2) -> (ℝ^1, ℝ^2) defined by: Get Morphism: ------------ ℝ^1 -> ℝ^1 ‣ x1 Put Morphism: ------------ ℝ^3 -> ℝ^2 ‣ x2 ‣ x3 gap> IsCongruentForMorphisms( PreCompose( id_A, f ), f ); true gap> TensorUnit( Lenses ); (ℝ^0, ℝ^0) gap> TensorProductOnObjects( A, B ); (ℝ^4, ℝ^6) gap> f1 := RandomMorphism( A, B, 5 ); (ℝ^1, ℝ^2) -> (ℝ^3, ℝ^4) defined by: Get Morphism: ------------ ℝ^1 -> ℝ^3 Put Morphism: ------------ ℝ^5 -> ℝ^2 gap> f2 := RandomMorphism( A, B, 5 ); (ℝ^1, ℝ^2) -> (ℝ^3, ℝ^4) defined by: Get Morphism: ------------ ℝ^1 -> ℝ^3 Put Morphism: ------------ ℝ^5 -> ℝ^2 gap> f3 := RandomMorphism( A, B, 5 ); (ℝ^1, ℝ^2) -> (ℝ^3, ℝ^4) defined by: Get Morphism: ------------ ℝ^1 -> ℝ^3 Put Morphism: ------------ ℝ^5 -> ℝ^2 gap> f1_f2 := TensorProductOnMorphisms( Lenses, f1, f2 ); (ℝ^2, ℝ^4) -> (ℝ^6, ℝ^8) defined by: Get Morphism: ------------ ℝ^2 -> ℝ^6 Put Morphism: ------------ ℝ^10 -> ℝ^4 gap> f2_f3 := TensorProductOnMorphisms( Lenses, f2, f3 ); (ℝ^2, ℝ^4) -> (ℝ^6, ℝ^8) defined by: Get Morphism: ------------ ℝ^2 -> ℝ^6 Put Morphism: ------------ ℝ^10 -> ℝ^4 gap> t1 := TensorProductOnMorphisms( Lenses, f1_f2, f3 ); (ℝ^3, ℝ^6) -> (ℝ^9, ℝ^12) defined by: Get Morphism: ------------ ℝ^3 -> ℝ^9 Put Morphism: ------------ ℝ^15 -> ℝ^6 gap> t2 := TensorProductOnMorphisms( Lenses, f1, f2_f3 ); (ℝ^3, ℝ^6) -> (ℝ^9, ℝ^12) defined by: Get Morphism: ------------ ℝ^3 -> ℝ^9 Put Morphism: ------------ ℝ^15 -> ℝ^6 gap> IsCongruentForMorphisms( t1, t2 ); true gap> Display( Braiding( A, B ) ); (ℝ^4, ℝ^6) -> (ℝ^4, ℝ^6) defined by: Get Morphism: ------------ ℝ^4 -> ℝ^4 ‣ x2 ‣ x3 ‣ x4 ‣ x1 Put Morphism: ------------ ℝ^10 -> ℝ^6 ‣ x9 ‣ x10 ‣ x5 ‣ x6 ‣ x7 ‣ x8 gap> Display( PreCompose( Braiding( A, B ), BraidingInverse( A, B ) ) ); (ℝ^4, ℝ^6) -> (ℝ^4, ℝ^6) defined by: Get Morphism: ------------ ℝ^4 -> ℝ^4 ‣ x1 ‣ x2 ‣ x3 ‣ x4 Put Morphism: ------------ ℝ^10 -> ℝ^6 ‣ x5 ‣ x6 ‣ x7 ‣ x8 ‣ x9 ‣ x10
‣ IsCategoryOfLenses( arg ) | ( filter ) |
Returns: true or false
The GAP category of a category of lenses.
‣ IsObjectInCategoryOfLenses( arg ) | ( filter ) |
Returns: true or false
The GAP category of objects in a category of lenses.
‣ IsMorphismInCategoryOfLenses( arg ) | ( filter ) |
Returns: true or false
The GAP category of morphisms in a category of lenses.
generated by GAPDoc2HTML