Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. index: 1, result: 1
  2. index: 2, result: 2
  3. index: 3, result: 3
  4. index: 4, result: 4
  5. index: 5, result: 1
  6. index: 6, result: 2
  7. index: 7, result: 3
  8. index: 8, result: 4
  9. index: 9, result: 1
  10. index: 10, result: 2
  11. index: 11, result: 3
  12. index: 12, result: 4
  13. etc.
  14.  
  15. const brain = require('brain.js');
  16.  
  17. const network = new brain.recurrent.LSTMTimeStep();
  18.  
  19. let trainingData = [];
  20.  
  21. for (let i = 1, j = [4, 1, 2, 3]; i <= 100; i++) {
  22. trainingData.push({input: {index: i}, output: {result: j[i%4]}});
  23. }
  24.  
  25. network.train(trainingData);
  26.  
  27. console.log(network.run({index: 101}));
  28. console.log(network.run({index: 102}));
  29. console.log(network.run({index: 103}));
  30. console.log(network.run({index: 104}));
  31.  
  32. /*
  33. { result: 2.564828634262085 }
  34. { result: 2.564828634262085 }
  35. { result: 2.564828634262085 }
  36. { result: 2.564828634262085 }
  37. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement