BrainJS / brain.js

🤖 GPU accelerated Neural networks in JavaScript for Browsers and Node.js
https://brain.js.org
MIT License
14.35k stars 1.07k forks source link

Always the same output data on NeuralNetwork #913

Closed Ealenn closed 10 months ago

Ealenn commented 11 months ago

A GIF or MEME to give some spice of the internet

What is wrong?

Hi!

I'm trying to train a pretty simple neural network, but no matter what I do, I always get the same results/prediction.

I don't know what I'm doing wrong, I've tried every configuration possible...

How do we replicate the issue?

I don't know enough jsfiddle to setup one quickly, but here's a simplification of my code.

And as you'll see, the results are always the same, whatever the input.

Node Example ```js const brain = require("brain.js"); const net = new brain.NeuralNetwork({}); net.train([{ input: { day: 1, month: 2, year: 2017 }, output: { '16': 1, '20': 1, '31': 1, '33': 1, '46': 1 } }, { input: { day: 27, month: 1, year: 2017 }, output: { '3': 1, '16': 1, '17': 1, '37': 1, '47': 1 } }, { input: { day: 25, month: 1, year: 2017 }, output: { '11': 1, '32': 1, '40': 1, '43': 1, '48': 1 } }, { input: { day: 22, month: 1, year: 2017 }, output: { '17': 1, '22': 1, '25': 1, '35': 1, '43': 1 } }, { input: { day: 20, month: 1, year: 2017 }, output: { '15': 1, '20': 1, '29': 1, '41': 1, '43': 1 } }, { input: { day: 18, month: 1, year: 2017 }, output: { '1': 1, '3': 1, '23': 1, '32': 1, '49': 1 } }, { input: { day: 15, month: 1, year: 2017 }, output: { '8': 1, '14': 1, '16': 1, '21': 1, '24': 1 } }, { input: { day: 13, month: 1, year: 2017 }, output: { '5': 1, '16': 1, '18': 1, '39': 1, '44': 1 } }, { input: { day: 11, month: 1, year: 2017 }, output: { '1': 1, '15': 1, '17': 1, '29': 1, '37': 1 } }, { input: { day: 8, month: 1, year: 2017 }, output: { '17': 1, '19': 1, '33': 1, '37': 1, '40': 1 } }, { input: { day: 6, month: 1, year: 2017 }, output: { '19': 1, '30': 1, '31': 1, '33': 1, '40': 1 } }, { input: { day: 4, month: 1, year: 2017 }, output: { '1': 1, '22': 1, '32': 1, '35': 1, '37': 1 } }, { input: { day: 1, month: 1, year: 2017 }, output: { '9': 1, '17': 1, '24': 1, '45': 1, '46': 1 } }, { input: { day: 30, month: 0, year: 2017 }, output: { '4': 1, '22': 1, '23': 1, '32': 1, '40': 1 } }, { input: { day: 28, month: 0, year: 2017 }, output: { '2': 1, '5': 1, '6': 1, '10': 1, '26': 1 } }, { input: { day: 25, month: 0, year: 2017 }, output: { '4': 1, '10': 1, '19': 1, '20': 1, '28': 1 } }, { input: { day: 23, month: 0, year: 2017 }, output: { '5': 1, '15': 1, '17': 1, '31': 1, '49': 1 } }, { input: { day: 21, month: 0, year: 2017 }, output: { '8': 1, '31': 1, '32': 1, '36': 1, '40': 1 } }, { input: { day: 18, month: 0, year: 2017 }, output: { '5': 1, '29': 1, '34': 1, '47': 1, '48': 1 } }, { input: { day: 16, month: 0, year: 2017 }, output: { '14': 1, '26': 1, '32': 1, '35': 1, '37': 1 } }, { input: { day: 14, month: 0, year: 2017 }, output: { '16': 1, '18': 1, '19': 1, '37': 1, '44': 1 } }, { input: { day: 11, month: 0, year: 2017 }, output: { '13': 1, '19': 1, '22': 1, '28': 1, '30': 1 } }, { input: { day: 9, month: 0, year: 2017 }, output: { '2': 1, '6': 1, '16': 1, '21': 1, '42': 1 } }, { input: { day: 7, month: 0, year: 2017 }, output: { '21': 1, '22': 1, '24': 1, '33': 1, '46': 1 } }, { input: { day: 4, month: 0, year: 2017 }, output: { '16': 1, '17': 1, '26': 1, '36': 1, '38': 1 } }, { input: { day: 2, month: 0, year: 2017 }, output: { '11': 1, '19': 1, '31': 1, '38': 1, '40': 1 } }, { input: { day: 31, month: 11, year: 2016 }, output: { '4': 1, '33': 1, '43': 1, '45': 1, '49': 1 } }, { input: { day: 28, month: 11, year: 2016 }, output: { '15': 1, '16': 1, '34': 1, '35': 1, '39': 1 } }, { input: { day: 26, month: 11, year: 2016 }, output: { '3': 1, '16': 1, '27': 1, '29': 1, '37': 1 } }, { input: { day: 24, month: 11, year: 2016 }, output: { '7': 1, '20': 1, '22': 1, '35': 1, '48': 1 } }, { input: { day: 21, month: 11, year: 2016 }, output: { '17': 1, '22': 1, '25': 1, '39': 1, '42': 1 } }, { input: { day: 19, month: 11, year: 2016 }, output: { '3': 1, '17': 1, '26': 1, '40': 1, '41': 1 } }, { input: { day: 17, month: 11, year: 2016 }, output: { '2': 1, '5': 1, '13': 1, '16': 1, '32': 1 } }, { input: { day: 14, month: 11, year: 2016 }, output: { '9': 1, '10': 1, '14': 1, '44': 1, '46': 1 } }, { input: { day: 12, month: 11, year: 2016 }, output: { '6': 1, '11': 1, '12': 1, '14': 1, '36': 1 } }, { input: { day: 10, month: 11, year: 2016 }, output: { '24': 1, '27': 1, '28': 1, '41': 1, '43': 1 } }, { input: { day: 7, month: 11, year: 2016 }, output: { '2': 1, '5': 1, '7': 1, '44': 1, '45': 1 } }, { input: { day: 5, month: 11, year: 2016 }, output: { '6': 1, '23': 1, '26': 1, '29': 1, '30': 1 } }, { input: { day: 3, month: 11, year: 2016 }, output: { '4': 1, '11': 1, '13': 1, '38': 1, '44': 1 } }, { input: { day: 30, month: 10, year: 2016 }, output: { '3': 1, '9': 1, '31': 1, '33': 1, '40': 1 } }, { input: { day: 28, month: 10, year: 2016 }, output: { '10': 1, '20': 1, '38': 1, '41': 1, '45': 1 } }, { input: { day: 26, month: 10, year: 2016 }, output: { '6': 1, '9': 1, '11': 1, '21': 1, '44': 1 } }, { input: { day: 23, month: 10, year: 2016 }, output: { '2': 1, '7': 1, '12': 1, '25': 1, '47': 1 } }, { input: { day: 21, month: 10, year: 2016 }, output: { '3': 1, '7': 1, '12': 1, '18': 1, '45': 1 } }, { input: { day: 19, month: 10, year: 2016 }, output: { '34': 1, '36': 1, '41': 1, '46': 1, '48': 1 } }, { input: { day: 16, month: 10, year: 2016 }, output: { '1': 1, '24': 1, '26': 1, '37': 1, '48': 1 } }, { input: { day: 14, month: 10, year: 2016 }, output: { '6': 1, '14': 1, '16': 1, '26': 1, '41': 1 } }, { input: { day: 12, month: 10, year: 2016 }, output: { '2': 1, '11': 1, '16': 1, '19': 1, '29': 1 } }, { input: { day: 9, month: 10, year: 2016 }, output: { '3': 1, '8': 1, '14': 1, '22': 1, '47': 1 } }, { input: { day: 7, month: 10, year: 2016 }, output: { '1': 1, '6': 1, '21': 1, '31': 1, '46': 1 } }, { input: { day: 5, month: 10, year: 2016 }, output: { '6': 1, '16': 1, '21': 1, '34': 1, '42': 1 } }, { input: { day: 2, month: 10, year: 2016 }, output: { '1': 1, '7': 1, '14': 1, '26': 1, '49': 1 } }, { input: { day: 31, month: 9, year: 2016 }, output: { '11': 1, '16': 1, '29': 1, '35': 1, '41': 1 } }, { input: { day: 29, month: 9, year: 2016 }, output: { '14': 1, '21': 1, '26': 1, '36': 1, '44': 1 } }, { input: { day: 26, month: 9, year: 2016 }, output: { '1': 1, '20': 1, '35': 1, '40': 1, '46': 1 } }, { input: { day: 24, month: 9, year: 2016 }, output: { '17': 1, '18': 1, '23': 1, '29': 1, '36': 1 } }, { input: { day: 22, month: 9, year: 2016 }, output: { '3': 1, '29': 1, '35': 1, '41': 1, '43': 1 } }, { input: { day: 19, month: 9, year: 2016 }, output: { '26': 1, '28': 1, '29': 1, '32': 1, '38': 1 } }, { input: { day: 17, month: 9, year: 2016 }, output: { '8': 1, '22': 1, '31': 1, '39': 1, '48': 1 } }, { input: { day: 15, month: 9, year: 2016 }, output: { '30': 1, '32': 1, '39': 1, '41': 1, '47': 1 } }, { input: { day: 12, month: 9, year: 2016 }, output: { '2': 1, '19': 1, '23': 1, '34': 1, '47': 1 } }, { input: { day: 10, month: 9, year: 2016 }, output: { '3': 1, '9': 1, '18': 1, '19': 1, '48': 1 } }, { input: { day: 8, month: 9, year: 2016 }, output: { '5': 1, '26': 1, '28': 1, '35': 1, '46': 1 } }, { input: { day: 5, month: 9, year: 2016 }, output: { '2': 1, '15': 1, '18': 1, '28': 1, '43': 1 } }, { input: { day: 3, month: 9, year: 2016 }, output: { '7': 1, '8': 1, '22': 1, '43': 1, '46': 1 } }, { input: { day: 1, month: 9, year: 2016 }, output: { '8': 1, '13': 1, '16': 1, '23': 1, '42': 1 } }, { input: { day: 28, month: 8, year: 2016 }, output: { '29': 1, '42': 1, '44': 1, '45': 1, '46': 1 } }, { input: { day: 26, month: 8, year: 2016 }, output: { '4': 1, '19': 1, '23': 1, '26': 1, '27': 1 } } ]); console.log('26,8,2016', net.run({ day: 26, month: 8, year: 2016 })); console.log('10,1,2017', net.run({ day: 10, month: 1, year: 2017 })); console.log('18,8,2012', net.run({ day: 18, month: 8, year: 2012 })); ```

