gap> Smooth := CategoryOfSkeletalSmoothMaps( ); 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 gap> R := EmbeddingIntoCategoryOfLenses( Smooth, Lenses ); Embedding functor into category of lenses gap> SourceOfFunctor( R ); SkeletalSmoothMaps gap> RangeOfFunctor( R ); CategoryOfLenses( SkeletalSmoothMaps ) gap> f := Smooth.Softmax( 2 ); ℝ^2 -> ℝ^2 gap> Display( f ); ℝ^2 -> ℝ^2 ‣ Exp( x1 ) / (Exp( x1 ) + Exp( x2 )) ‣ Exp( x2 ) / (Exp( x1 ) + Exp( x2 )) gap> Rf := ApplyFunctor( R, f ); (ℝ^2, ℝ^2) -> (ℝ^2, ℝ^2) defined by: Get Morphism: ---------- ℝ^2 -> ℝ^2 Put Morphism: ---------- ℝ^4 -> ℝ^2 gap> Display( Rf ); (ℝ^2, ℝ^2) -> (ℝ^2, ℝ^2) defined by: Get Morphism: ------------ ℝ^2 -> ℝ^2 ‣ Exp( x1 ) / (Exp( x1 ) + Exp( x2 )) ‣ Exp( x2 ) / (Exp( x1 ) + Exp( x2 )) Put Morphism: ------------ ℝ^4 -> ℝ^2 ‣ x3 * ((Exp( x1 ) + Exp( x2 ) - Exp( x1 )) * (Exp( x1 ) / (Exp( x1 ) + Exp( x2 )) ^ 2)) + x4 * ((- Exp( x1 )) * (Exp( x2 ) / (Exp( x1 ) + Exp( x2 )) ^ 2)) ‣ x3 * ((- Exp( x2 )) * (Exp( x1 ) / (Exp( x1 ) + Exp( x2 )) ^ 2)) + x4 * ((Exp( x1 ) + Exp( x2 ) - Exp( x2 )) * (Exp( x2 ) / (Exp( x1 ) + Exp( x2 )) ^ 2)) gap> Display( Lenses.GradientDescentOptimizer( :learning_rate := 0.01 )( 2 ) ); (ℝ^2, ℝ^2) -> (ℝ^2, ℝ^2) defined by: Get Morphism: ------------ ℝ^2 -> ℝ^2 ‣ x1 ‣ x2 Put Morphism: ------------ ℝ^4 -> ℝ^2 ‣ x1 + 0.01 * x3 ‣ x2 + 0.01 * x4 gap> Display( Lenses.GradientDescentWithMomentumOptimizer( > :learning_rate := 0.01, momentum := 0.9 )( 2 ) ); (ℝ^4, ℝ^4) -> (ℝ^2, ℝ^2) defined by: Get Morphism: ------------ ℝ^4 -> ℝ^2 ‣ x3 ‣ x4 Put Morphism: ------------ ℝ^6 -> ℝ^4 ‣ 0.9 * x1 + 0.01 * x5 ‣ 0.9 * x2 + 0.01 * x6 ‣ x3 + (0.9 * x1 + 0.01 * x5) ‣ x4 + (0.9 * x2 + 0.01 * x6) gap> Display( Lenses.AdagradOptimizer( :learning_rate := 0.01 )( 2 ) ); (ℝ^4, ℝ^4) -> (ℝ^2, ℝ^2) defined by: Get Morphism: ------------ ℝ^4 -> ℝ^2 ‣ x3 ‣ x4 Put Morphism: ------------ ℝ^6 -> ℝ^4 ‣ x1 + x5 ^ 2 ‣ x2 + x6 ^ 2 ‣ x3 + 0.01 * x5 / (1.e-07 + Sqrt( (x1 + x5 ^ 2) )) ‣ x4 + 0.01 * x6 / (1.e-07 + Sqrt( (x2 + x6 ^ 2) )) gap> Display( 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 ‣ x6 ‣ x7 Put Morphism: ------------ ℝ^9 -> ℝ^7 ‣ x1 + 1 ‣ 0.9 * x2 + 0.1 * x8 ‣ 0.9 * x3 + 0.1 * x9 ‣ 0.999 * x4 + 0.001 * x8 ^ 2 ‣ 0.999 * x5 + 0.001 * x9 ^ 2 ‣ x6 + 0.01 / (1 - 0.999 ^ x1) * ((0.9 * x2 + 0.1 * x8) / (1.e-07 + Sqrt( (0.999 * x4 + 0.001 * x8 ^ 2) / (1 - 0.999 ^ x1) ))) ‣ x7 + 0.01 / (1 - 0.999 ^ x1) * ((0.9 * x3 + 0.1 * x9) / (1.e-07 + Sqrt( (0.999 * x5 + 0.001 * x9 ^ 2) / (1 - 0.999 ^ x1) )))
gap> Smooth := CategoryOfSkeletalSmoothMaps( ); SkeletalSmoothMaps gap> Para := CategoryOfParametrisedMorphisms( Smooth ); CategoryOfParametrisedMorphisms( SkeletalSmoothMaps ) gap> R1 := Smooth.( 1 ); ℝ^1 gap> R2 := Smooth.( 2 ); ℝ^2 gap> R3 := Smooth.( 3 ); ℝ^3 gap> R1 / Para; ℝ^1 gap> Para.( 1 ); ℝ^1 gap> IsEqualForObjects( Para.( 1 ), R1 / Para ); true gap> f := Smooth.Softmax( 3 ); ℝ^3 -> ℝ^3 gap> f := MorphismConstructor( Para, R1 / Para, [ R2, f ], R3 / Para ); ℝ^1 -> ℝ^3 defined by: Underlying Object: ----------------- ℝ^2 Underlying Morphism: ------------------- ℝ^3 -> ℝ^3 gap> Display( f ); ℝ^1 -> ℝ^3 defined by: Underlying Object: ----------------- ℝ^2 Underlying Morphism: ------------------- ℝ^3 -> ℝ^3 ‣ Exp( x1 ) / (Exp( x1 ) + Exp( x2 ) + Exp( x3 )) ‣ Exp( x2 ) / (Exp( x1 ) + Exp( x2 ) + Exp( x3 )) ‣ Exp( x3 ) / (Exp( x1 ) + Exp( x2 ) + Exp( x3 )) gap> IsWellDefined( f ); true gap> r := DirectProductFunctorial( Smooth, [ Smooth.Sqrt, Smooth.Cos ] ); ℝ^2 -> ℝ^2 gap> Display( r ); ℝ^2 -> ℝ^2 ‣ Sqrt( x1 ) ‣ Cos( x2 ) gap> g := ReparametriseMorphism( f, r ); ℝ^1 -> ℝ^3 defined by: Underlying Object: ----------------- ℝ^2 Underlying Morphism: ------------------- ℝ^3 -> ℝ^3 gap> Display( g ); ℝ^1 -> ℝ^3 defined by: Underlying Object: ----------------- ℝ^2 Underlying Morphism: ------------------- ℝ^3 -> ℝ^3 ‣ Exp( Sqrt( x1 ) ) / (Exp( Sqrt( x1 ) ) + Exp( Cos( x2 ) ) + Exp( x3 )) ‣ Exp( Cos( x2 ) ) / (Exp( Sqrt( x1 ) ) + Exp( Cos( x2 ) ) + Exp( x3 )) ‣ Exp( x3 ) / (Exp( Sqrt( x1 ) ) + Exp( Cos( x2 ) ) + Exp( x3 )) gap> l := Para.AffineTransformation( 3, 2 ); ℝ^3 -> ℝ^2 defined by: Underlying Object: ----------------- ℝ^8 Underlying Morphism: ------------------- ℝ^11 -> ℝ^2 gap> h := PreCompose( g, l ); ℝ^1 -> ℝ^2 defined by: Underlying Object: ----------------- ℝ^10 Underlying Morphism: ------------------- ℝ^11 -> ℝ^2 gap> Display( h ); ℝ^1 -> ℝ^2 defined by: Underlying Object: ----------------- ℝ^10 Underlying Morphism: ------------------- ℝ^11 -> ℝ^2 ‣ x1 * (Exp( Sqrt( x9 ) ) / (Exp( Sqrt( x9 ) ) + Exp( Cos( x10 ) ) + Exp( x11 ))) + x2 * (Exp( Cos( x10 ) ) / (Exp( Sqrt( x9 ) ) + Exp( Cos( x10 ) ) + Exp( x11 ))) + x3 * (Exp( x11 ) / (Exp( Sqrt( x9 ) ) + Exp( Cos( x10 ) ) + Exp( x11 ))) + x4 ‣ x5 * (Exp( Sqrt( x9 ) ) / (Exp( Sqrt( x9 ) ) + Exp( Cos( x10 ) ) + Exp( x11 ))) + x6 * (Exp( Cos( x10 ) ) / (Exp( Sqrt( x9 ) ) + Exp( Cos( x10 ) ) + Exp( x11 ))) + x7 * (Exp( x11 ) / (Exp( Sqrt( x9 ) ) + Exp( Cos( x10 ) ) + Exp( x11 ))) + x8 gap> constants := [ 0.91, 0.24, 0.88, 0.59, 0.67, 0.05, 0.85, 0.31, 0.76, 0.04 ];; gap> r := Smooth.Constant( constants ); ℝ^0 -> ℝ^10 gap> t := ReparametriseMorphism( h, r ); ℝ^1 -> ℝ^2 defined by: Underlying Object: ----------------- ℝ^0 Underlying Morphism: ------------------- ℝ^1 -> ℝ^2 gap> Display( t ); ℝ^1 -> ℝ^2 defined by: Underlying Object: ----------------- ℝ^0 Underlying Morphism: ------------------- ℝ^1 -> ℝ^2 ‣ 0.91 * (2.39116 / (5.10727 + Exp( x1 ))) + 0.24 * (2.71611 / (5.10727 + Exp( x1 ))) + 0.88 * (Exp( x1 ) / (5.10727 + Exp( x1 ))) + 0.59 ‣ 0.67 * (2.39116 / (5.10727 + Exp( x1 ))) + 0.05 * (2.71611 / (5.10727 + Exp( x1 ))) + 0.85 * (Exp( x1 ) / (5.10727 + Exp( x1 ))) + 0.31 gap> s := SimplifyMorphism( t, infinity ); ℝ^1 -> ℝ^2 defined by: Underlying Object: ----------------- ℝ^0 Underlying Morphism: ------------------- ℝ^1 -> ℝ^2 gap> Display( s ); ℝ^1 -> ℝ^2 defined by: Underlying Object: ----------------- ℝ^0 Underlying Morphism: ------------------- ℝ^1 -> ℝ^2 ‣ (1.47 * Exp( x1 ) + 5.84111) / (Exp( x1 ) + 5.10727) ‣ (1.16 * Exp( x1 ) + 3.32114) / (Exp( x1 ) + 5.10727) gap> iota := NaturalEmbeddingIntoCategoryOfParametrisedMorphisms( 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> Print( DisplayString( psi ) ); ℝ^2 -> ℝ^1 defined by: Underlying Object: ----------------- ℝ^0 Underlying Morphism: ------------------- ℝ^2 -> ℝ^1 ‣ x1 + x2
gap> Smooth := CategoryOfSkeletalSmoothMaps( ); SkeletalSmoothMaps gap> R2 := ObjectConstructor( Smooth, 2 ); ℝ^2 gap> R2 = Smooth.2; true gap> r := RandomMorphism( R2, R2, 3 ); ℝ^2 -> ℝ^2 gap> Display( r ); ℝ^2 -> ℝ^2 ‣ 0.766 * x1 ^ 1 + 0.234 * x2 ^ 2 + 1. ‣ 0.388 * x1 ^ 1 + 0.459 * x2 ^ 2 + 0.278 gap> f := MorphismConstructor( Smooth, > Smooth.2, > Pair( > x -> [ x[1] ^ 2 + Sin( x[2] ), Exp( x[1] ) + 3 * x[2] ], > x -> [ [ 2 * x[1], Cos( x[2] ) ], [ Exp( x[1] ), 3 ] ] ), > Smooth.2 ); ℝ^2 -> ℝ^2 gap> Display( f ); ℝ^2 -> ℝ^2 ‣ x1 ^ 2 + Sin( x2 ) ‣ Exp( x1 ) + 3 * x2 gap> dummy_input := ConvertToExpressions( [ "x1", "x2" ] ); [ x1, x2 ] gap> Map( f )( dummy_input ); [ x1 ^ 2 + Sin( x2 ), Exp( x1 ) + 3 * x2 ] gap> JacobianMatrix( f )( dummy_input ); [ [ 2 * x1, Cos( x2 ) ], [ Exp( x1 ), 3 ] ] gap> x := [ 0.2, 0.3 ]; [ 0.2, 0.3 ] gap> Map( f )( x ); [ 0.33552, 2.1214 ] gap> JacobianMatrix( f )( x ); [ [ 0.4, 0.955336 ], [ 1.2214, 3 ] ] gap> g := MorphismConstructor( Smooth, > Smooth.2, > Pair( > x -> [ 3 * x[1], Exp( x[2] ), x[1] ^ 3 + Log( x[2] ) ], > x -> [ [ 3, 0 ], > [ 0, Exp( x[2] ) ], > [ 3 * x[1] ^ 2, 1 / x[2] ] ] ), > Smooth.3 ); ℝ^2 -> ℝ^3 gap> Display( g ); ℝ^2 -> ℝ^3 ‣ 3 * x1 ‣ Exp( x2 ) ‣ x1 ^ 3 + Log( x2 ) gap> Map( g )( dummy_input ); [ 3 * x1, Exp( x2 ), x1 ^ 3 + Log( x2 ) ] gap> JacobianMatrix( g )( dummy_input ); [ [ 3, 0 ], [ 0, Exp( x2 ) ], [ 3 * x1 ^ 2, 1 / x2 ] ] gap> h := PostCompose( g, f ); ℝ^2 -> ℝ^3 gap> Display( h ); ℝ^2 -> ℝ^3 ‣ 3 * (x1 ^ 2 + Sin( x2 )) ‣ Exp( Exp( x1 ) + 3 * x2 ) ‣ (x1 ^ 2 + Sin( x2 )) ^ 3 + Log( (Exp( x1 ) + 3 * x2) ) gap> x; [ 0.2, 0.3 ] gap> Map( h )( x ); [ 1.00656, 8.34283, 0.789848 ] gap> Eval( h, x ); [ 1.00656, 8.34283, 0.789848 ] gap> Map( g )( Map( f )( x ) ); [ 1.00656, 8.34283, 0.789848 ] gap> JacobianMatrix( h )( x ); [ [ 1.2, 2.86601 ], [ 10.19, 25.0285 ], [ 0.710841, 1.7368 ] ] gap> EvalJacobianMatrix( h, x ); [ [ 1.2, 2.86601 ], [ 10.19, 25.0285 ], [ 0.710841, 1.7368 ] ] gap> JacobianMatrix( g )( Map( f )( x ) ) * JacobianMatrix( f )( x ); [ [ 1.2, 2.86601 ], [ 10.19, 25.0285 ], [ 0.710841, 1.7368 ] ] gap> IsCongruentForMorphisms( Smooth, f + f, 2 * f ); true gap> IsCongruentForMorphisms( Smooth, 2 * f - f, f ); true gap> s := SimplifyMorphism( h, infinity ); ℝ^2 -> ℝ^3 gap> Display( s ); ℝ^2 -> ℝ^3 ‣ 3 * x1 ^ 2 + 3 * Sin( x2 ) ‣ Exp( 3 * x2 + Exp( x1 ) ) ‣ (x1 ^ 2 + Sin( x2 )) ^ 3 + Log( (3 * x2 + Exp( x1 )) ) gap> R2 := Smooth.( 2 ); ℝ^2 gap> R3 := Smooth.( 3 ); ℝ^3 gap> DirectProduct( R2, R3 ); ℝ^5 gap> p1 := ProjectionInFactorOfDirectProduct( [ R2, R3 ], 1 ); ℝ^5 -> ℝ^2 gap> Display( p1 ); ℝ^5 -> ℝ^2 ‣ x1 ‣ x2 gap> p2 := ProjectionInFactorOfDirectProduct( [ R2, R3 ], 2 ); ℝ^5 -> ℝ^3 gap> Display( p2 ); ℝ^5 -> ℝ^3 ‣ x3 ‣ x4 ‣ x5 gap> u := UniversalMorphismIntoDirectProduct( Smooth, [ f, g ] ); ℝ^2 -> ℝ^5 gap> Display( u ); ℝ^2 -> ℝ^5 ‣ x1 ^ 2 + Sin( x2 ) ‣ Exp( x1 ) + 3 * x2 ‣ 3 * x1 ‣ Exp( x2 ) ‣ x1 ^ 3 + Log( x2 ) gap> PreCompose( Smooth, u, p1 ) = f; true gap> PreCompose( Smooth, u, p2 ) = g; true gap> d := DirectProductFunctorial( Smooth, [ f, g ] ); ℝ^4 -> ℝ^5 gap> Display( d ); ℝ^4 -> ℝ^5 ‣ x1 ^ 2 + Sin( x2 ) ‣ Exp( x1 ) + 3 * x2 ‣ 3 * x3 ‣ Exp( x4 ) ‣ x3 ^ 3 + Log( x4 ) gap> Rf := ReverseDifferential( f ); ℝ^4 -> ℝ^2 gap> Display( Rf ); ℝ^4 -> ℝ^2 ‣ x3 * (2 * x1) + x4 * Exp( x1 ) ‣ x3 * Cos( x2 ) + x4 * 3 gap> Display( Smooth.Sqrt ); ℝ^1 -> ℝ^1 ‣ Sqrt( x1 ) gap> Display( Smooth.Exp ); ℝ^1 -> ℝ^1 ‣ Exp( x1 ) gap> Display( Smooth.Log ); ℝ^1 -> ℝ^1 ‣ Log( x1 ) gap> Display( Smooth.Sin ); ℝ^1 -> ℝ^1 ‣ Sin( x1 ) gap> Display( Smooth.Cos ); ℝ^1 -> ℝ^1 ‣ Cos( x1 ) gap> Display( Smooth.Constant( [ 1.2, 3.4 ] ) ); ℝ^0 -> ℝ^2 ‣ 1.2 ‣ 3.4 gap> Display( Smooth.Zero( 2, 3 ) ); ℝ^2 -> ℝ^3 ‣ 0 ‣ 0 ‣ 0 gap> Display( Smooth.IdFunc( 2 ) ); ℝ^2 -> ℝ^2 ‣ x1 ‣ x2 gap> Display( Smooth.Relu( 2 ) ); ℝ^2 -> ℝ^2 ‣ Relu( x1 ) ‣ Relu( x2 ) gap> Display( Smooth.Mul( 3 ) ); ℝ^3 -> ℝ^1 ‣ x1 * x2 * x3 gap> Display( Smooth.Sum( 3 ) ); ℝ^3 -> ℝ^1 ‣ x1 + x2 + x3 gap> Display( Smooth.Mean( 3 ) ); ℝ^3 -> ℝ^1 ‣ (x1 + x2 + x3) / 3 gap> Display( Smooth.Variance( 3 ) ); ℝ^3 -> ℝ^1 ‣ ((x1 - (x1 + x2 + x3) / 3) ^ 2 + (x2 - (x1 + x2 + x3) / 3) ^ 2 + (x3 - (x1 + x2 + x3) / 3) ^ 2) / 3 gap> Display( Smooth.StandardDeviation( 3 ) ); ℝ^3 -> ℝ^1 ‣ Sqrt( ((x1 - (x1 + x2 + x3) / 3) ^ 2 + (x2 - (x1 + x2 + x3) / 3) ^ 2 + (x3 - (x1 + x2 + x3) / 3) ^ 2) / 3 ) gap> Display( Smooth.Power( 6 ) ); ℝ^1 -> ℝ^1 ‣ x1 ^ 6 gap> Display( Smooth.PowerBase( 6 ) ); ℝ^1 -> ℝ^1 ‣ 6 ^ x1 gap> Display( Smooth.Sigmoid( 2 ) ); ℝ^2 -> ℝ^2 ‣ 1 / (1 + Exp( (- x1) )) ‣ 1 / (1 + Exp( (- x2) )) gap> Display( Smooth.Softmax( 2 ) ); ℝ^2 -> ℝ^2 ‣ Exp( x1 ) / (Exp( x1 ) + Exp( x2 )) ‣ Exp( x2 ) / (Exp( x1 ) + Exp( x2 )) gap> Display( Smooth.QuadraticLoss( 2 ) ); ℝ^4 -> ℝ^1 ‣ ((x1 - x3) ^ 2 + (x2 - x4) ^ 2) / 2 gap> Display( Smooth.BinaryCrossEntropyLoss( 1 ) ); ℝ^2 -> ℝ^1 ‣ - (x2 * Log( x1 ) + (1 - x2) * Log( (1 - x1) )) gap> Display( Smooth.SigmoidBinaryCrossEntropyLoss( 1 ) ); ℝ^2 -> ℝ^1 ‣ Log( 1 + Exp( (- x1) ) ) + (1 - x2) * x1 gap> Display( Smooth.CrossEntropyLoss( 3 ) ); ℝ^6 -> ℝ^1 ‣ (- (Log( x1 ) * x4 + Log( x2 ) * x5 + Log( x3 ) * x6)) / 3 gap> Display( Smooth.SoftmaxCrossEntropyLoss( 3 ) ); ℝ^6 -> ℝ^1 ‣ ((Log( Exp( x1 ) + Exp( x2 ) + Exp( x3 ) ) - x1) * x4 + (Log( Exp( x1 ) + Exp( x2 ) + Exp( x3 ) ) - x2) * x5 + (Log( Exp( x1 ) + Exp( x2 ) + Exp( x3 ) ) - x3) * x6) / 3 gap> Display( Smooth.AffineTransformation( 2, 3 ) ); ℝ^11 -> ℝ^3 ‣ x1 * x10 + x2 * x11 + x3 ‣ x4 * x10 + x5 * x11 + x6 ‣ x7 * x10 + x8 * x11 + x9 gap> Display( Smooth.PolynomialTransformation( 2, 3, 2 ) ); ℝ^20 -> ℝ^3 ‣ x1 * x19 ^ 2 + x2 * (x19 ^ 1 * x20 ^ 1) + x3 * x19 ^ 1 + x4 * x20 ^ 2 + x5 * x20 ^ 1 + x6 * 1 ‣ x7 * x19 ^ 2 + x8 * (x19 ^ 1 * x20 ^ 1) + x9 * x19 ^ 1 + x10 * x20 ^ 2 + x11 * x20 ^ 1 + x12 * 1 ‣ x13 * x19 ^ 2 + x14 * (x19 ^ 1 * x20 ^ 1) + x15 * x19 ^ 1 + x16 * x20 ^ 2 + x17 * x20 ^ 1 + x18 * 1
gap> vars := [ "x", "y", "z" ]; [ "x", "y", "z" ] gap> e1 := Expression( vars, "x + Sin( y ) * Log( z )" ); x + Sin( y ) * Log( z ) gap> e2 := Expression( vars, "( x * y + Sin( z ) ) ^ 2" ); (x * y + Sin( z )) ^ 2 gap> CategoriesOfObject( e1 ); [ "IsExtAElement", "IsNearAdditiveElement", "IsNearAdditiveElementWithZero", "IsNearAdditiveElementWithInverse", "IsAdditiveElement", "IsExtLElement", "IsExtRElement", "IsMultiplicativeElement", "IsExpression" ] gap> KnownAttributesOfObject( e1 ); [ "String", "Variables" ] gap> String( e1 ); "x + Sin( y ) * Log( z )" gap> Variables( e1 ); [ "x", "y", "z" ] gap> e1 + e2; x + Sin( y ) * Log( z ) + (x * y + Sin( z )) ^ 2 gap> e1 * e2; (x + Sin( y ) * Log( z )) * (x * y + Sin( z )) ^ 2 gap> e := Sin( e1 ) / e2; Sin( (x + Sin( y ) * Log( z )) ) / (x * y + Sin( z )) ^ 2 gap> f := AsFunction( e ); function( vec ) ... end gap> Display( f ); function ( vec ) local x, y, z; Assert( 0, IsDenseList( vec ) and Length( vec ) = 3 ); x := vec[1]; y := vec[2]; z := vec[3]; return Sin( (x + Sin( y ) * Log( z )) ) / (x * y + Sin( z )) ^ 2; end gap> x := [ 3, 2, 4 ]; [ 3, 2, 4 ] gap> f( x ); -0.032725 gap> dummy_input := ConvertToExpressions( [ "x1", "x2", "x3" ] ); [ x1, x2, x3 ] gap> f( dummy_input ); Sin( (x1 + Sin( x2 ) * Log( x3 )) ) / (x1 * x2 + Sin( x3 )) ^ 2 gap> AssignExpressions( dummy_input ); #I MakeReadWriteGlobal: x1 already read-write #I MakeReadWriteGlobal: x2 already read-write #I MakeReadWriteGlobal: x3 already read-write gap> x1; x1 gap> Variables( x1 ); [ "x1", "x2", "x3" ] gap> [ [ x1, x2 ] ] * [ [ x3 ], [ -x3 ] ]; [ [ x1 * x3 + x2 * (- x3) ] ] gap> e := Sin( x1 ) / Cos( x1 ) + Sin( x2 ) ^ 2 + Cos( x2 ) ^ 2; Sin( x1 ) / Cos( x1 ) + Sin( x2 ) ^ 2 + Cos( x2 ) ^ 2 gap> SimplifyExpressionUsingPython( [ e ] ); [ "Tan(x1) + 1" ] gap> Diff( e, 1 )( dummy_input ); Sin( x1 ) ^ 2 / Cos( x1 ) ^ 2 + 1 gap> LazyDiff( e, 1 )( dummy_input );; gap> # Diff( [ "x1", "x2", "x3" ], > # "(((Sin(x1))/(Cos(x1)))+((Sin(x2))^(2)))+((Cos(x2))^(2))", 1 )( [ x1, x2, x3 ] ); gap> JacobianMatrixUsingPython( [ x1*Cos(x2)+Exp(x3), x1*x2*x3 ], [ 1, 2, 3 ] ); [ [ "Cos(x2)", "-x1*Sin(x2)", "Exp(x3)" ], [ "x2*x3", "x1*x3", "x1*x2" ] ] gap> JacobianMatrix( [ "x1", "x2", "x3" ], [ "x1*Cos(x2)+Exp(x3)", "x1*x2*x3" ], > [ 1, 2, 3 ] )(dummy_input); [ [ Cos(x2), (-x1)*Sin(x2), Exp(x3) ], [ x2*x3, x1*x3, x1*x2 ] ] gap> LaTeXOutputUsingPython( e ); "\\frac{\\sin{\\left(x_{1} \\right)}}{\\cos{\\left(x_{1} \\right)}} + \\sin^{2}{\\left(x_{2} \\right)} + \\cos^{2}{\\left(x_{2} \\right)}" gap> sigmoid := Expression( [ "x" ], "Exp(x)/(1+Exp(x))" ); Exp( x ) / (1 + Exp( x )) gap> sigmoid := AsFunction( sigmoid ); function( vec ) ... end gap> sigmoid( [ 0 ] ); 0.5 gap> points := List( 0.1 * [ -20 .. 20 ], x -> [ x, sigmoid( [ x ] ) ] ); [ [ -2., 0.119203 ], [ -1.9, 0.130108 ], [ -1.8, 0.141851 ], [ -1.7, 0.154465 ], [ -1.6, 0.167982 ], [ -1.5, 0.182426 ], [ -1.4, 0.197816 ], [ -1.3, 0.214165 ], [ -1.2, 0.231475 ], [ -1.1, 0.24974 ], [ -1., 0.268941 ], [ -0.9, 0.28905 ], [ -0.8, 0.310026 ], [ -0.7, 0.331812 ], [ -0.6, 0.354344 ], [ -0.5, 0.377541 ], [ -0.4, 0.401312 ], [ -0.3, 0.425557 ], [ -0.2, 0.450166 ], [ -0.1, 0.475021 ], [ 0., 0.5 ], [ 0.1, 0.524979 ], [ 0.2, 0.549834 ], [ 0.3, 0.574443 ], [ 0.4, 0.598688 ], [ 0.5, 0.622459 ], [ 0.6, 0.645656 ], [ 0.7, 0.668188 ], [ 0.8, 0.689974 ], [ 0.9, 0.71095 ], [ 1., 0.731059 ], [ 1.1, 0.75026 ], [ 1.2, 0.768525 ], [ 1.3, 0.785835 ], [ 1.4, 0.802184 ], [ 1.5, 0.817574 ], [ 1.6, 0.832018 ], [ 1.7, 0.845535 ], [ 1.8, 0.858149 ], [ 1.9, 0.869892 ], [ 2., 0.880797 ] ] gap> labels := List( points, point -> SelectBasedOnCondition( point[2] < 0.5, 0, 1 ) ); [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ] gap> ScatterPlotUsingPython( points, labels : size := "100", action := "save" );; gap> # e.g, dir("/tmp/gaptempdirX7Qsal/") > AsCythonFunction( [ [ "x", "y" ], [ "z" ] ], [ "f", "g" ], [ "x*y", "Sin(z)" ] );; gap> # e.g., > # cd /tmp/gaptempdirI6rq3l/ > # > # start python! > # > # from cython_functions import f, g; gap> # > # # w = [ 2 entries :) ] > # > # # f(w)
generated by GAPDoc2HTML