Hello and welcome to the first part of this AI implementation part one building the AI.
And as you can see I already added dimension in the structure of this indentation with these three sections
composing Part 1 which clearly show how we are going to build this AI.
First we're going to make the brain.
There is nothing else than the neural network then we're going to make the body which will define how
the actions are going to be played.
And then once we have the brain and the body we will assemble them to make the AI which will be in the
last section of this first part.
So now you can already have a good vision of the structure of this implementation.
First we make the brain then we make the body and then we assemble the two to make the AI.
And then this is all we're going to start with the first section that is about making the brain.
And this is going to take us for tutorials.
You can imagine that making a brain is not like making a cake.
So this will require more than one tutorial.
And of course as usual we are going to represent that brain with a class because we will need several
functions and in order to have a structure of several functions that will be organized in some kind
of instructions.
Well of course we need a class and that's Berkeley because once we made that class.
Well we will be able to create as many brains as we want by just creating some objects of this class.
So again classes in Python and in general an object oriented programming languages are very practical
because you make a model of something you want to build and then you're able to create as many object
as you want and they will have all the features that you define in the class.
And for our brain the features will be of course.
Well first of all the architecture of the neural network which I remind will be of CNN and of course
two different functions like for example passing on the signals from the input neurons to the output
neurons that will be of course the Ford function that will make.
So let's do this let's start making the brain.
This is going to be pretty exciting.
It is one of my favorite parts.
And therefore let's get straight into it.
So we're going to start by introducing the class of course and we're going to call this class.
Well I hesitated to call it brain but let's be more direct and let's call it CNN because actually the
brain is a CNN network.
Convolutional neural network.
So as you watch you can call brain if you want but at least now we know what we're building.
And CNN As for the network of the self-driving car is going to inherit from the end of Mudgal.
So remember the end of module is what we put it here and we want to be able to use all the tools of
this and a module and therefore we want to use this technique in object oriented programming which is
inheritance and which allows us to you know well use all the tools from a parent class and this very
class is going to be on that module.
There we go.
And now we can use all the tools and objects at the end of that module.
All right so now that we have our inheritance we can go into the class to make our first function.
And as you probably guess the first function is the end function that will define all the variables
of the future brain objects.
You know the future and objects that will be created.
All right so let's do this.
Def then two underscores in it to the scores again.
And now we need to put some variables.
So first of all I was going to be self that's of course to refer to the object.
Now I guess you're pretty comfortable with this then we we're going to add another variable which will
be the number of actions in the Dumah environment.
So we're going to call that number actions.
Number of actions.
And actually this variable is not compulsory for the function.
It's just that if you want to test the idea we're going to build on other environments.
Well this will be very practical because we will import this number of actions horrible from the doom
and Varman wrappers with two discrete and when doing that we will you know input the name of the environment
do the zero.
And so if you want to you know experiment with this on other environments and play other games well
you won't have anything to do because this number of actions will directly get the number of actions
in the Dumor environment.
You'll be playing with.
OK so that's it for the two arguments of this function.
So now we can go inside and now remember what we have to do.
The first thing we have to do is activate the inheritance with the superfunction.
So that's exactly like for the self-driving car.
We take the superfunction then inside we start by inputting the class that will define the neural network
and that is CNN.
Then we have to input self to refer to the object.
But then remember that's not all we need to add here at DOT and then the init function with some parenthesis.
And by doing that we activate the inheritance.
And now we can use all the tools from the end and the module.
All right so now I think it's time to build the architecture of the neural network.
And so as you remember we are going to build a CNN convolutional neural network simply because this
time the AI will have eyes and the eyes of the eye will be the convolutional layers of this convolutional
neural network.
And then after the ai ai visualizes the images with the convolutional layers it will pass on the signals
into a classic our visual neural network.
So that is the one that we had before with fully connected layers.
And that's where it will try to predict the cube values for each possible actions that we can play.
So you have the architecture in mind first we're going to have some convolutional layers and then some
fully connected layers and this will be the brain of our AI.
So what we're going to do to be able to have a step back at what we're making.
Well let's just make this architecture with the variables we want to create.
So actually speaking of this architecture we are going to build a CNN with three convolutional layers.
And then after that one hidden layer that means that we will need three convolutional connections and
two full connections.
And speaking of connections that's exactly what we're about to define that will be the variables for
CNN class and therefore Right now I'm going to define five variables.
Three for the convolutional connections and two political connections.
So let's do this.
We're going to start with the convolution connections.
So I'm going to call them self-taught convolution.
One going to copy that and based on the low.
And then we go self-conviction to and self-conviction three that are convolution connections to this
first conclusion one here we'll apply some convolution to the input images to get a first convolutional
layer then the second contribution to here will take the first convolutional layer as input and by applying
again some convolution it will create a second convolutional there and then this convolutional there
will get some new images each of them detecting one specific feature.
So we'll get these new images in a convolutional there then we will apply this convolution to here to
connect these new images from this first convolutional layer to some new images of a second convolution
layer.
And these new images again will detect some features in the images of the first convolutional there.
So it's just to reinforce the future detection and then to the emergence of the second convolutional
there.
We applied the third convolutional here to get it for each of them.
Some more images that detect even more features inside the input images.
And so the more we do this the more we apply some convolutions to the different layers of images.
Well the more we are able to detect some features and that's how by detecting features the eye will
understand where the monsters are where it has to shoot to kill them and where it should go to.
It will also detect the walls the obstacles.
Well literally where it has to go and that is thanks to what all these convolutional layers detect in
the original images.
All right so that's for the convolution part of the CNN.
But then remember after the convolutional layers we have to flatten all the pixels obtained by the different
series of convolutions that were applied and by flattening all the arrays of pixels we get this huge
vector that will become the input of a classic artificial neural network.
And that's where we get our fully connected letters and therefore our connections.
And so now what we have to do is create two new variables because we're going to have one here and there
in this classic artificial neural network that comes next and therefore we need one full connection
from this huge Flaten vector to this one here and there and a second full connection between this one
here and there and the output layer composed of the output neurons that are the key values.
So let's make these two first connections and then we will define all these connections.
So ask for the soundtrack in code we're going to call them self that one and then self taught C too.
All right so now we have all our valuables and to know what we have to do is of course defined then
with the classes of the engine module.
So that means we'll basically create the architecture of the neural network and that's what we'll do
in the next tomorrow.
Until then I.