image

How important is this (1-5)?

I guess 0, it's probably a misuse

Is it a configuration issue? Or rather the format of data?

Thanks for your help!

Version

Node v18.12.1

"brain.js": "^2.0.0-beta.23"
Ealenn commented 11 months ago

I tried to normalize the Input (related to https://github.com/BrainJS/brain.js/issues/712) My issue probably come from this, because, I now get different results, very similar but different.

Node Example ```js const brain = require("brain.js"); const net = new brain.NeuralNetwork({}); net.train([ { input: [ 0.1522017 ], output: { '8': 1, '14': 1, '16': 1, '21': 1, '24': 1 } }, { input: [ 0.1322017 ], output: { '5': 1, '16': 1, '18': 1, '39': 1, '44': 1 } }, { input: [ 0.1122017 ], output: { '1': 1, '15': 1, '17': 1, '29': 1, '37': 1 } }, { input: [ 0.822017 ], output: { '17': 1, '19': 1, '33': 1, '37': 1, '40': 1 } }, { input: [ 0.622017 ], output: { '19': 1, '30': 1, '31': 1, '33': 1, '40': 1 } }, { input: [ 0.422017 ], output: { '1': 1, '22': 1, '32': 1, '35': 1, '37': 1 } }, { input: [ 0.122017 ], output: { '9': 1, '17': 1, '24': 1, '45': 1, '46': 1 } }, { input: [ 0.3012017 ], output: { '4': 1, '22': 1, '23': 1, '32': 1, '40': 1 } }, { input: [ 0.2812017 ], output: { '2': 1, '5': 1, '6': 1, '10': 1, '26': 1 } }, { input: [ 0.2512017 ], output: { '4': 1, '10': 1, '19': 1, '20': 1, '28': 1 } }, { input: [ 0.2312017 ], output: { '5': 1, '15': 1, '17': 1, '31': 1, '49': 1 } }, { input: [ 0.2112017 ], output: { '8': 1, '31': 1, '32': 1, '36': 1, '40': 1 } }, { input: [ 0.1812017 ], output: { '5': 1, '29': 1, '34': 1, '47': 1, '48': 1 } }, { input: [ 0.1612017 ], output: { '14': 1, '26': 1, '32': 1, '35': 1, '37': 1 } }, { input: [ 0.1412017 ], output: { '16': 1, '18': 1, '19': 1, '37': 1, '44': 1 } }, { input: [ 0.1112017 ], output: { '13': 1, '19': 1, '22': 1, '28': 1, '30': 1 } }, { input: [ 0.912017 ], output: { '2': 1, '6': 1, '16': 1, '21': 1, '42': 1 } }, { input: [ 0.712017 ], output: { '21': 1, '22': 1, '24': 1, '33': 1, '46': 1 } }, { input: [ 0.412017 ], output: { '16': 1, '17': 1, '26': 1, '36': 1, '38': 1 } }, { input: [ 0.212017 ], output: { '11': 1, '19': 1, '31': 1, '38': 1, '40': 1 } }, { input: [ 0.31122016 ], output: { '4': 1, '33': 1, '43': 1, '45': 1, '49': 1 } }, { input: [ 0.28122016 ], output: { '15': 1, '16': 1, '34': 1, '35': 1, '39': 1 } }, { input: [ 0.26122016 ], output: { '3': 1, '16': 1, '27': 1, '29': 1, '37': 1 } }, { input: [ 0.24122016 ], output: { '7': 1, '20': 1, '22': 1, '35': 1, '48': 1 } }, { input: [ 0.21122016 ], output: { '17': 1, '22': 1, '25': 1, '39': 1, '42': 1 } }, { input: [ 0.19122016 ], output: { '3': 1, '17': 1, '26': 1, '40': 1, '41': 1 } }, { input: [ 0.17122016 ], output: { '2': 1, '5': 1, '13': 1, '16': 1, '32': 1 } }, { input: [ 0.14122016 ], output: { '9': 1, '10': 1, '14': 1, '44': 1, '46': 1 } }, { input: [ 0.12122016 ], output: { '6': 1, '11': 1, '12': 1, '14': 1, '36': 1 } }, { input: [ 0.10122016 ], output: { '24': 1, '27': 1, '28': 1, '41': 1, '43': 1 } }, { input: [ 0.7122016 ], output: { '2': 1, '5': 1, '7': 1, '44': 1, '45': 1 } }, { input: [ 0.5122016 ], output: { '6': 1, '23': 1, '26': 1, '29': 1, '30': 1 } }, { input: [ 0.3122016 ], output: { '4': 1, '11': 1, '13': 1, '38': 1, '44': 1 } } ]); console.log(net.run([0.23022016])); console.log(net.run([0.11011995])); console.log(net.run([0.08122023])); ```