Comparing version
@@ -22,4 +22,6 @@ var _ = require("underscore")._; | ||
learningRate: classifier.learningRate, | ||
hidden: classifier.hiddenSizes | ||
hidden: classifier.hiddenSizes, | ||
network: classifier.toJSON() | ||
}); | ||
return stats; | ||
@@ -41,8 +43,13 @@ } | ||
iterations: 0, | ||
trainError: 0, | ||
precision: 0, | ||
accuracy: 0, | ||
recall: 0 | ||
trainError: 0 | ||
}; | ||
var stats = { | ||
truePos: 0, | ||
trueNeg: 0, | ||
falsePos: 0, | ||
falseNeg: 0, | ||
total: 0 | ||
}; | ||
var misclasses = []; | ||
@@ -57,7 +64,13 @@ | ||
_(avgs).each(function(sum, i) { | ||
avgs[i] = sum + result[i]; | ||
_(avgs).each(function(sum, stat) { | ||
avgs[stat] = sum + result[stat]; | ||
}); | ||
_(stats).each(function(sum, stat) { | ||
stats[stat] = sum + result[stat]; | ||
}) | ||
misclasses.push(result.misclasses); | ||
return result; | ||
}); | ||
@@ -69,9 +82,15 @@ | ||
avgs.testSize = size; | ||
avgs.trainSize = data.length - size; | ||
stats.precision = stats.truePos / (stats.truePos + stats.falsePos); | ||
stats.recall = stats.truePos / (stats.truePos + stats.falseNeg); | ||
stats.accuracy = (stats.trueNeg + stats.truePos) / stats.total; | ||
stats.testSize = size; | ||
stats.trainSize = data.length - size; | ||
return { | ||
avgs: avgs, | ||
stats: stats, | ||
sets: results, | ||
misclasses: _(misclasses).flatten() | ||
}; | ||
} |
@@ -364,17 +364,20 @@ var _ = require("underscore"), | ||
// return standalone function that mimics run() | ||
return new Function("inputs", | ||
return new Function("input", | ||
' var net = ' + JSON.stringify(json) + ';\n\n\ | ||
for(var i = 1; i < net.layers.length; i++) {\n\ | ||
for (var i = 1; i < net.layers.length; i++) {\n\ | ||
var layer = net.layers[i];\n\ | ||
var outputs = {};\n\ | ||
for(var id in layer) {\n\ | ||
var output = {};\n\ | ||
\n\ | ||
for (var id in layer) {\n\ | ||
var node = layer[id];\n\ | ||
var sum = node.bias;\n\ | ||
for(var iid in node.weights)\n\ | ||
sum += node.weights[iid] * inputs[iid];\n\ | ||
outputs[id] = (1/(1 + Math.exp(-sum)));\n\ | ||
\n\ | ||
for (var iid in node.weights) {\n\ | ||
sum += node.weights[iid] * input[iid];\n\ | ||
}\n\ | ||
output[id] = (1 / (1 + Math.exp(-sum)));\n\ | ||
}\n\ | ||
inputs = outputs;\n\ | ||
input = output;\n\ | ||
}\n\ | ||
return outputs;'); | ||
return output;'); | ||
} | ||
@@ -381,0 +384,0 @@ } |
{ | ||
"name": "brain", | ||
"description": "Neural network library", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"author": "Heather Arthur <fayearthur@gmail.com>", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -16,3 +16,3 @@ # brain | ||
There's no reason to use a neural network to figure out XOR however (-: so here's a more involved, realistic example: | ||
[Demo: training a neural network to recognize color contrast](http://harthur.github.com/brain/examples/blackorwhite.html) | ||
[Demo: training a neural network to recognize color contrast](http://harthur.github.com/brain/) | ||
@@ -31,3 +31,3 @@ # Using in node | ||
#### Data format | ||
Each training pattern should have an `input` and an `output`, both of which can be either an array of numbers from `0` to `1` or a hash of numbers from `0` to `1`. For the [color constrast demo](http://harthur.github.com/brain/examples/blackorwhite.html) it looks something like this: | ||
Each training pattern should have an `input` and an `output`, both of which can be either an array of numbers from `0` to `1` or a hash of numbers from `0` to `1`. For the [color constrast demo](http://harthur.github.com/brain/) it looks something like this: | ||
@@ -34,0 +34,0 @@ ```javascript |
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
3552
0.71%5
-16.67%158761
-13.11%24
-11.11%