Skip to content

Commit 572e421

Browse files
Merge pull request BrainJS#161 from BrainJS/160-fix-train-opts-legacy
fix legacy to support when no trainOpts are sent in, with test
2 parents e3cbe93 + 4d94d16 commit 572e421

File tree

7 files changed

+67
-87
lines changed

7 files changed

+67
-87
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
"node_modules",
3232
"test"
3333
],
34-
"version": "1.0.5"
34+
"version": "1.1.1"
3535
}

browser.js

Lines changed: 23 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* license: MIT (http://opensource.org/licenses/MIT)
77
* author: Heather Arthur <[email protected]>
88
* homepage: https://github.com/brainjs/brain.js#readme
9-
* version: 1.1.0
9+
* version: 1.1.1
1010
*
1111
* acorn:
1212
* license: MIT (http://opensource.org/licenses/MIT)
@@ -903,7 +903,6 @@ var NeuralNetwork = function () {
903903
/**
904904
*
905905
* @param options
906-
* @param boolean
907906
* @private
908907
*/
909908
value: function _validateTrainingOptions(options) {
@@ -1042,7 +1041,7 @@ var NeuralNetwork = function () {
10421041

10431042
/**
10441043
*
1045-
* @param supported input: ['sigmoid', 'relu', 'leaky-relu', 'tanh']
1044+
* @param activation supported inputs: 'sigmoid', 'relu', 'leaky-relu', 'tanh'
10461045
*/
10471046

10481047
}, {
@@ -1220,12 +1219,12 @@ var NeuralNetwork = function () {
12201219

12211220
/**
12221221
*
1223-
* @param options
1222+
* @param opts
12241223
* Supports all `trainDefaults` properties
12251224
* also supports:
12261225
* learningRate: (number),
12271226
* momentum: (number),
1228-
* activation: ['sigmoid', 'relu', 'leaky-relu', 'tanh']
1227+
* activation: 'sigmoid', 'relu', 'leaky-relu', 'tanh'
12291228
*/
12301229

12311230
}, {
@@ -1282,8 +1281,7 @@ var NeuralNetwork = function () {
12821281
/**
12831282
*
12841283
* @param data
1285-
* @param learning Rate
1286-
* @returns error
1284+
* @returns number
12871285
*/
12881286

12891287
}, {
@@ -1298,8 +1296,9 @@ var NeuralNetwork = function () {
12981296

12991297
/**
13001298
*
1301-
* @param status { iterations: number, error: number}
1302-
* @param options
1299+
* @param {object} data
1300+
* @param {object} status { iterations: number, error: number }
1301+
* @param endTime
13031302
*/
13041303

13051304
}, {
@@ -1327,7 +1326,7 @@ var NeuralNetwork = function () {
13271326
* @param data
13281327
* @param options
13291328
* @private
1330-
* @return {{runTrainingTick: function, status: {error: number, iterations: number}}}
1329+
* @return {object}
13311330
*/
13321331

13331332
}, {
@@ -1438,8 +1437,7 @@ var NeuralNetwork = function () {
14381437
this.calculateDeltas(target);
14391438
this._adjustWeights();
14401439

1441-
var error = (0, _mse2.default)(this.errors[this.outputLayer]);
1442-
return error;
1440+
return (0, _mse2.default)(this.errors[this.outputLayer]);
14431441
}
14441442

14451443
/**
@@ -1830,8 +1828,10 @@ var NeuralNetwork = function () {
18301828
}
18311829
}
18321830
}
1833-
this._updateTrainingOptions(json.trainOpts);
1834-
this.setActivation();
1831+
if (json.hasOwnProperty('trainOpts')) {
1832+
this._updateTrainingOptions(json.trainOpts);
1833+
}
1834+
this.setActivation(this.activation || 'sigmoid');
18351835
return this;
18361836
}
18371837

@@ -13286,7 +13286,6 @@ module.exports = function () {
1328613286
this.addFunction = null;
1328713287
this.functions = null;
1328813288
this.nativeFunctions = null;
13289-
this.copyData = true;
1329013289
this.subKernels = null;
1329113290
this.subKernelProperties = null;
1329213291
this.subKernelNames = null;
@@ -13549,12 +13548,6 @@ module.exports = function () {
1354913548
this._webGl = webGl;
1355013549
return this;
1355113550
}
13552-
}, {
13553-
key: 'setCopyData',
13554-
value: function setCopyData(copyData) {
13555-
this.copyData = copyData;
13556-
return this;
13557-
}
1355813551

1355913552
/**
1356013553
* @memberOf BaseKernel#
@@ -15473,7 +15466,7 @@ module.exports = function (_KernelBase) {
1547315466
var output = [];
1547415467
output.result = this.renderOutput(outputTexture);
1547515468
for (var _i = 0; _i < this.subKernels.length; _i++) {
15476-
output.push(new Texture(this.subKernelOutputTextures[_i], texSize, this.output, this._webGl));
15469+
output.push(new Texture(this.subKernelOutputTextures[_i], texSize, this.threadDim, this.output, this._webGl));
1547715470
}
1547815471
return output;
1547915472
} else if (this.subKernelProperties !== null) {
@@ -15483,7 +15476,7 @@ module.exports = function (_KernelBase) {
1548315476
var _i2 = 0;
1548415477
for (var p in this.subKernelProperties) {
1548515478
if (!this.subKernelProperties.hasOwnProperty(p)) continue;
15486-
_output[p] = new Texture(this.subKernelOutputTextures[_i2], texSize, this.output, this._webGl);
15479+
_output[p] = new Texture(this.subKernelOutputTextures[_i2], texSize, this.threadDim, this.output, this._webGl);
1548715480
_i2++;
1548815481
}
1548915482
return _output;
@@ -15520,7 +15513,7 @@ module.exports = function (_KernelBase) {
1552015513
var threadDim = this.threadDim;
1552115514
var output = this.output;
1552215515
if (this.outputToTexture) {
15523-
return new Texture(outputTexture, texSize, output, this._webGl);
15516+
return new Texture(outputTexture, texSize, this.threadDim, output, this._webGl);
1552415517
} else {
1552515518
var result = void 0;
1552615519
if (this.floatOutput) {
@@ -15646,25 +15639,6 @@ module.exports = function (_KernelBase) {
1564615639

1564715640
/**
1564815641
* @memberOf WebGLKernel#
15649-
* @name getSubKernelTexture
15650-
* @function
15651-
*
15652-
* @desc This uses *getTextureCache* to get the Texture Cache of the sub-kernel
15653-
*
15654-
* @param {String} name - Name of the subKernel
15655-
*
15656-
* @returns {Object} Texture cache for the subKernel
15657-
*
15658-
*/
15659-
15660-
}, {
15661-
key: 'getSubKernelTexture',
15662-
value: function getSubKernelTexture(name) {
15663-
return this.getTextureCache('SUB_KERNEL_' + name);
15664-
}
15665-
15666-
/**
15667-
* @memberOf WebGLKernel#
1566815642
* @name getTextureCache
1566915643
* @function
1567015644
*
@@ -15679,10 +15653,6 @@ module.exports = function (_KernelBase) {
1567915653
}, {
1568015654
key: 'getTextureCache',
1568115655
value: function getTextureCache(name) {
15682-
if (this.outputToTexture) {
15683-
// Don't retain a handle on the output texture, we might need to render on the same texture later
15684-
return this._webGl.createTexture();
15685-
}
1568615656
if (this.textureCache.hasOwnProperty(name)) {
1568715657
return this.textureCache[name];
1568815658
}
@@ -15873,8 +15843,7 @@ module.exports = function (_KernelBase) {
1587315843
case 'Texture':
1587415844
{
1587515845
var inputTexture = value;
15876-
var _dim2 = utils.getDimensions(inputTexture, true);
15877-
15846+
var _dim2 = inputTexture.dimensions;
1587815847
var _size2 = inputTexture.size;
1587915848

1588015849
gl.activeTexture(gl.TEXTURE0 + this.argumentsLength);
@@ -17076,16 +17045,18 @@ module.exports = function () {
1707617045
/**
1707717046
* @desc WebGl Texture implementation in JS
1707817047
* @constructor Texture
17079-
* @param {Object} texture
17080-
* @param {Array} size
17048+
* @param {Object} texture
17049+
* @param {Array} size
17050+
* @param dimensions
1708117051
* @param {Array} output
1708217052
* @param {Object} webGl
1708317053
*/
17084-
function Texture(texture, size, output, webGl) {
17054+
function Texture(texture, size, dimensions, output, webGl) {
1708517055
_classCallCheck(this, Texture);
1708617056

1708717057
this.texture = texture;
1708817058
this.size = size;
17059+
this.dimensions = dimensions;
1708917060
this.output = output;
1709017061
this.webGl = webGl;
1709117062
this.kernel = null;

dist/neural-network.js

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/neural-network.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "brain.js",
33
"description": "Neural network library",
4-
"version": "1.1.0",
4+
"version": "1.1.1",
55
"author": "Heather Arthur <[email protected]>",
66
"repository": {
77
"type": "git",

0 commit comments

Comments
 (0)