Skip to content

Commit

Permalink
forward: ocd split into separate sum function
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Miller committed May 23, 2017
1 parent 8111dd0 commit bc21801
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions index.js
Expand Up @@ -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.
*
Expand Down

0 comments on commit bc21801

Please sign in to comment.