| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <!DOCTYPE html>
- <html>
- <head>
- <title>Brain JS Test</title>
- <meta charset="utf-8" />
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <style>
- #network {
- background: #ccc;
- border: 1px solid red;
- width: 80%;
- height: 400px;
- }
- </style>
- </head>
- <body>
- <h1>Brain JS Test</h1>
- <p>
- Brain.js is a machine learning program in Javascript.
- </p>
- <h2>Test results</h2>
- <div id="output"></div>
- <h2>Network</h2>
- <div id="network"></div>
- </body>
- <script src="brain-browser.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: "relu", // supported activation types: ['sigmoid', 'relu', 'leaky-relu', 'tanh'],
- leakyReluAlpha: 0.01, // supported for activation type 'leaky-relu'
- inputSize: 2,
- outputSize: 1,
- };
- // 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 input = [1, 0];
- const output = net.run(input); // [0.987]
- document.getElementById("output").innerHTML =
- "Input:" + input + "<br/>" + "output is " + output;
- document.getElementById("network").innerHTML = brain.utilities.toSVG(
- net,
- config
- );
- </script>
- </html>
|