Implementation

Simulation Environment

The screen shows a 500x500 block of an infinite plane. Food and blobs will always spawn on the screen, though blobs can move outside of that plane. Depending on our point in this project’s evolution, blobs either reproduce when they eat food (in which the new blob’s genetic material stems from one parent), or when two blobs meet (in which the new blob’s genetic material is based off both the blobs). When all the blobs die, a new population of blobs are born, based on the two top scoring blobs of the previous population. The score is based on the amount of food eaten.

Blob Attributes

Each blob is an object with the following attributes: angle of sight, radius of sight, x and y coordinates, amount of energy, the angle it is facing, and it's neural network object. It also keeps track of distance and angle to the closest food,distance and angle to the closest blob, and the number of food it eats.

Each blob has an angle, which determines where it can move to and how far it can see. The blob can only target food and other blobs that are within their angle of vision, which is 10 degrees to the left and the right of the angle that the blob is facing.

When a blob eats food, they gain energy. The blob’s energy simulates metabolism in real organisms. When blobs move around, they lose energy proportional to the distance they moved in that time step, as well as losing a constant amount of energy every time step. When the blob runs out of energy, they die and are removed from the simulation.

The Neural Network

Prior to learning about neural networks, we created a linear system for decision making in which we multiplied the inputs by a matrix of values. With a neural network, we can create much more complex decision making processes.

Neural Network

We implemented a neural network with one layer of hidden nodes with binary inputs for food and other blob detection within its 20˚ sight arc, as well as an input for current energy level. The network outputs forward speed and angle change. The weights of the connections between nodes are represented as elements in one of two weight matrices; One matrix represents the weights between the inputs and the hidden layer, the other between hidden layer and the output nodes. Signal is propagated through the neural network by multiplying the input as a vector by the first weight matrix, processing the resultant vector element-wise at the nodes with a sigmoid function to normalize the signal and simulate realy neurons (read more about sigmoids here), multiplying by the second matrix, and finally applying the sigmoid function again to normalize the output. The blobs movement can thus be considered a function of several variables within the matrices. In each new agent, the coefficients of the weights recombine and mutate such that on the population scale the function that defines the blobs' movement becomes better and better. Currently, the neural network is the only one of the blob’s attributes that is genetically modified over generations.

Code Structure

Both food and blobs are considered Parent Sprites. Parent Sprites manipulate their locations and create a standard definition of angle between and distance between methods.

In order to draw the simulation, we use pygame and a model, view, controller model.