Tyler Sengia

# First Genetic Learning Project

Tyler Sengia 5 min read
Table of Contents

A long time ago, I decided to make my own simulation to see if “virtual organisms” would be able to learn to survive in a simulated habitat. These virtual organisms were named “Quibs.” I don’t know why I chose that name; probably because it just sounded funny.

You can run this simulation in your own browser by going to this page on my website. The simulation is entirely programmed in JavaScript and is rendered in real time on an HTML5 Canvas element.

Link to demo application: quibs.html

Simulation Environment

The virtual environment is made up of two objects:

  • “Quibs” - The red squares numbered with white text that wander around.
  • “Food” - The smaller light blue squares that are stationary.

For each “tick” of the simulation, a forward pass of each Quib’s neural network is evaluated to determine the direction that the Quib moves. If a Quib goes off the screen, it is immediately wraps around to the opposite edge. Additionally, after movement, each Quib uses up some of its energy. You can see the remaining amount of energy that each Quib has on the colored chart on the lower right corner of the simulation screen.

When a Quib runs out of energy, it dies and a Food object is spawned in its place.

The simulation continues until only 3 Quibs are remaining, which are then “bred” to create the next generation of Quibs for the next round of the simulation. Rarely, the remaining Quibs die off at the same exact time, and when that happens, the last surviving Quib is duplicated until there are three Quibs to be used for breeding. When the next round starts, the new Quibs are placed at random locations, but the Food objects remain.

Quib Feedforward Neural Network

The Quib’s decision making is powered through a simple feed-forward artificial neural network shown below:

Diagram of the quib's feedforward neural network

The neural network is comprised of 4 input neurons, 5 hidden neurons, and 4 output neurons. This gives a total of 40 weights, and no bias neurons/inputs are used. The 4 input neurons are fed either a 1 or a 0 if the nearest food object is to the right, left, above, or below them. Each input neuron is assigned a direction: left, right, up, or down.

Each output neuron is given a direction as well: left, right, up, or down. The direction that the Quib moves in is based upon comparing left versus right and up versus down. This means that a Quib can move both horizontally and vertically in one tick. The amount the Quib moves is based upon the magnitude of the output neuron.

Training

For the first round of the generation, all Quibs are created with randomly generated weights. At the end of a round, the 3 surviving Quibs are then “bred” to create the next generation of Quibs. Every Quib in the next generation “inherits” network weights from its parents from the previous generation.

Below is a table describing all of the different “inheritance” methods used to generate the weights for the next generation of Quibs.

Inheritance MethodDescription
CloneEach weight is copied exactly from a parent Quib
RandomEach weight is random
Random MixEach weight is randomly chosen to either be copied from a parent Quib, or take on a random value
MergeEach weight is randomly copied from one of two parent Quibs
SumEach weight is a sum of the parent’s value for that weight
AverageEach weight is the average of the parent’s value for that weight

Below is a list of each Quib # and how it was generated:

Quib #Inheritance MethodParent(s)
0Clone”Alpha” Quib
1Clone”Beta” Quib
2Clone”C” Quib
3Random Mix”Alpha” Quib
4Random Mix”Beta” Quib
5Random Mix”C” Quib
6MergeAlpha and Beta Quibs
7MergeBeta and C Quibs
8MergeAlpha and C Quibs
9SumAlpha, Beta, and C Quibs
10AverageAlpha, Beta, and C Quibs

Conclusions

I have not run any tests/investigations on which breeding method is most effective.

All I know is that after a few minutes of observing these virtual creatures, you may start to see some “intelligent” movement patterns. The table below lists some common behavioural patterns I’ve seen arise:

BehaviourDescription
FloaterRegardless of where the Food objects are, the Quib will move in one direction with constant velocity.
StuckQuib gets stuck at an equilibrium point between two food objects.
Zig ZagQuib will move directly towards the closest food object, and zig zags towards the food until it eats the food.
Zig Zag BounceSimilar to the above Zig Zag pattern, but has a slight defect that causes the Quib to “bounce” away from the closest food object when it gets close.

Out of the above behavioural patterns, the Floaters and the Zig Zags seem to be the most “optimal”/“intelligent” behaviors. Quibs that bounce or get stuck seem to get less food.

Zig Zagging Quibs seem the most “intelligent” since they move directly to the nearest food objects, however the Floaters are still a valid strategy! The Floaters simply move in one direction, and they move fast. This allows Floaters to rely on pure luck to run into food objects, which is more likely the faster they go.

It’s almost like a safari, I hope you enjoy watching them!


More Posts

# 4 Bit CMOS 40XX Adder

Tyler Sengia 1 min read

In my high school electronics class, I decided to build a 4bit full adder out of discreet CMOS 40XX series integrated circuits.This means there were only AND, OR, and XOR gates in my design.

Read

# Homerolled IDE for HTML5 Canvas Games

Tyler Sengia 1 min read

While learning JavaScript and HTML5 for game development, I created my own web-based IDE for rapidly testing and debugging the games I would create.I called my IDE the RouteEngineA1 studio.

Read