| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <!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: 640px;
- height: 480px;
- }
- </style>
- </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: 20,
- inputRange: 20,
- hiddenLayers: [2, 5],
- outputSize: 20,
- learningRate: 0.01,
- decayRate: 0.999,
- };
- const svg_config = {
- height: 480,
- width: 640,
- radius: 10,
- inputs:{
- labels:['1','2','3', '4','5' ],
- color:'#333',
- }
- };
- // 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>
|