Last active
February 13, 2016 11:33
-
-
Save ruemic/49b13d1394e417f9be3e to your computer and use it in GitHub Desktop.
Revisions
-
ruemic revised this gist
Feb 13, 2016 . 1 changed file with 7 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,20 +8,24 @@ const validateLengths = (a,b,action) => { } const arrayMultiply = (arr1, arr2) => { validateLengths(arr1, arr2, "multiply") return reduce(arr1, (accumulator, arrayItem, i) => accumulator += arrayItem * arr2[i] , 0) } const arrayAdd = (arr1, arr2) => { validateLengths(arr1, arr2, "add") return map(arr1, (arrayItem, i) => arrayItem + arr2[i] ) } const arraySubtract = (arr1, arr2) => { validateLengths(arr1, arr2, "subtract") return map(arr1, (arrayItem, i) => arrayItem - arr2[i] ) } const sigmoid = (z) => -
ruemic revised this gist
Feb 13, 2016 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,19 +9,19 @@ const validateLengths = (a,b,action) => { const arrayMultiply = (arr1, arr2) => { validateLengths(arr1,arr2,"mutliply") return reduce(arr1, (accumulator, arrayItem, i) => accumulator += arrayItem * arr2[i] , 0) } const arrayAdd = (arr1, arr2) => { validateLengths(arr1, arr2, "add") return map(arr1, (arrayItem,i) => arrayItem + arr2[i] ) } const arraySubtract = (arr1, arr2) => { validateLengths(arr1, arr2, "subtract") return map(arr1, (arrayItem,i) => arrayItem - arr2[i] ) } const sigmoid = (z) => -
ruemic created this gist
Feb 13, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ const map = require('lodash/map') const reduce = require('lodash/reduce') const validateLengths = (a,b,action) => { if (a.length !== b.length) { throw Error(`Can\'t ${action} arrays of length ${a.length} and ${b.length}`); } } const arrayMultiply = (arr1, arr2) => { validateLengths(arr1,arr2,"mutliply") return arr1.reduce((accumulator, arrayItem, i) => accumulator += arrayItem * arr2[i] , 0) } const arrayAdd = (arr1, arr2) => { validateLengths(arr1, arr2, "add") return arr1.map((arrayItem,i) => arrayItem + arr2[i] ) } const arraySubtract = (arr1, arr2) => { validateLengths(arr1, arr2, "subtract") return arr1.map((arrayItem,i) => arrayItem - arr2[i] ) } const sigmoid = (z) => 1 / (1 + Math.exp(z * -1)) const sigmoidGradient = (z) => sigmoid(z) * (1 - sigmoid(z)) const sigmoidInverse = (a) => Math.log(a) - Math.log(1 - a) exports.arrayMultiply = arrayMultiply; exports.arrayAdd = arrayAdd; exports.arraySubtract = arraySubtract; exports.sigmoid = sigmoid; exports.sigmoidGradient = sigmoidGradient; exports.sigmoidInverse = sigmoidInverse;