sourcelibs/Conv/demos/edges.xtl
1⍝!/usr/bin/env xetal
2⍝│ Conv on one small picture: a square, two edge filters, ReLU and
3⍝│ pooling, drawn. Run with "just demo-lib Conv edges".
4
5"cv:" u̲se< "Conv"
6
7⍝│ A 10 x 10 picture: a bright square on dark.
8r ← (o̲ffsets 10) 'l̲eft t̲able o̲ffsets 10
9cc ← (o̲ffsets 10) 'r̲ight t̲able o̲ffsets 10
10x ← 1 10 10 r̲eshape f̲loat (r > 2) ∧ (r < 7) ∧ (cc > 2) ∧ cc < 7
11⍝│ Two filters: left-to-right brightening (a left edge), and top-to-bottom.
12K ← 2 9 r̲eshape -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 0.0 1.0 -1.0 -1.0 -1.0 0.0 0.0 0.0 1.0 1.0 1.0
13ᵘs̲hade ← { m → (1 + f̲loor 0 m̲ax 3 m̲in m) s̲elect " .:#" }
14⍝│ The picture, then each filter's map after ReLU (8 x 8), then pooled (4 x 4).
15ᵘs̲hade 3.0 × 10 10 r̲eshape x
16m ← 0.0 m̲ax (K, 0.0 0.0) ᶜᵛc̲onv x
17ᵘs̲hade 8 8 r̲eshape 1 s̲elect₂ m
18ᵘs̲hade 8 8 r̲eshape 2 s̲elect₂ m
19ᵘs̲hade 4 4 r̲eshape 1 s̲elect₂ ᶜᵛp̲ool m