Skip to content

Commit

Permalink
updated to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
robertleeplummerjr committed Mar 1, 2018
1 parent e79b3d8 commit 0e70c77
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 91 deletions.
57 changes: 29 additions & 28 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,6 @@ var _gpu = require('gpu.js');

var _gpu2 = _interopRequireDefault(_gpu);

var _thaw = require('thaw.js');

var _thaw2 = _interopRequireDefault(_thaw);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Expand Down Expand Up @@ -503,9 +499,6 @@ var NeuralNetworkGPU = function (_NeuralNetwork) {
return null;
}
}
}, {
key: 'train',
value: function train() {}
}, {
key: 'trainAsync',
value: function trainAsync(data, options) {
Expand All @@ -521,14 +514,16 @@ var NeuralNetworkGPU = function (_NeuralNetwork) {
endTime = _prepTraining.endTime;


var train = function train() {
if (_this2._trainingTick(data, status, endTime)) {
options.done();
} else {
requestAnimationFrame(train);
}
};
train();
return new Promise(function (resolve, reject) {
var train = function train() {
if (_this2._trainingTick(data, status, endTime)) {
requestAnimationFrame(train);
} else {
resolve(status);
}
};
train();
});
}
}, {
key: 'buildRunInput',
Expand Down Expand Up @@ -560,7 +555,8 @@ var NeuralNetworkGPU = function (_NeuralNetwork) {
hardcodeConstants: true,
constants: {
size: this.sizes[layer - 1]
}
},
floatTextures: true
});
}
}
Expand Down Expand Up @@ -617,7 +613,8 @@ var NeuralNetworkGPU = function (_NeuralNetwork) {
output: [this.sizes[layer]],
outputToTexture: true,
outputImmutable: true,
hardcodeConstants: true
hardcodeConstants: true,
floatTextures: true
});
} else {
this.backwardPropagate[layer] = this.gpu.createKernelMap({
Expand All @@ -633,7 +630,8 @@ var NeuralNetworkGPU = function (_NeuralNetwork) {
hardcodeConstants: true,
constants: {
size: this.deltas[layer + 1].length
}
},
floatTextures: true
});
}
}
Expand Down Expand Up @@ -673,7 +671,8 @@ var NeuralNetworkGPU = function (_NeuralNetwork) {
size: this.outputs[layer - 1].length,
learningRate: this.trainOpts.learningRate,
momentum: this.trainOpts.momentum
}
},
floatTextures: true
});
}
}
Expand All @@ -697,7 +696,8 @@ var NeuralNetworkGPU = function (_NeuralNetwork) {
hardcodeConstants: true,
constants: {
learningRate: this.trainOpts.learningRate
}
},
floatTextures: true
});
}
}
Expand All @@ -715,7 +715,8 @@ var NeuralNetworkGPU = function (_NeuralNetwork) {
output: [1],
constants: {
size: this.sizes[this.outputLayer]
}
},
floatTextures: true
});
}

