We are about to switch to a new forum software. Until then we have removed the registration on this forum.
here we go, following up my previous post (https://forum.processing.org/two/discussion/23539/genetic-algorithm-driven-ecosystem#latest) i finally managed to write a fully functional multilayer perceptron to give my creatures their very own brain. it's a simple simulation, brains are randomly generated, creatures have 4 inputs, they triangulate the distance of the closest food with body and antennas, they can also perceive their health levels. creatures will die for starvation (change color from red to white) and overeating (from red to black), so over time they will learn that they need food to survive, how to seek it and to balance food consumption. outputs are: rotate right, rotate left, move forward, speed value. Click on a creature to display its brain.
the code is extensively commented, but for a better comprehension i suggest you to read it in the following order: Connection class, Neuron class, Layer class, Neural Network class, Eater/food class, World class, Main Tab (NeuroEvolution V3).
gitHub repo: https://github.com/m4l4/Neuroevolution-Simulation Hope you enjoy it, prepare for some code:
Comments
ok, that should be it, with that configuration it takes something between 15-20 generations to see a coherent behavior, my record is 40k age on gen 19. Eaters seems to have some problems with the borders() function (limit their position to screen size), so i'm currently using wrapAround() (continuos screen) and working on a different set of inputs for the creatures. i'm working on adding sight, smell, hearing and whatsoever, (here's my line of sight project https://forum.processing.org/two/discussion/24691/solved-collision-and-obstacles-detection#latest) i'll be very interested in your opinions/suggestions. also if someone has a better understanding of neural networks (i'm a complete noob so if you have some insight about it, you're probably better than i am) i'd like to hear your opinions about my approach to the problem and the possible future developments (recurrent neural nets, backpropagation, fitness function etc.)
Could you try and upload your sketch to https://github.com ?
i've never used github myself, i've got no account there
It was new to me too but it's a professional tool and makes downloading your sketch much easier than here.
i hope it works https://github.com/m4l4/Neuroevolution-Simulation
It works! Well done!
Thank you for sharing this -- very interesting!
Thank you so much for this code, it is extremely enlightening. I will go through it thoroughly these days, I’m sure it will make the process of making my own neural network much easier. Also expect a lot of questions from me in the coming days. To start: I haven’t examined your code, but you have used only a genetic algorithm to train the network right? No backpropagation?
I have given your code a quick initial scan and I have another question: why did you use a tanh activation function? Why not just use a sigmoid one? I am not one to know for sure, but I don’t think your network requires enough gradient strength to require tanh over sigmoid.
In line 32 of your Layer tab, is there a reason you're using expand() instead of append()? Why don't you use arraylists for everything data structure that changes, instead of arrays? It would save you a lot of hassle.