programlibs/Net/demos/xor.xtl

XOR, the network written as one line. NN's own demo builds the same two layers by hand; here the spec "2 2 relu 2 softmax" is the network, and xetal expand shows the function the macro wrote. Run with "just demo-lib Net xor"; see it with "just expand-lib Net xor".

source · imports nn: libs/NN/src/NN.xtl; net: libs/Net/src/Net.xtlm

x : Float

value · line 10

The four points 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: p

y : Int

value · line 11
y ← 1 2 2 1

w1 : Float

value · line 13

The weights, set by hand: each layer's bias is its last row.

w1 ← 3 2 r̲eshape 1.0 1.0 1.0 1.0 0.0 -1.0

w2 : Float

value · line 14
w2 ← 3 2 r̲eshape 0.0 4.0 0.0 -8.0 0.0 -2.0

ᵘx̲or : Float -> Float

function · line 20

The network: a function, written by the macro.

ᵘx̲or ← "2 2 relu 2 softmax" ⁿᵉᵗn̲etwork< "w1 w2"
ⁿᵉᵗn̲etwork< expands to
({ x → ⁿⁿs̲oftmax (ⁿⁿr̲elu x ⁿⁿd̲ense w1) ⁿⁿd̲ense w2 })
Used in: p

p : Float

value · line 21
p ← ᵘx̲or x