Skip to content

Commit 295cff4

Browse files
committed
add extra tests
1 parent f014407 commit 295cff4

File tree

2 files changed

+107
-2
lines changed

2 files changed

+107
-2
lines changed

examples/CategoryOfParametrisedMorphisms.g

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ R2 := Smooth.( 2 );
1515
#! ℝ^2
1616
R3 := Smooth.( 3 );
1717
#! ℝ^3
18+
R1 / Para;
19+
#! ℝ^1
20+
Para.( 1 );
21+
#! ℝ^1
22+
IsEqualForObjects( Para.( 1 ), R1 / Para );
23+
#! true
1824
f := Smooth.Softmax( 3 );
1925
#! ℝ^3 -> ℝ^3
2026
f := MorphismConstructor( Para, R1 / Para, [ R2, f ], R3 / Para );
@@ -41,6 +47,8 @@ Display( f );
4147
#! ‣ Exp( x1 ) / (Exp( x1 ) + Exp( x2 ) + Exp( x3 ))
4248
#! ‣ Exp( x2 ) / (Exp( x1 ) + Exp( x2 ) + Exp( x3 ))
4349
#! ‣ Exp( x3 ) / (Exp( x1 ) + Exp( x2 ) + Exp( x3 ))
50+
IsWellDefined( f );
51+
#! true
4452
r := DirectProductFunctorial( Smooth, [ Smooth.Sqrt, Smooth.Cos ] );
4553
#! ℝ^2 -> ℝ^2
4654
Display( r );
@@ -110,7 +118,7 @@ Display( h );
110118
#! + x6 * (Exp( Cos( x10 ) ) / (Exp( Sqrt( x9 ) ) + Exp( Cos( x10 ) ) + Exp( x11 )))
111119
#! + x7 * (Exp( x11 ) / (Exp( Sqrt( x9 ) ) + Exp( Cos( x10 ) ) + Exp( x11 ))) + x8
112120
constants := [ 0.91, 0.24, 0.88, 0.59, 0.67, 0.05, 0.85, 0.31, 0.76, 0.04 ];;
113-
r := SmoothMorphism( Smooth, Smooth.( 0 ), constants, Smooth.( 10 ) );
121+
r := Smooth.Constant( constants );
114122
#! ℝ^0 -> ℝ^10
115123
t := ReparametriseMorphism( h, r );
116124
#! ℝ^1 -> ℝ^2 defined by:
@@ -147,7 +155,7 @@ s := SimplifyMorphism( t, infinity );
147155
#! Parametrised Morphism:
148156
#! ----------------------
149157
#! ℝ^1 -> ℝ^2
150-
#! gap> Display( s );
158+
Display( s );
151159
#! ℝ^1 -> ℝ^2 defined by:
152160
#!
153161
#! Parameter Object:
@@ -160,4 +168,30 @@ s := SimplifyMorphism( t, infinity );
160168
#!
161169
#! ‣ (1.47 * Exp( x1 ) + 5.84111) / (Exp( x1 ) + 5.10727)
162170
#! ‣ (1.16 * Exp( x1 ) + 3.32114) / (Exp( x1 ) + 5.10727)
171+
iota := NaturalEmbeddingIntoCategoryOfParametrisedMorphisms( Smooth, Para );
172+
#! Natural embedding into category of parametrised morphisms
173+
ApplyFunctor( iota, Smooth.( 1 ) );
174+
#! ℝ^1
175+
psi := ApplyFunctor( iota, Smooth.Sum( 2 ) );
176+
#! ℝ^2 -> ℝ^1 defined by:
177+
#!
178+
#! Parameter Object:
179+
#! -----------------
180+
#! ℝ^0
181+
#!
182+
#! Parametrised Morphism:
183+
#! ----------------------
184+
#! ℝ^2 -> ℝ^1
185+
Print( DisplayString( psi ) );
186+
#! ℝ^2 -> ℝ^1 defined by:
187+
#!
188+
#! Parameter Object:
189+
#! -----------------
190+
#! ℝ^0
191+
#!
192+
#! Parametrised Morphism:
193+
#! ----------------------
194+
#! ℝ^2 -> ℝ^1
195+
#!
196+
#! ‣ x1 + x2
163197
#! @EndExample

