diff options
author | TinWoodman92 <chrhodgden@gmail.com> | 2024-02-08 16:09:56 -0600 |
---|---|---|
committer | TinWoodman92 <chrhodgden@gmail.com> | 2024-02-08 16:09:56 -0600 |
commit | 62993dd59bbbfcdb07dbb5836d359fad6334f23e (patch) | |
tree | 4f0d310442c66050d0886eb82bebd9475e63803c /src/nnetwork.js |
initial commit
Diffstat (limited to 'src/nnetwork.js')
-rw-r--r-- | src/nnetwork.js | 36 |
1 files changed, 36 insertions, 0 deletions
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() + } +}; |