Created
August 12, 2019 14:58
-
-
Save luiscarbonell/f8dde2e8ab9e80a3996f25e9b8304412 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const uid = require("cuid"); | |
| const Neuron = require("./neuron"); | |
| function Group(size, bias) { | |
| this.id = uid(); | |
| this.neurons = size == undefined ? [] : Array.from({ length: size }, function() { | |
| return new Neuron(bias); | |
| }); | |
| this.connect = function(target, weights) { | |
| const self = this; | |
| this.neurons.forEach(function(neuron, a) { | |
| target.neurons.forEach(function(other, b) { | |
| if(weights) neuron.connect(other, weights[self.neurons.length * a + b]); | |
| else neuron.connect(other); | |
| }) | |
| }) | |
| } | |
| this.activate = function(inputs) { | |
| return this.neurons.map(function(neuron, index) { | |
| if(inputs) return neuron.activate(inputs[index]); | |
| else return neuron.activate(); | |
| }) | |
| } | |
| this.propagate = function(targets, rate=0.3) { | |
| return this.neurons.map(function(neuron, index) { | |
| if(targets) return neuron.propagate(targets[index]); | |
| else return neuron.propagate(); | |
| }) | |
| } | |
| } | |
| module.exports = Group; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment