you are viewing a single comment's thread.

view the rest of the comments →

[–]magnora7[S] 4 insightful - 2 fun4 insightful - 1 fun5 insightful - 2 fun -  (0 children)

This is a simulation game, I made it mostly for myself to explore artificial intelligence and neural networks so it's not incredibly polished or user-friendly. But it is very interesting from a technological perspective. It's entirely html5 and javascript, and open source. You can right-click and 'inspect' to see all the code right in the file.

HOW TO PLAY: Each fish has a neural network of 12 neurons. Those neurons are connected to each other in random ways with random strengths. So all the fish have random brains at the start, and thus random behaviors. Each fish is unique.

Then a generation happens over a few seconds, the fish run their neural network programs. Each fish has inputs of knowing the angle of the nearest food and that food's color. It has outputs of what speed it swims and how much to turn. Each fish has a unique neural network, and every generation has 100 fish.

The 10 fish that are the best at eating food by the end of the round go on to create the "children" for the next generation. This mimics natural selection. The children are mixtures of the genes of the adults, plus some random noise. This mimics evolution.

The green food is worth is +1 point to the fish health, yellow is +3, and red is -1. The healthiest 10 fish at the end of the generation have the children for the next generation, as ranked by these scores.

This process then repeats again and again, generation after generation, and the neural nets get better at the task given their inputs and outputs, through the process of natural selection and evolution. The connection strengths between the virtual neurons find an arrangement that produces the selected-for behavior.

If you want to see this in fast-time, toggle with the letter 'F' and it will do the generations very quickly and graph them for you. The green line is the median health score of a fish for each generation. The yellow line is the top 25%, and the red is the top 10% (the ones that will make the children for the next generation). The zig zag lines show every generation and the straight lines are the average across the last 10. This shows you the total improvement, regardless of season. The zig-zag lines go away after generation 200 to just leave you with the averages.

The black line that goes down is the genetic diversity. When it starts, all the brains are random, so the genetic diversity is very high. As the system hones in on a good design, the genetic diversity of the population shrinks, which in turn shrinks the possible genetic diversity of the children. The genes determine the brain design, more specifically how strongly each neuron in the neural network is connected to every other neuron.

If the diversity gets too narrow, it can get "stuck" on a certain gene arrangement. Sometimes this is good to lock in on a really nice behavior, but sometimes it's not. If it gets stuck on a bad behavior you can increase the gene mutation rate (like radiation) by hitting 'P' or reduce it by hitting 'O'. This value is called "User added std" (standard deviation). This means you're adding more noise to the children's genes. If you add too much noise all the brains eventually go back to completely random after a few generations, but if you have too little then it might "lock in" too early and not have the opportunity to discover new gene patterns that might be even more efficient at eating food.

You can let it run as long as you want, and it'll go as fast as your processor can handle. If you watch the fish after evolving them for 15 minutes, you can see they're quite good at the task! After a few hours (if you have a good run), I don't think I could actually program them to do it more efficiently than they do it. It's kind of amazing and showcases how powerful neural network evolution can be.

When you restart the game by refreshing the tab, it'll start with an entirely new pool of random brains, so each evolution is completely different and the fish discover different strategies.

Also there is a "seasonal" cycle that repeats every 10 generations. During "summer" there is a lot of yellow and green food and very little red food. During "winter" it's mostly red food to be avoided with very little green. This diversity of food situations creates more robust fish behavior, that is good both at finding the yellow/green and avoiding the red.

Anyway, if you have questions let me know. I might develop this more if people are interested, but I thought you all might enjoy a chance to play with your own neural network and to try evolving things from scratch using neural network technology right in javascript and html5.


tl;dr: "O" creates less genetic diversity in future generations, "P" makes more, "F" goes fast with graphs that hopefully go up. The fish get really good at eating the food and they learn how all by themselves without being programmed. You can open multiple tabs and have them compete and compare how they evolve differently.