Skip to content

Commit bc18f46

Browse files
committed
Missed a _updateTrainingOpts in the merge, remade browser and dist
1 parent 86edaf3 commit bc18f46

File tree

5 files changed

+63
-154
lines changed

5 files changed

+63
-154
lines changed

browser.js

Lines changed: 29 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ var NeuralNetwork = function () {
930930
Object.assign(this, this.constructor.defaults, options);
931931
this.hiddenSizes = options.hiddenLayers;
932932
this.trainOpts = {};
933-
this.updateTrainingOptions(Object.assign({}, this.constructor.trainDefaults, options));
933+
this._updateTrainingOptions(Object.assign({}, this.constructor.trainDefaults, options));
934934

935935
this.sizes = null;
936936
this.outputLayer = null;
@@ -1183,38 +1183,15 @@ var NeuralNetwork = function () {
11831183
*/
11841184

11851185
}, {
1186-
key: 'updateTrainingOptions',
1187-
value: function updateTrainingOptions(opts) {
1188-
if (opts.iterations) {
1189-
this.trainOpts.iterations = opts.iterations;
1190-
}
1191-
if (opts.errorThresh) {
1192-
this.trainOpts.errorThresh = opts.errorThresh;
1193-
}
1194-
if (opts.log) {
1195-
this._setLogMethod(opts.log);
1196-
}
1197-
if (opts.logPeriod) {
1198-
this.trainOpts.logPeriod = opts.logPeriod;
1199-
}
1200-
if (opts.learningRate) {
1201-
this.trainOpts.learningRate = opts.learningRate;
1202-
}
1203-
if (opts.momentum) {
1204-
this.trainOpts.momentum = opts.momentum;
1205-
}
1206-
if (opts.callback) {
1207-
this.trainOpts.callback = opts.callback;
1208-
}
1209-
if (opts.callbackPeriod) {
1210-
this.trainOpts.callbackPeriod = opts.callbackPeriod;
1211-
}
1212-
if (opts.timeout) {
1213-
this.trainOpts.timeout = opts.timeout;
1214-
}
1215-
if (opts.activation) {
1216-
this.activation = opts.activation;
1217-
}
1186+
key: '_updateTrainingOptions',
1187+
value: function _updateTrainingOptions(opts) {
1188+
var _this2 = this;
1189+
1190+
Object.keys(NeuralNetwork.trainDefaults).forEach(function (opt) {
1191+
return _this2.trainOpts[opt] = opts[opt] || _this2.trainOpts[opt];
1192+
});
1193+
this._setLogMethod(opts.log || this.trainOpts.log);
1194+
this.activation = opts.activation || this.activation;
12181195
}
12191196

12201197
/**
@@ -1226,35 +1203,13 @@ var NeuralNetwork = function () {
12261203
}, {
12271204
key: '_getTrainOptsJSON',
12281205
value: function _getTrainOptsJSON() {
1229-
var results = {};
1230-
if (this.trainOpts.iterations) {
1231-
results.iterations = this.trainOpts.iterations;
1232-
}
1233-
if (this.trainOpts.errorThresh) {
1234-
results.errorThresh = this.trainOpts.errorThresh;
1235-
}
1236-
if (this.trainOpts.logPeriod) {
1237-
results.logPeriod = this.trainOpts.logPeriod;
1238-
}
1239-
if (this.trainOpts.learningRate) {
1240-
results.learningRate = this.trainOpts.learningRate;
1241-
}
1242-
if (this.trainOpts.momentum) {
1243-
results.momentum = this.trainOpts.momentum;
1244-
}
1245-
if (this.trainOpts.callback) {
1246-
results.callback = this.trainOpts.callback;
1247-
}
1248-
if (this.trainOpts.callbackPeriod) {
1249-
results.callbackPeriod = this.trainOpts.callbackPeriod;
1250-
}
1251-
if (this.trainOpts.timeout) {
1252-
results.timeout = this.trainOpts.timeout;
1253-
}
1254-
if (this.trainOpts.log) {
1255-
results.log = true;
1256-
}
1257-
return results;
1206+
var _this3 = this;
1207+
1208+
return Object.keys(NeuralNetwork.trainDefaults).reduce(function (opts, opt) {
1209+
if (_this3.trainOpts[opt]) opts[opt] = _this3.trainOpts[opt];
1210+
if (opt === 'log') opts.log = typeof opts.log === 'function';
1211+
return opts;
1212+
}, {});
12581213
}
12591214

12601215
/**
@@ -1387,7 +1342,7 @@ var NeuralNetwork = function () {
13871342
}, {
13881343
key: 'trainAsync',
13891344
value: function trainAsync(data) {
1390-
var _this2 = this;
1345+
var _this4 = this;
13911346

13921347
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
13931348

@@ -1403,10 +1358,10 @@ var NeuralNetwork = function () {
14031358

14041359
return new Promise(function (resolve, reject) {
14051360
try {
1406-
var thawedTrain = new _thaw2.default(new Array(_this2.trainOpts.iterations), {
1361+
var thawedTrain = new _thaw2.default(new Array(_this4.trainOpts.iterations), {
14071362
delay: true,
14081363
each: function each() {
1409-
return _this2._trainingTick(data, status, endTime) || thawedTrain.stop();
1364+
return _this4._trainingTick(data, status, endTime) || thawedTrain.stop();
14101365
},
14111366
done: function done() {
14121367
return resolve(status);
@@ -1584,7 +1539,7 @@ var NeuralNetwork = function () {
15841539
}, {
15851540
key: '_formatData',
15861541
value: function _formatData(data) {
1587-
var _this3 = this;
1542+
var _this5 = this;
15881543

15891544
if (!Array.isArray(data)) {
15901545
// turn stream datum into array
@@ -1601,7 +1556,7 @@ var NeuralNetwork = function () {
16011556
}));
16021557
}
16031558
data = data.map(function (datum) {
1604-
var array = _lookup2.default.toArray(_this3.inputLookup, datum.input);
1559+
var array = _lookup2.default.toArray(_this5.inputLookup, datum.input);
16051560
return Object.assign({}, datum, { input: array });
16061561
}, this);
16071562
}
@@ -1613,7 +1568,7 @@ var NeuralNetwork = function () {
16131568
}));
16141569
}
16151570
data = data.map(function (datum) {
1616-
var array = _lookup2.default.toArray(_this3.outputLookup, datum.output);
1571+
var array = _lookup2.default.toArray(_this5.outputLookup, datum.output);
16171572
return Object.assign({}, datum, { output: array });
16181573
}, this);
16191574
}
@@ -1634,7 +1589,7 @@ var NeuralNetwork = function () {
16341589
}, {
16351590
key: 'test',
16361591
value: function test(data) {
1637-
var _this4 = this;
1592+
var _this6 = this;
16381593

16391594
data = this._formatData(data);
16401595

@@ -1653,13 +1608,13 @@ var NeuralNetwork = function () {
16531608
var sum = 0;
16541609

16551610
var _loop = function _loop(i) {
1656-
var output = _this4.runInput(data[i].input);
1611+
var output = _this6.runInput(data[i].input);
16571612
var target = data[i].output;
16581613

16591614
var actual = void 0,
16601615
expected = void 0;
16611616
if (isBinary) {
1662-
actual = output[0] > _this4.binaryThresh ? 1 : 0;
1617+
actual = output[0] > _this6.binaryThresh ? 1 : 0;
16631618
expected = target[0];
16641619
} else {
16651620
actual = output.indexOf((0, _max2.default)(output));
@@ -1828,7 +1783,7 @@ var NeuralNetwork = function () {
18281783
}
18291784
}
18301785
}
1831-
this.updateTrainingOptions(json.trainOpts);
1786+
this._updateTrainingOptions(json.trainOpts);
18321787
this.setActivation();
18331788
return this;
18341789
}
@@ -1906,15 +1861,15 @@ var NeuralNetwork = function () {
19061861
}, {
19071862
key: 'isRunnable',
19081863
get: function get() {
1909-
var _this5 = this;
1864+
var _this7 = this;
19101865

19111866
if (!this.runInput) {
19121867
console.error('Activation function has not been initialized, did you run train()?');
19131868
return false;
19141869
}
19151870

19161871
var checkFns = ['sizes', 'outputLayer', 'biases', 'weights', 'outputs', 'deltas', 'changes', 'errors'].filter(function (c) {
1917-
return _this5[c] === null;
1872+
return _this7[c] === null;
19181873
});
19191874

19201875
if (checkFns.length > 0) {

0 commit comments

Comments
 (0)