tst/functor.tst

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
3+
gap> Smooth := SkeletalSmoothMaps;;
4+
gap> Lenses := CategoryOfLenses( Smooth );;
5+
gap> Para := CategoryOfParametrisedMorphisms( Smooth );;
6+
gap> Para_Lenses := CategoryOfParametrisedMorphisms( Lenses );;
7+
gap> f := LossMorphismOfNeuralNetwork( Para, 2, [], 1, "IdFunc" );;
8+
The total number of layers is 2
9+
10+
Creating a morphism from layer 1 to 2 with 3 parameters
11+
gap> dummy_input := ConvertToExpressions( [ "w1", "w2", "b1", "x1", "x2", "y" ] );
12+
[ w1, w2, b1, x1, x2, y ]
13+
gap> Display( f : dummy_input := dummy_input );
14+
^3 ->^1 defined by:
15+
16+
Parameter Object:
17+
-----------------
18+
^3
19+
20+
Parametrised Morphism:
21+
----------------------
22+
^6 ->^1
23+
24+
‣ (w1 * x1 + w2 * x2 + b1 - y) ^ 2 / 1
25+
gap> R := EmbeddingIntoCategoryOfParametrisedMorphisms( Para, Para_Lenses );
26+
Embedding into category of parametrised morphisms
27+
gap> Rf := ApplyFunctor( R, f );
28+
(ℝ^3, ℝ^3) -> (ℝ^1, ℝ^1) defined by:
29+
30+
Parameter Object:
31+
-----------------
32+
(ℝ^3, ℝ^3)
33+
34+
Parametrised Morphism:
35+
----------------------
36+
(ℝ^6, ℝ^6) -> (ℝ^1, ℝ^1) defined by:
37+
38+
Get Morphism:
39+
----------
40+
^6 ->^1
41+
42+
Put Morphism:
43+
----------
44+
^7 ->^6
45+
gap> Display( Rf );
46+
(ℝ^3, ℝ^3) -> (ℝ^1, ℝ^1) defined by:
47+
48+
Parameter Object:
49+
-----------------
50+
(ℝ^3, ℝ^3)
51+
52+
Parametrised Morphism:
53+
----------------------
54+
(ℝ^6, ℝ^6) -> (ℝ^1, ℝ^1) defined by:
55+
56+
Get Morphism:
57+
------------
58+
^6 ->^1
59+
60+
‣ (x1 * x4 + x2 * x5 + x3 - x6) ^ 2 / 1
61+
62+
Put Morphism:
63+
------------
64+
^7 ->^6
65+
66+
‣ x7 * (2 * (x1 * x4 + x2 * x5 + x3 - x6) / 1 * (1 * (x4 * 1 + 0 + 0 + 0 + 0)) + 0)
67+
‣ x7 * (2 * (x1 * x4 + x2 * x5 + x3 - x6) / 1 * (1 * (0 + x5 * 1 + 0 + 0 + 0)) + 0)
68+
‣ x7 * (2 * (x1 * x4 + x2 * x5 + x3 - x6) / 1 * (1 * (0 + 0 + 1 + 0 + 0)) + 0)
69+
‣ x7 * (2 * (x1 * x4 + x2 * x5 + x3 - x6) / 1 * (1 * (0 + 0 + 0 + x1 * 1 + 0)) + 0)
70+
‣ x7 * (2 * (x1 * x4 + x2 * x5 + x3 - x6) / 1 * (1 * (0 + 0 + 0 + 0 + x2 * 1)) + 0)
71+
‣ x7 * (0 + 2 * (x6 - (x1 * x4 + x2 * x5 + x3)) / 1 * 1)

0 commit comments

Comments
 (0)