console.js 442 B

1234567891011121314151617181920
  1. runTests = (label, network, tests) => {
  2. console.log(`--- ${label}`);
  3. for (test of tests) {
  4. console.log(`${label} test ${JSON.stringify(test)}: ${network.run(test)}`);
  5. }
  6. }
  7. netXOR = new brain.NeuralNetwork();
  8. netXOR.train([
  9. { input: [0, 0], output: [0] },
  10. { input: [0, 1], output: [1] },
  11. { input: [1, 0], output: [1] },
  12. { input: [1, 1], output: [0] }
  13. ]);
  14. runTests("XOR gate", netXOR, [
  15. [0,0],
  16. [0,1],
  17. [1,0],
  18. [1,1]
  19. ]);