Skip to content

Instantly share code, notes, and snippets.

@josher19
Created March 22, 2013 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save josher19/5218613 to your computer and use it in GitHub Desktop.
Save josher19/5218613 to your computer and use it in GitHub Desktop.
brain does not likes "0"
// Requires: http://cloud.github.com/downloads/harthur/brain/brain-0.6.0.js
// Contrived example using string "0" as output.
var net = new brain.NeuralNetwork();
net.train([{input: [0, 0], output: {"F":1}},
{input: [0, 1], output: {"1":1}},
{input: [1, 0], output: {"1":1}},
{input: [1, 1], output: {"0":1}}]);
var expected = net.run([1, 0]); // {"0":0.044832217084211604,"1":0.8987734592394667,"F":0.03189275580772041}
// toFunction works normally.
var runner = net.toFunction()
JSON.stringify(runner([1,0])) === JSON.stringify(expected)
// true
// Having a "0" as output causes results of `run` to be converted to an Array when using fromJSON
var net_clone = new brain.NeuralNetwork;
net_clone.fromJSON(net.toJSON())
JSON.stringify(net_clone.run([1,0]))
// "[0.03928773934418956,0.8975583923207543,0.03358100452772138]"
JSON.stringify(net_clone.run([1,0])) == JSON.stringify(expected)
// false!!!
// Work-around: if we use "00" or "#0" or letter "0" instead of number "0" in the output, it works normally.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment