programlibs/NN/demos/xor.xtl
XOR by a two-layer network with hand-set weights: no straight line separates XOR's classes, but one hidden ReLU layer does. Every layer is one nn:d_ense on the whole batch of four points at once. Run with "just demo-lib NN xor".
x : Float
The four points, one per row, and their classes (1: same, 2: differ).
x ← 4 2 r̲eshape 0.0 0.0 0.0 1.0 1.0 0.0 1.0 1.0
Used in: h
w1 : Float
Hidden layer: h1 = relu(a + b), h2 = relu(a + b - 1); the last row of each weight array is its bias.
w1 ← 3 2 r̲eshape 1.0 1.0 1.0 1.0 0.0 -1.0
Used in: h
w2 : Float
Output layer: class 2's score is 4 h1 - 8 h2 - 2, class 1's is 0.
w2 ← 3 2 r̲eshape 0.0 4.0 0.0 -8.0 0.0 -2.0
Used in: p
p : Float
p ← ⁿⁿs̲oftmax h ⁿⁿd̲ense w2