Selaa lähdekoodia

Start a test js app for brain.js

Jason Xing 3 vuotta sitten
commit
2f417e3cd7
1 muutettua tiedostoa jossa 41 lisäystä ja 0 poistoa
  1. 41 0
      brain-js.test-01.html

+ 41 - 0
brain-js.test-01.html

@@ -0,0 +1,41 @@
+<!DOCTYPE HTML>
+<html>
+
+<head>
+    <title>Brain JS Test</title>
+</head>
+
+<body>
+    <h1>Brain JS Test</h1>
+    <p>
+        Brain.js is a machine learning program in Javascript.
+    </p>
+    <div id="output"></div>
+    <div id="network"></div>
+</body>
+<script src="//unpkg.com/brain.js"></script>
+<script type="text/javascript">
+// provide optional config object (or undefined). Defaults shown.
+const config = {
+  binaryThresh: 0.5,
+  hiddenLayers: [3], // array of ints for the sizes of the hidden layers in the network
+  activation: 'sigmoid', // supported activation types: ['sigmoid', 'relu', 'leaky-relu', 'tanh'],
+  leakyReluAlpha: 0.01, // supported for activation type 'leaky-relu'
+};
+
+// create a simple feed forward neural network with backpropagation
+const net = new brain.NeuralNetwork(config);
+
+net.train([
+  { input: [0, 0], output: [0] },
+  { input: [0, 1], output: [1] },
+  { input: [1, 0], output: [1] },
+  { input: [1, 1], output: [0] },
+]);
+
+const output = net.run([1, 0]); // [0.987]
+
+document.getElementById('output').innerHTML = "Input:" + [1, 0] + "<br>" + "output is " + output;
+</script>
+
+</html>