Created
May 10, 2014 02:24
-
-
Save jesvs/83ecfe01e0a58a221320 to your computer and use it in GitHub Desktop.
This file contains 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 characters
var textColor = function (bgColor) { | |
var output = runNetwork(bgColor); | |
if (output.black > .5) { | |
return 'black'; | |
} | |
return 'white'; | |
} | |
var runNetwork = function anonymous(input | |
/**/) { | |
var net = {"layers":[{"r":{},"g":{},"b":{}},{"0":{"bias":7.033599782111697,"weights":{"r":-0.6584023522497092,"g":-9.131572195766312,"b":-1.484211549994347}},"1":{"bias":-1.5180984361560637,"weights":{"r":0.4747268806134254,"g":2.730146205939069,"b":0.6702867737577332}},"2":{"bias":3.687254520355556,"weights":{"r":-0.44971489887101657,"g":-5.102605895582099,"b":-0.8970959129419429}}},{"black":{"bias":3.3101676819516674,"weights":{"0":-11.13417539480403,"1":5.020650886600332,"2":-6.059263260100297}}}],"outputLookup":true,"inputLookup":true}; | |
for (var i = 1; i < net.layers.length; i++) { | |
var layer = net.layers[i]; | |
var output = {}; | |
for (var id in layer) { | |
var node = layer[id]; | |
var sum = node.bias; | |
for (var iid in node.weights) { | |
sum += node.weights[iid] * input[iid]; | |
} | |
output[id] = (1 / (1 + Math.exp(-sum))); | |
} | |
input = output; | |
} | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment