brain-js.test-01.html 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Brain JS Test</title>
  5. <meta charset="utf-8" />
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <meta name="viewport"
  8. content="width=device-width, initial-scale=1.0">
  9. <style>
  10. #network {
  11. background: #ccc;
  12. border: 1px solid red;
  13. width: 640px;
  14. height: 480px;
  15. }
  16. </style>
  17. <link rel="stylesheet" href="simple.min.css">
  18. </head>
  19. <body>
  20. <h1>Brain JS Test</h1>
  21. <p>
  22. Brain.js is a machine learning program in Javascript.
  23. </p>
  24. <h2>Test results</h2>
  25. <div id="output"></div>
  26. <h2>Network</h2>
  27. <div id="network"></div>
  28. </body>
  29. <script src="brain-browser.js"></script>
  30. <script type="text/javascript">
  31. const svg_config = {
  32. height: 480,
  33. width: 640,
  34. };
  35. // create a simple feed forward neural network with backpropagation
  36. const net = new brain.NeuralNetwork();
  37. net.train([
  38. { input: [0, 0], output: [0] },
  39. { input: [0, 1], output: [1] },
  40. { input: [1, 0], output: [1] },
  41. { input: [1, 1], output: [0] },
  42. ]);
  43. const input = [1, 0];
  44. const output = net.run(input); // [0.987]
  45. document.getElementById("output").innerHTML =
  46. `Input: [${input}] <br/>Output is ${output}`;
  47. document.getElementById("network").innerHTML = brain.utilities.toSVG(
  48. net,
  49. svg_config
  50. );
  51. </script>
  52. </html>