From bc218015a13933c2ffbd0d418d360e42457e8b94 Mon Sep 17 00:00:00 2001 From: Steven Miller Date: Tue, 23 May 2017 10:31:42 -0700 Subject: [PATCH] forward: ocd split into separate sum function --- index.js | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index 11aa10c..cf0ac67 100644 --- a/index.js +++ b/index.js @@ -117,40 +117,40 @@ class Mind extends Emitter { */ forward (examples) { - const activate = this.activate - const weights = this.weights const results = [] - // sum the weight and input - function sum (w, i) { - const res = {} - - res.sum = Matrix.multiply(w, i) - res.result = res.sum.transform(activate) - - return res - }; - // input > hidden - results.push( - sum(weights[0], examples.input) - ) + results.push(this.sum(this.weights[0], examples.input)) // hidden > hidden for (let i = 1; i < this.hiddenLayers; i++) { - results.push( - sum(weights[i], results[i - 1].result) - ) + results.push(this.sum(this.weights[i], results[i - 1].result)) } // hidden > output - results.push( - sum(weights[weights.length - 1], results[results.length - 1].result) - ) + results.push(this.sum(this.weights[this.weights.length - 1], results[results.length - 1].result)) return results } + /** + * Sum `weight` and `input`. + * + * @param {Matrix} weight + * @param {Array} input + * @return {Object} + * @api private + */ + + sum (weight, input) { + const res = {} + + res.sum = Matrix.multiply(weight, input) + res.result = res.sum.transform(this.activate) + + return res + } + /** * Back propagate. *