Skip to content

Instantly share code, notes, and snippets.

@luiscarbonell
Created August 6, 2019 02:56
Show Gist options
  • Select an option

  • Save luiscarbonell/718dbd791b23f03c57695156c46c28a2 to your computer and use it in GitHub Desktop.

Select an option

Save luiscarbonell/718dbd791b23f03c57695156c46c28a2 to your computer and use it in GitHub Desktop.
const uid = require("cuid");
function Neuron() {
this.id = uid(); // ID
this.bias = bias == undefined ? Math.random() * 2 - 1 : bias; // this.bias ∈ ℝ && -1 < this.bias < 1
// Incoming Connections
this.incoming = {
neurons: {}, // new Map()
weights: {} // new Map()
}
// Outgoing Connections
this.outgoing = {
neurons: {}, // new Map()
weights: {} // new Map()
}
this._output; // f'(x)
this.output; // f(x)
this.error; // E'(f(x))
this.connect = function(neuron, weight) {
this.outgoing.neurons[neuron.id] = neuron;
neuron.incoming.neurons[this.id] = this;
this.outgoing.weights[neuron.id] = neuron.incoming.weights[this.id] = weight == undefined ? Math.random() * 2 - 1 : weight; // weight ∈ ℝ && -1 < weight < 1
}
}
module.exports = Neuron;
@luiscarbonell

Copy link
Copy Markdown
Author

+ neuron.v0.0.2.js
+ neuron.connect() - enables the creation of neural networks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment