Neural Network XOR Plot style canvas border 1px solid black body min height 600px style h1 Neural Network XOR Plot h1 canvas id canvas width 400 height 400 canvas script src https cdnjs cloudflare com ajax libs synaptic 1 1 4 synaptic js script script Create the neural network const Layer Network Trainer synaptic const inputLayer new Layer 2 const hiddenLayer new Layer 3 const outputLayer new Layer 1 inputLayer project hiddenLayer hiddenLayer project outputLayer const myNetwork new Network input inputLayer hidden hiddenLayer output outputLayer XOR training set const trainingSet input 0 0 output 0 input 0 1 output 1 input 1 0 output 1 input 1 1 output 0 Train the neural network const trainer new Trainer myNetwork trainer train trainingSet rate 0 2 iterations 20000 error 0 005 shuffle true log 1000 cost Trainer cost CROSS_ENTROPY Plotting function const canvas document getElementById canvas const ctx canvas getContext 2d function plotPoint x y color w 6 h 6 ctx fillStyle color ctx fillRect x 400 w 0 5 y 400 w 0 5 w h Generate points and plot for let i 0 i 1 i 0 01 for let j 0 j 1 j 0 01 const output myNetwork activate i j const color output 0 0 5 red blue plotPoint i j color Plot original data points plotPoint 0 0 green 30 30 plotPoint 0 1 yellow 30 30 plotPoint 1 0 yellow 30 30 plotPoint 1 1 green 30 30 script
const trainer new Trainer myNetwork trainer train trainingSet rate 0 2 iterations 20000 error 0 005 shuffle true log 1000 cost Trainer cost CROSS_ENTROPY Plotting function const canvas document getElementById canvas const ctx canvas getContext 2d function plotPoint x y color w 6 h 6 ctx fillStyle color ctx fillRect x 400 w 0 5 y 400 w 0 5 w h Generate points and plot for let i 0 i 1 i 0 01 for let j 0 j 1 j 0 01 const output myNetwork activate i j const color output 0 0 5 red blue plotPoint i j color Plot original data points plotPoint 0 0 green 30 30 plotPoint 0 1 yellow 30 30 plotPoint 1 0 yellow 30 30 plotPoint 1 1 green 30 30 script