Expand Down Expand Up @@ -912,7 +913,7 @@ function mse(errors) {
return sum / this.constants.size;
}

},{"./lookup":3,"./neural-network":5,"gpu.js":75,"thaw.js":100}],5:[function(require,module,exports){
},{"./lookup":3,"./neural-network":5,"gpu.js":75}],5:[function(require,module,exports){
'use strict';

Object.defineProperty(exports, "__esModule", {
Expand Down Expand Up @@ -1349,14 +1350,14 @@ var NeuralNetwork = function () {
status.iterations++;

if (this.trainOpts.log && status.iterations % this.trainOpts.logPeriod === 0) {
status.error = this._calculateTrainingError(data);
// status.error = this._calculateTrainingError(data);
this.trainOpts.log('iterations: ' + status.iterations + ', training error: ' + status.error);
} else {
if (status.iterations % 100 === 0) {
status.error = this._calculateTrainingError(data);
} else {
this._trainPatterns(data);
}
// if (status.iterations % 100 === 0) {
// status.error = this._calculateTrainingError(data);
// } else {
this._trainPatterns(data);
// }
}

if (this.trainOpts.callback && status.iterations % this.trainOpts.callbackPeriod === 0) {
Expand Down
8 changes: 4 additions & 4 deletions browser.min.js

Large diffs are not rendered by default.

43 changes: 22 additions & 21 deletions dist/neural-network-gpu.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/neural-network-gpu.js.map

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions dist/neural-network.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/neural-network.js.map

Large diffs are not rendered by default.

39 changes: 22 additions & 17 deletions src/neural-network-gpu.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import NeuralNetwork from './neural-network';
import lookup from './lookup';
import GPU from 'gpu.js';
import Thaw from "thaw.js";

/**
*
Expand Down Expand Up @@ -55,20 +54,20 @@ export default class NeuralNetworkGPU extends NeuralNetwork {
}
}

train() {}

trainAsync(data, options) {
let status, endTime;
({ data, status, endTime } = this._prepTraining(data, options));

const train = () => {
if (this._trainingTick(data, status, endTime)) {
options.done();
} else {
requestAnimationFrame(train);
}
};
train();
return new Promise((resolve, reject) => {
const train = () => {
if (this._trainingTick(data, status, endTime)) {
requestAnimationFrame(train);
} else {
resolve(status);
}
};
train();
});
}

buildRunInput() {
Expand Down Expand Up @@ -99,7 +98,8 @@ export default class NeuralNetworkGPU extends NeuralNetwork {
hardcodeConstants: true,
constants: {
size: this.sizes[layer - 1]
}
},
floatTextures: true
});
}
}
Expand Down Expand Up @@ -156,7 +156,8 @@ export default class NeuralNetworkGPU extends NeuralNetwork {
output: [this.sizes[layer]],
outputToTexture: true,
outputImmutable: true,
hardcodeConstants: true
hardcodeConstants: true,
floatTextures: true
});
} else {
this.backwardPropagate[layer] = this.gpu.createKernelMap({
Expand All @@ -172,7 +173,8 @@ export default class NeuralNetworkGPU extends NeuralNetwork {
hardcodeConstants: true,
constants: {
size: this.deltas[layer + 1].length
}
},
floatTextures: true
});
}
}
Expand Down Expand Up @@ -220,7 +222,8 @@ export default class NeuralNetworkGPU extends NeuralNetwork {
size: this.outputs[layer - 1].length,
learningRate: this.trainOpts.learningRate,
momentum: this.trainOpts.momentum
}
},
floatTextures: true
});
}
}
Expand All @@ -247,7 +250,8 @@ export default class NeuralNetworkGPU extends NeuralNetwork {
hardcodeConstants: true,
constants: {
learningRate: this.trainOpts.learningRate
}
},
floatTextures: true
});
}
}
Expand All @@ -266,7 +270,8 @@ export default class NeuralNetworkGPU extends NeuralNetwork {
output: [1],
constants: {
size: this.sizes[this.outputLayer]
}
},
floatTextures: true
});
}

Expand Down
10 changes: 5 additions & 5 deletions src/neural-network.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,14 @@ export default class NeuralNetwork {
status.iterations++;

if (this.trainOpts.log && (status.iterations % this.trainOpts.logPeriod === 0)) {
status.error = this._calculateTrainingError(data);
// status.error = this._calculateTrainingError(data);
this.trainOpts.log(`iterations: ${status.iterations}, training error: ${status.error}`);
} else {
if (status.iterations % 100 === 0) {
status.error = this._calculateTrainingError(data);
} else {
// if (status.iterations % 100 === 0) {
// status.error = this._calculateTrainingError(data);
// } else {
this._trainPatterns(data);
}
// }
}

if (this.trainOpts.callback && (status.iterations % this.trainOpts.callbackPeriod === 0)) {
Expand Down
Loading

0 comments on commit 0e70c77

Please sign in to comment.