brain-js.test-01.html 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Brain JS Test</title>
  5. </head>
  6. <body>
  7. <h1>Brain JS Test</h1>
  8. <p>
  9. Brain.js is a machine learning program in Javascript.
  10. </p>
  11. <div id="output"></div>
  12. <div id="network"></div>
  13. </body>
  14. <script src="//unpkg.com/brain.js"></script>
  15. <script type="text/javascript">
  16. // provide optional config object (or undefined). Defaults shown.
  17. const config = {
  18. binaryThresh: 0.5,
  19. hiddenLayers: [3], // array of ints for the sizes of the hidden layers in the network
  20. activation: 'sigmoid', // supported activation types: ['sigmoid', 'relu', 'leaky-relu', 'tanh'],
  21. leakyReluAlpha: 0.01, // supported for activation type 'leaky-relu'
  22. };
  23. // create a simple feed forward neural network with backpropagation
  24. const net = new brain.NeuralNetwork(config);
  25. net.train([
  26. { input: [0, 0], output: [0] },
  27. { input: [0, 1], output: [1] },
  28. { input: [1, 0], output: [1] },
  29. { input: [1, 1], output: [0] },
  30. ]);
  31. const output = net.run([1, 0]); // [0.987]
  32. document.getElementById('output').innerHTML = "Input:" + [1, 0] + "<br>" + "output is " + output;
  33. </script>
  34. </html>