Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added max computation time option #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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