ml5-library icon indicating copy to clipboard operation
ml5-library copied to clipboard

Xor example predicts 1 for [1,1]

Open happycze opened this issue 2 years ago • 2 comments

Hi, i have returned back to ml5js and checked basic examples including xor, which seem to be not working as expected, because predict function returns 1 for pair 1,1. I have found few issues here which seems to be related, but no fix. Please could you check it and let me know? Thx

https://examples.ml5js.org/p5js/neuralnetwork/neuralnetwork_xor/

happycze avatar Aug 22 '21 15:08 happycze

Seems like this example is badly written. XOR requires at least one hidden layer. I tried to fix this by customizing layers, but the documentation is so vague, that I can't know what layers option should look like.

KonradLinkowski avatar Sep 22 '21 16:09 KonradLinkowski

This seems like a very interesting example. I made a copy of the sketch to clean it up and test solutions. https://editor.p5js.org/stampyzfanz/sketches/pRKTciRsT. I added the 16 hidden units as Daniel Shiffman used but it still didn't work. It only works if you include the sample data twice? And it gives different results if the data is entered in a different order. This sounds like a bug in ml5.js unless random order in the training is a hidden option, in which case it should be easier to find in the documentation. Edit: In TF.js, the Coding Train used the option shuffle: true. I can't find the word shuffle on any ml5.js website. image image In fact, when I inputted all the inputs into the NN in the original sketch, it still worked. Maybe ml5.js includes hidden nodes by default.

tldr: the solution is to add the input xs and ys twice to the NN?

stampyzfanz avatar Apr 06 '22 07:04 stampyzfanz