| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <!DOCTYPE html>
- <html>
- <head>
- <title>Brain JS Test</title>
- <meta charset="utf-8" />
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="viewport"
- content="width=device-width, initial-scale=1.0">
- <style>
- #network {
- background: #ccc;
- border: 1px solid red;
- width: 640px;
- height: 480px;
- }
- </style>
- <link rel="stylesheet" href="simple.min.css">
- </head>
- <body>
- <h1>Brain JS Test - RNN</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, defaults shown.
- const config = {
- inputSize: 5,
- hiddenLayers: [6,6],
- outputSize: 5,
- learningRate: 0.01,
- decayRate: 0.999,
- };
- const svg_config = {
- height: 480,
- width: 640,
- };
- // create a simple recurrent neural network
- const net = new brain.recurrent.RNN(config);
- net.train([
- { input: [0, 0], output: [0] },
- { input: [0, 1], output: [1] },
- { input: [1, 0], output: [1] },
- { input: [1, 1], output: [0] },
- ]);
- let input = [1, 0];
- let output = net.run([0, 0]); // [0]
- document.getElementById("output").innerHTML =
- "Input:" + input + "<br/>" + "output is " + output;
- document.getElementById("network").innerHTML = brain.utilities.toSVG(
- net,
- svg_config
- );
- </script>
- </html>
|