layerganza
Version:
A feed-forward neural network with injectable layers, activation functions, and optimizers.
28 lines (27 loc) • 1.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("./index");
const shuffleTrainLog = (epoch, setNumber, inputs, targetOutputs, outputs) => {
// console.log('inputs:', inputs);
let errors = new Array(outputs.length);
for (let i = 0, len = outputs.length; i < len; i++) {
errors[i] = Math.abs(targetOutputs[i] - outputs[i]).toFixed(4);
}
console.log(epoch + ':' + setNumber, 'errors', errors);
};
//Create the model
let network = new index_1.Network([
new index_1.InputLayer(2),
new index_1.HiddenLayer(100, new index_1.LeakyRelu(), new index_1.AdamOptimizer()),
new index_1.OutputLayer(6, new index_1.Linear(), new index_1.AdamOptimizer())
]);
//Train the model
let trainingSets = [
[[0, 0], [0, 0, 0, 0, 0, 1]],
[[0, 1], [1, 1, 0, 0, 1, 0]],
[[1, 0], [1, 1, 0, 1, 0, 0]],
[[1, 1], [0, 1, 1, 0, 0, 0]],
];
index_1.shuffleTrain(network, trainingSets, 400, shuffleTrainLog);
//Get some output from the model
//console.log('Output for input [1,1]:', network.invoke([1, 1]));