A Brief Introduction to Neural Networks

While genetic algorithms are immeasurably interesting, there exist far more captivating concepts in computer programming. One such concept is the idea of neural networks.

I became intrigued by neural networks when I started thinking about artificial intelligence and how a computer programmer might get a computer to “think,” “learn,” and all these other things such as “have a consciousness” which we humans often claim as uniquely ours.

Just as Leonardo Da Vinci and many other enlightenment thinkers looked to birds to create their designs for flying ornithopters, the concepts for a neural net also comes from a look at nature. Brain cells, also known as neurons, are the fundamental building block of the brain, and therefore are considered a good place to start for building a virtual mind inside a computer.

Any neuron, whether inside your head or from the lowest of life forms supporting such cells, works fairly similarly. Scientists are still working out all of the details, but a neurons basically acts as an all-or-nothing electric pulse. It collects charge from the incoming connections, and if it is sufficient to cause it to blow, it will release a certain amount of charge over its outgoing connections, possibly stimulating cells further down the line.

The typical neuron contains a list of weights which magnify or reduce the charge sent through them from the parent neuron, and a threshold value which determines whether or not that neuron will fire. If a neuron’s accumulated charge is above the threshold value, it fires, and an amount of virtual charge is sent into the neurons it is connected to according to the weight attributed to each connection.

A simple representation of a neuron

According to Wikipedia, the human brain consists of roughly 100 billion neurons, and about 100 trillion neural connections. While the interplay at the neuron level seems quite mathematical and artificial, the combined performance of neurons on such a scale can, and does, produce a thinking, conscious being. (Where this line is, of course, is under extreme debate, and is simply a problem of definition. The answer is: there is no line, we simply designate where it is.)

What a computer programmer can do is set a computer up with hundreds of virtual neurons, with thousands of virtual connections, and then let it run its electric pulses and watch what it does. Just as in the human body, neurons in a computer can trigger certain actions. In a human, certain neurons control certain movements, whereas in a program certain neurons might trigger the AI you are fighting against to fire, to run and hide, or to strafe left.

I decided to play it simple with my first neural network, writing code which simulated creatures (red dots) fighting for food (blue dots) in a two dimensional, bounded, habitat. Each creature has a little brain inside, a neural network which receives stimulus from its environment. In this case, they are all fed the vector towards the nearest food source, whether it is to its left or right, above or below, and the same information towards the nearest other creature. These charges work their way through the network, and then the pulses on the output layer determines how it accelerates on the x and y axis. The code can be found here.

Each creature’s “mind” is set in stone. They do not learn as we do, which is something I plan on adding in the future. Instead, they act more as filters, turning one set of pulses into another set of pulses, which cause (or don’t cause) movement.

Here is the same program, after it had evolved.

Better minds were evolved by allowing a creature which found food to give birth to a mutated offspring. Creatures which did not find food slowly died of starvation. If the population level goes below a certain level, random individuals are added to keep things moving. Creatures which collide take big chunks out of each other.

Initially, the creatures do nothing, but a small percentage spin in circles, or travel in a straight line across the screen. These have a higher chance of hitting food, which gives rise to more creatures which can move. Eventually, the entire population consists of gliders, creatures which by default follow a straight path. After a while, they eventually evolve to change their movement based on their inputs, and actually swerve towards the nearest piece of food.

This is done with about 30 neurons, far less than the 100 billion, give or take, between your ears! But if 30 neurons can give red dots a means of getting food, who says that 100 thousand can’t get a computer to walk around, or 500 million to recognise faces, 100 billion to hold a real conversation with you, and 100 trillion to propel the human and machine races into the next technological epoch?

Still, for now they are dots on a screen. We’ll have to liven it up a bit next time.