Created
May 20, 2021 01:07
-
-
Save Nixinova/e06a47a24c970780c76b5ac652ff9664 to your computer and use it in GitHub Desktop.
Neural network attempts addition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Synaptic = require('synaptic'); | |
const NUM_INPUTS = 2; | |
const HIDDEN = 1; | |
const NUM_OUTPUTS = 1; | |
const network = new Synaptic.Architect.Perceptron( | |
NUM_INPUTS, | |
HIDDEN, | |
NUM_OUTPUTS | |
); | |
const trainingSet = [ | |
{ input: [0.2, 0.2], output: [0.4] }, | |
{ input: [0.1, 0.3], output: [0.4] }, | |
{ input: [0.3, 0.15], output: [0.45] }, | |
{ input: [0.2, 0.25], output: [0.45] }, | |
{ input: [0.01, 0.1], output: [0.11] }, | |
{ input: [0.8, 0.01], output: [0.81] }, | |
{ input: [0.9, 0.1], output: [1] }, | |
{ input: [0.01, 0.99], output: [1] }, | |
{ input: [0.6, 0.4], output: [1] }, | |
{ input: [0.45, 0.5], output: [0.95] }, | |
{ input: [0.47, 0.23], output: [0.7] }, | |
{ input: [0.4, 0.3], output: [0.7] }, | |
{ input: [0.33, 0.3], output: [0.63] }, | |
{ input: [0.42, 0.1], output: [0.52] }, | |
{ input: [0, 0], output: [0] }, | |
{ input: [1, 0], output: [1] } | |
]; | |
const trainer = new Synaptic.Trainer(network); | |
trainer.train(trainingSet, { | |
iterations: 30000, | |
shuffle: true, | |
log: 1000 | |
}); | |
let input = [0.5, 0.45]; | |
let prec = 1e3; | |
console.log(Math.round(network.activate(input) * prec) / prec); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment