Created
January 25, 2013 20:04
-
-
Save kastner/4637397 to your computer and use it in GitHub Desktop.
from here
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 characters
| var textColor = function (bgColor) { | |
| var output = runNetwork(bgColor); | |
| if (output.black > .5) { | |
| return 'black'; | |
| } | |
| return 'white'; | |
| } | |
| var runNetwork = function anonymous(inputs) { | |
| var net = {"layers":[{"r":{},"g":{},"b":{}},{"0":{"bias":10.762609321045387,"weights":{"r":-1.6101593793420965,"g":-8.079421879958582,"b":-7.882746791637501}},"1":{"bias":7.175588252506214,"weights":{"r":-1.0511422879361831,"g":-5.602044992104212,"b":-6.278794890237195}},"2":{"bias":18.851966380700553,"weights":{"r":-7.484336046810216,"g":-15.237355119365034,"b":-3.489557046149576}}},{"black":{"bias":12.649899021596282,"weights":{"0":-10.474642369487578,"1":-7.487009391808981,"2":-19.021313930174223}}}]}; | |
| for(var i = 1; i < net.layers.length; i++) { | |
| var layer = net.layers[i]; | |
| var outputs = {}; | |
| for(var id in layer) { | |
| var node = layer[id]; | |
| var sum = node.bias; | |
| for(var iid in node.weights) | |
| sum += node.weights[iid] * inputs[iid]; | |
| outputs[id] = (1/(1 + Math.exp(-sum))); | |
| } | |
| inputs = outputs; | |
| } | |
| return outputs; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment