Neural networks – an explanation with flappy bird

in #tech6 years ago (edited)

Neural networks are seen as the basis of artificial intelligence and deep learning. They can predict stock prices, beat humans in games like league of legends and Go and are becoming increasingly present in our everyday life.  But how do they work? In the following article I will attempt to teach you the basics of neural networks using the famous game “flappy bird” as an example.  

Last summer I modified the game flappy bird (written in python3.4 by https://github.com/sourabhv/FlapPyBird) to be able to give every bird a neural network as “brain”. The way how I trained them and taught them how to play will be explained in a following article. For this article only the bird and how his brain works will be the focus.  

Neural networks 

A neural network is, as the name implies, a network consisting of neurons, which are just the same as our brain cells.

 

  src: http://news.unchealthcare.org/images/science-images/neuron-illustration-1/view  

Functionality of a brain cell: Dendrites act as inputs, the cell body as a processing unit and the axon and terminal bulb as an output. 

  -> Input is converted into an output   

What we usually refer to as “intelligence” takes place inside the body of the cell, there it is decided whether or not a neuron will fire, depending on the strength of the incoming signals from the inputs (dendrites). The strength of a signal arriving at a dendrite is furthermore influenced by a factor, which in- or decreases the strength of the incoming signal. This factor is called weight.

Now we try to rebuild this system by using computers.  

We have got input numbers, which will be in- or decreased by multiplying them with weights. 

After this they are processed by an activation function (sigmoid for example) to an output value. 

The activation function is always the same, so only the weights are variable, and there the learning takes place. How exactly this learning works (backpropagation etc.) is not that important to know, but if you`re interested leave a comment and I will explain it to you.

If we now add multiple neurons together we will have created a neural network, which simply calculates inputs into outputs.

Flappy bird

The two inputs are: 

  • The distance to the new pipe
  • The height of the hole in the next pipe 

Now these two inputs will be processed by multiplying them with the weights and using the activation function and the output will be either 0 or 1.   

1 stands for flying (tapping on the screen), 0 stands for not flying (not tapping on the screen).  

This step (input – processing input – decision about flying) will be iterated on and on, until the bird dies by hitting the pipe or the ground.

And that`s it. Now we have an artificial intelligence playing flappy bird. With a lap top and enough time you can break every human record, my birds reached a constant result between 400 and 600 points after 4 hours of training.  

If you have questions or suggestions just let me know in the comments, also if you`re interested in my code or some video footage of the training write me and I will send it to you.  

I hope you enjoyed the article!  


Sources: Tariq Rashid – Neuronale Netze selber programmieren  

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.034
BTC 63960.62
ETH 3142.95
USDT 1.00
SBD 3.95