Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. const uid = require("cuid");
  2. const Neuron = require("./neuron");
  3.  
  4. function Group(size, bias) {
  5. this.id = uid();
  6.  
  7. this.neurons = size == undefined ? [] : Array.from({ length: size }, function() {
  8. return new Neuron(bias);
  9. });
  10.  
  11. this.connect = function(target, weights) {
  12. const self = this;
  13.  
  14. this.neurons.forEach(function(neuron, a) {
  15. target.neurons.forEach(function(other, b) {
  16. if(weights) neuron.connect(other, weights[self.neurons.length * a + b]);
  17. else neuron.connect(other);
  18. })
  19. })
  20. }
  21.  
  22. this.activate = function(inputs) {
  23. return this.neurons.map(function(neuron, index) {
  24. if(inputs) return neuron.activate(inputs[index]);
  25. else return neuron.activate();
  26. })
  27. }
  28.  
  29. this.propagate = function(targets, rate=0.3) {
  30. return this.neurons.map(function(neuron, index) {
  31. if(targets) return neuron.propagate(targets[index]);
  32. else return neuron.propagate();
  33. })
  34. }
  35. }
  36.  
  37. module.exports = Group;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement