In this lesson, you will get a short introduction to Artificial Intelligence (AI in short). We will talk about what AI is, what it does, and what it is used for. We would appreciate it if you would give us feedback on this collection through Google Drive.
AI is intelligence demonstrated by machines. It is different from natural intelligence used by humans and animals, which includes consciousness and emotions.
There are multiple types of AI. For example, we have the commonly used shallow/simple AI. If we look at shallow/simple AI, we think of rule-based AI. Rule-based AI means that the program produces pre-defined outcomes that are based on a set of specific rules coded by humans. These systems are models which use the rule of if-then coding statements. An example of rule-based AI would be an identifier of animals, like the following picture illustrates.
For example, we could consider a hummingbird. In the first node, we go to the right since the bird has no hair. Furthermore, it is small and can fly; hence we conclude it is a bird. This example illustrates that rule-based AI works very efficiently. However, it has a major disadvantage. E.g., for a limited input (mammals, bugs, and birds), rule-based AI can work quite well. The AI does not work at all though, when we use a salamander or a fish as input since the AI does not know how to classify these animals.
This is why for these tutorials, we will not delve deeper into rule-based AI. Instead, we will focus on machine learning. The word machine learning is used when a computer “learns” or “solves problems”. Machine learning systems do not use if-then statements, but they define their own set of rules based on data it receives. They constantly evolve themselves and therefore are scalable. This property is a significant advantage over rule-based learning. In rule-based learning, we have a "fixed" intelligence since all rules are pre-specified. However, in machine learning, it is based on the data it receives, resulting in a more flexible intelligence since it can learn new rules based on data.
Machine learning is much more integrated into our daily lives than you might think. One often-used application where machine learning is used, is speech recognition. So when you tell your phone, Google Home, or Alexa to do something, machine learning is being used. The speech-to-text software constantly improves itself when receiving new input to better determine what you were saying. Another important application of machine learning is image recognition. This has all sorts of practical applications. For example, recognizing cancer in an early stage could be crucial for the patient's survival. This is but one of the many practical applications of machine learning.
To make machine learning possible, we will use so-called neural networks. In the next tutorial we will go into more detail about what neural networks are and how they work.
In these tutorials, you will create a neural network for the game flappy bird. After completing the entire series of tutorials you will create a fully functional neural network for the game flappy bird and understand why and how it works based on the mathematics behind neural networks.
The tutorials are ordered in such a way that each piece of mathematical background is followed by a part where you will implement the learned concepts into your AI.
The spectrum of mathematics behind neural networks and artificial intelligence is quite broad, so in these tutorials you will learn the basics without going into too much detail. All the topics that will be covered are listed below.
From a mathematical perspective, the essence of a neural network is that it approximates the function that fits best through given data points. This is called data fitting. A simple example of this is that when you have a few data points you can try to fit a line through the data points, meaning linear data fitting. Of course, the more data points you have, the more accurate your function approximation will be[1]. A neural network works similarly, we train the network with a certain amount of data points such that the network ‘learns’ from this information. Then in a new situation, the network can react to new information based on the rules it learned from the training data.
In the following tutorial, you will learn some more about the structure of a neural network. It is built out of matrices, which will be the next mathematical subject to cover. Matrices are used in various fields since they are an easy means of storing massive amounts of data. Therefore, to construct a neural network, you will need some knowledge of working with matrices. Moreover, we will also discuss vectors which are, in a sense, a small matrix. In most technical studies, vectors and matrices appear due to their usefulness.
As said before, a neural network approximates a function. In the mathematics classes you attended, one of the most prominent subjects was optimizing functions. For example, finding the maximum/minimum of a function, you first calculate the derivative and set it equal to zero. What is interesting is that in neural networks, this procedure is still applicable and very useful. However, the setting is a little bit different, making the situation a tad more complicated. This branch of mathematics is often referred to as optimization.
Of course, there are many more branches of mathematics we would like to discuss. Unfortunately, they require a specific set of mathematical tools you might learn at the university rather than at high school. Therefore, we cannot discuss everything in depth in these tutorials. The purpose of mathematics in these tutorials is to show you how mathematics facilitates machine learning. Perhaps, in the coming years, when following a technical study at a university, you learn the details of these mathematics. This makes this tutorial an ideal foundation for what is to come.
To start programming, you first need to install a few programs and files. The first, and most important program is Python. Python (we recommend Python 3.8) can be installed from the Microsoft store or the Python website.
Next to Python, you will need an IDE that can support you in writing code. We recommend downloading Pycharm community. Pycharm is an IDE that creates environments to work in, keeps everything in one place and color-codes your programs.
Once Pycharm is installed, you should create a new project by going to File → New Project. You should get the new project tab.
At the top of the tab, you will need to put the location of a (new) empty folder. The files you make will be placed in this file.
You should create a new environment using ”Virtualenv”. The Virtual environment, as it is called, automatically creates a folder, since this is the folder where the IDE places the information the machine needs to run. Uncheck the “Create a main.py welcome script" box. Now you can hit the Create button and create your Virtual environment.
Download the files for the basic Flappy Bird game as a zip from Github. The FlappyBirdGame-main zip file contains the folder Flappy Bird Game and three images. This folder and the images should be placed in your working environment just by copying them. After that, you can see the files in your Pycharm project.
(In case you don’t remember where that folder is; you can find the path to it at the top of your project in Pycharm.)
Before you can play Flappy Bird, you must first install a few packages. This can be done by first clicking on the terminal button at the bottom of Pycharm. In the terminal, you should copy and paste the following code:
pip install pygame numpy scipy
Let the program work through the three installs. This will take some time, the program will let you know when it is finished.
After the installs are done, you can open the Flappy Bird Game folder. Right-click the main py file and clicking on Run (the one with the green arrow) to start playing Flappy Bird. You can flap by pressing space and quit by pressing any other button.
During the tutorials Python is used as a programming language. To understand the code it is convenient to know the Python syntax (e.g. the usage of classes and functions, or that Constants are defined in all capital letters). If you are not familiar with the basics of Python, we would like to refer you first to the Python introduction of Serpentine Wiki.
In this tutorial, you have seen a short introduction to Artificial Intelligence. You now know the difference between rule-based AI and machine learning. Furthermore, we have provided an overview of the mathematics we are going to discuss in the other tutorials. These topics are important for understanding how machine learning works on the game Flappy bird. Lastly, you have installed Python, and played the game Flappy bird to gain understanding of the game. In the following tutorial, you will build the neural network behind the game in order to beat it.
However, too many data points is also not beneficial! This is called overfitting. Similarly to the rule-based AI, we fit the data such that it is perfect for a certain training set. However, when we use the learned rules on a different training set, the performance is in general terrible. See https://blog.minitab.com/en/adventures-in-statistics-2/the-danger-of-overfitting-regression-models#:~:text=In regression analysis%2C overfitting a,complicated for your data set. for a more elaborate discussion on overfitting and its disadvantages. ↩︎