Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/nn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down