diff --git a/lib/nn.js b/lib/nn.js index 9461679..f0f607f 100644 --- a/lib/nn.js +++ b/lib/nn.js @@ -6,6 +6,8 @@ var DEFAULT_OPTS = { layers: [ 3 ], // maximum training epochs to perform on the training data iterations: 20000, + // maximum execution time, in seconds + time: Infinity, // minimum acceptable error threshold errorThresh: 0.0005, // activation function ('logistic' and 'hyperbolic' supported) @@ -69,8 +71,9 @@ NN.prototype.train = function (trainingData) { var iterations = this.opts.iterations var totalIterations = 0 var mse = 1 + var startTime = new Date() - while (totalIterations++ < iterations && mse > this.opts.errorThresh) { + while (totalIterations++ < iterations && mse > this.opts.errorThresh && (new Date() - startTime)/1000 < this.opts.time) { // run through the training data trainingData.forEach(function (trainingEntry, index) {