runTests = (label, network, tests) => { console.log(`--- ${label}`); for (test of tests) { console.log(`${label} test ${JSON.stringify(test)}: ${network.run(test)}`); } } netXOR = new brain.NeuralNetwork(); netXOR.train([ { input: [0, 0], output: [0] }, { input: [0, 1], output: [1] }, { input: [1, 0], output: [1] }, { input: [1, 1], output: [0] } ]); runTests("XOR gate", netXOR, [ [0,0], [0,1], [1,0], [1,1] ]); netSum = new brain.recurrent.LSTM({ hiddenLayer: [20] }); netSum.train([ "0+0=0", "0+1=1", "0+2=2", "0+3=3", "0+4=4", "0+5=5", "1+0=1", "1+1=2", "1+2=3", "1+3=4", "1+4=5", "1+5=6", "2+0=2", "2+1=3", "2+2=4", "2+3=5", "2+4=6", "2+5=7", "3+0=3", "3+1=4", "3+2=5", "3+3=6", "3+4=7", "3+5=8", "4+0=4", "4+1=5", "4+2=6", "4+3=7", "4+4=8", "4+5=9", "5+0=5", "5+1=6", "5+2=7", "5+3=8", "5+4=9", "5+5=10" ], { errorThresh: 0.025 }); runTests("Sum", netSum, [ "1+2=", "4+2=", "3+3=" ]);