Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. const Network = require("./network");
  2.  
  3. // AND Logic Gate
  4. const dataset = [
  5. { inputs: [0,0], outputs: [0] },
  6. { inputs: [0,1], outputs: [0] },
  7. { inputs: [1,0], outputs: [0] },
  8. { inputs: [1,1], outputs: [1] }
  9. ]
  10.  
  11. // Neural Network
  12. const network = new Network([2,2,1]);
  13.  
  14. // Utility Functions
  15. const train = (iterations=1) => {
  16. while(iterations > 0) {
  17. dataset.map(datum => {
  18. network.activate(datum.inputs);
  19. network.propagate(datum.outputs);
  20. });
  21. iterations--;
  22. }
  23. };
  24.  
  25. // Train Network (10,000 Iterations)
  26. train(10000);
  27.  
  28. // Test Network
  29. console.log(activate([0,0])); // ~0 (0.01214291222508886)
  30. console.log(activate([0,1])); // ~0 (0.08100696632854297)
  31. console.log(activate([1,0])); // ~0 (0.07793351045035582)
  32. console.log(activate([1,1])); // ~1 (0.8780115291725155)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement