From 62993dd59bbbfcdb07dbb5836d359fad6334f23e Mon Sep 17 00:00:00 2001 From: TinWoodman92 Date: Thu, 8 Feb 2024 16:09:56 -0600 Subject: initial commit --- src/nnetwork.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/nnetwork.js (limited to 'src/nnetwork.js') diff --git a/src/nnetwork.js b/src/nnetwork.js new file mode 100644 index 0000000..dd21491 --- /dev/null +++ b/src/nnetwork.js @@ -0,0 +1,36 @@ +console.log('Hello from nnetwork.js'); + +class NNetwork { + constructor(nodeCounts, activationFunctionNames, learningRate) { + this.learningRate = learningRate; + this.layers = []; + for (let i = 1; i < nodeCounts.length; i++) { + this.layers.push(new Layer(nodeCounts[i-1], nodeCounts[i], activationFunctionNames[i])); + }; + } + forwardPropogation(activationInput) { + let ao = activationInput; + this.layers.forEach(layer => { + ao = layer.forwardPropogation(ao); + }); + return ao; + } + backPropogation(activationInput, targetOutput) { + let ao = this.forwardPropogation(activationInput); + let cost = math.subtract(ao, targetOutput); + let dc_da = math.multiply(cost, 2); + cost = math.map(cost, element => element ** 2); + cost = math.sum(cost) + this.layers.reverse().forEach(layer => { + dc_da = layer.backPropogation(dc_da); + }); + this.layers.reverse() + return cost; + } + gradientDescent() { + this.layers.reverse().forEach(layer => { + layer.gradientDescent(this.learningRate); + }); + this.layers.reverse() + } +}; -- cgit v1.2.3