nntsreinforcement
Version:
A Neural Network for Reinforcement Learning in TypeScript
41 lines (40 loc) • 1.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Layer = void 0;
var neuron_1 = require("./neuron");
var Layer = /** @class */ (function () {
function Layer(numOfNeurons, type) {
if (type === void 0) { type = "Type not defined"; }
this.type = type;
this.neurons = [];
for (var i = 0; i < numOfNeurons; i++) {
this.neurons.push(new neuron_1.Neuron(undefined, undefined, type));
}
}
Layer.prototype.setValues = function (data) {
for (var i = 0; i < data.length; i++) {
this.neurons[i].activation = data[i];
}
};
Layer.prototype.compute = function (prevActivations) {
for (var i = 0; i < this.neurons.length; i++) {
this.neurons[i].compute(prevActivations);
}
};
Layer.prototype.getActivations = function () {
var ret = [];
for (var _i = 0, _a = this.neurons; _i < _a.length; _i++) {
var neuron = _a[_i];
ret.push(neuron.activation);
}
return ret;
};
Layer.prototype.mutate = function (rate) {
for (var _i = 0, _a = this.neurons; _i < _a.length; _i++) {
var neuron = _a[_i];
neuron.mutate(rate);
}
};
return Layer;
}());
exports.Layer = Layer;