An artificial neural network is a computational model based on the operation of neurons in the human brain. Neural networks can predict a certain outcome by learning from data. The data will pass through different layers to finally predict the outcome.
A fully-connected neural network consists of at least an input layer and an output layer. A hidden layer can be added for a more elaborate network. Each layer of the neural network consists of a defined number of the so-called nodes. The input layer nodes collect the raw data from a vector and move it to the output layer, passing hidden layers. Every connection trains the unique set of data obtained from the previous layer, and the output layer contains the final prediction scores for each output node.
As the name does suggest, the layers are fully connected. Every connection has a specific weight. The weight indicates how much influence the particular data information has on the output prediction. How these weights are calculated is explained in one of the following tutorials called ‘Weights’.
A neural network will be designed based on the situation. Specifically, during these tutorials, a neural network for the Flappy Bird game will be designed. It is necessary to have the situation in your mind when setting the number of nodes in each different layer.
We will start with the number of nodes in the output layer.
Every loop through the neural network will have two possibilities as output. Which two?
Based on this information, using two nodes in the output layer sounds logical. However, just one node will be enough. But why?
The moment when the bird flaps is critical to run the game successfully. The bird’s altitude, the distance of the bird to the pipes, and the height of the pipes are factors that determine this moment. The only thing that we can influence with the AI is the bird itself and therefore the bird’s altitude. So that is why the output layer consists of one node that is telling the bird whether they should flap or not.
The information of the bird’s distance to the pipes and the height of the pipes can be used as input information of the neural network to determine if the bird should flap or not.
With the information of above, how many input nodes would we get?
We now have set the number of nodes in the output layer and the input layer. What remains is the number of nodes in the hidden layer and the number of hidden layers. More layers and more nodes will give more specific training, resulting in a more precise response. However, the running time will also increase when raising the number of nodes and layers. Furthermore, too many calculations can lead to overfitting the neural network. Overfitting means that the model is aligned to a limited set of data points. Fewer nodes can be advantageous but can also result in the neural network not being specific enough. The ultimate goal is data fitting as explained in the previous tutorial.
We will start simply with one hidden layer having five nodes. The structure of the neural network for the Flappy Bird game is visualized below. The I in the nodes stands for input and the O for output. We will work with this setup in the next tutorials.
In this tutorial, you have learned what a typical neural network looks like. For the Flappy Bird game, this network is rather small, making it easier to comprehend. We have seen that in the game, we have 2 output nodes since the bird has to flap or not flap. Moreover, we have 2 input nodes since the only information we require is the distance from the bird to the next pipe and the distance to the center of the gap between the pipes. The next step after this tutorial would be to get the AI working. However, we first need to explain the ideas behind matrices and weights before we can move on. Therefore, the next tutorial will be a mathematics tutorial focused on matrices.