| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <!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>
|