Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

"Isn't the program supposed to  preserve the best creature and so the drop in fitness shouldn't happen because of that?“

Yes, the best creature’s brain will be included without any modifications in the next generation if you have the setting enabled (I’ve also tested and verified this). You’re right, this should theoretically prevent a drastic fitness drop. Maybe this is also related to the behaviour change bug.

"Isn't the simulation deterministic so the same creature with the same brain should always behave exactly the same way?“

The neural network is fully deterministic so yes, the idea is that the same brain should always result in the same behaviour. Apparently though, this doesn’t always happen, for which I have no explanation. The only part of the full code that isn’t deterministic is the mutation and mating logic (the creatures that get picked are based on weighted randomization), but this has nothing to do with the brain during the simulation.

The part that is not under my control is Unity’s physics system, which could have something to do with the issue.

"Maybe the best creature is picked but for some reason some other creature is being displayed?“

The way that the best creatures logic works is the following: At the end of every generation I store the encoded brain (as a string) of the best creature in a list. When a „Best creature“ needs to be displayed (either manually or automatically), I pick the respective encoded brain, instantiate a new copy of the body, decode the brain string (chromosome) into an actual neural network and apply that to the body. (I also verified that the creatures always get the same brain that the best one of the generation had - even when the „Best creature“ doesn’t move, it has the exact same brain as when it used to be moving)

"Also shouldn't the worst creatures be erased from the population and so there shouldn't be such a big gap between the best and worst creature?“

The worst ones don’t get completely erased but they have a very small chance of passing on their genes to the next generation. It can also always happen that you mate two good creatures and then mutate a section of their brain that then renders the whole brain useless and results in a really bad creature.

"You said that the bug doesn't happen often but for me it happens all the time. As you can see in the video the "best of" screen never shows anything other than a creature falling on it's face.“

I mean it doesn’t happen that often in different simulations. Once it happens in a certain simulation then it seems to persist for the rest of that simulation without going back to normal.

"Are you the one who wrote the code behind the neural network or are you using some libraries for that?“

Yes, I wrote the network (and everything else) myself without using any libraries. The whole point of this project to me was to learn the basics of neural networks and evolutionary algorithms and have something to apply that knowledge to and playing around with.

"And one last thing. Is there any chance of you releasing the source code to public?“

I get asked that quite often and I’m actually surprised that nobody just tries to search for it, because you could easily find it in about 20 seconds. The source code is and has always been on my GitHub. https://github.com/keiwando/evolution

The project does not have an open source license, so the regular copyright stuff applies. You can obviously read through the code or play around with it for personal use though.

"Hmm, may it be that the reason for the bug is that, you are reseting physical structure of creature but not it's brain at the start of "the best" simulation? Same reason could be the cause for that fitness drop.“

The brains / neural networks have no state associated with them that would need to be reset. The networks always get encoded into strings (which is just an encoding of the weight matrices), then these strings are used for mutation and reproduction and then the new strings are decoded into networks to be applied to the new set of copies of the body.

"The part that is not under my control is Unity’s physics system, which could have something to do with the issue."

Yes, Unity's physics engine is not deterministic. That would be the source of the behavioral not being deterministic since the behavior is dependent not only on the neural network but on the inputs to the neural network which in this case may vary from one run to another due to the physic engine not being deterministic.  Personally, I like it that way, because it gives us a look at how the neural network reacts, rather than simply how it once reacted.

(+1)

According to what I gather from the discussion at https://stackoverflow.com/questions/41063608/why-are-computer-game-physics-engin... it appears that Unity would be deterministic within a given installation if time is calculated within the program without reference to real time. That is, because background processes may cause the computer used to take a different amount of time to do the same thing on different occasions, synchronizing Unity to the actual time can cause velocity calculations to give different results in otherwise identical situations.

(+1)

Here's another article on the subject, which goes into more detail. https://forum.unity.com/threads/the-truth-about-fixedupdate.231637/