Hello.
Welcome back.
So let's see how to build to the hidden layer neuro network.
I'm gonna make a copy of the last project over here.
Copy paste I'm going to call this hidden layer and then
open it.
Right.
So let's take a look at the architecture again.
So that's what the hidden layer neural network looks like.
So we've got our input here and our outputs pass through another layer before we have.
And before we get our output to this computation to run at a layer before we have our output layer.
Right.
And we're already described how we could do this.
So let's implemented in code.
Now this is the pseudo functions we wrote and we're going to write the actual functions now.
Right.
Or minimize this.
And I'm going to go to our neural network to see file and I'm going to create the function is down here.
Right.
So the function we're going to create is going to be called the hidden layer and n and this function
shall take seven argument.
The first argument is going to be the input vector.
Then the next argument is going to be the length of the input and then after the the third argument
will be the the length of the hidden layer which means the number of nodes or the number of units in
the hidden layer.
Whenever I say node or unit just think of this.
Right.
The Psychos are the nodes or the units.
Right.
So I'll just start right in the function here.
Call a void hidden and
well like I said and like I said it takes a number of argument come over here.
The first argument is a pointer to the input vector.
The next argument is the input land you in 232 on the score t
input line like this.
The next argument after this is the length of the hidden layer.
Then the next argument is the input to hidden layer weight.
And that's what I mean by input to hit only a weight the weight for these snaps.
The weight for these are roots.
Yeah.
Inputs to hidden layer weight these weight we're going to pass them as I comment number four.
So it's going to be a two dimensional array or it matrix if you want to call it that
so I'll just call this in to hit weight
and the size is going to be
hit in length the number of rows of course hit in length and the number of columns of course input land.
Once that is done the next argument is going to be the length of the output
after this.
The next argument is going to be hit into output weight the weight for for this side hidden layer 2
outputs layer the weight we need for them.
Oh come over here and this is going to be a two dimensional array as well.
Double I'll she hit out weight
and the first size is output Lent.
Second of size is it in length like this and the next and last argument is a pointer to a vector to
store the 0 attributes
like this right.
So like I mentioned we simply need to perform we simply need to perform a matrix vector multiplication
of the input vector and DMM to head in to inputs weight.
And once we get a result we perform another matrix vector multiplication with a result with the hit
into output layer weight.
So I'm gonna start off by creating a buffer here which is going to be like a crutch array.
Now we're going to use to store the hidden layer predicted values for the hidden layer.
So we need to perform a matrix to vector multiplication using these inputs and these weights these weights
are represented here.
We need to take these inputs this a vector.
It's gonna be a one dimensional array and this two dimensional array the result that we get is going
to be hit in 0 hit in one hit into these are going to be the result and we take this resort and then
we perform another matrix vector multiplication.
But this time with this weight to hit into output weight and after that we get the results for side
sick and active.
So basically this is how a neural network with hidden layer computes the resort.
Right.
So come over here and see double it in predicted value
it is predicted vector.
And this is going to be the size of the hidden layer to hit it.
Then
and then I'll see matrix vector multiplication.
The first argument is going to be the input vector.
The second argument is going to be the length of the input vector which is input land.
The third argument is going to be the output vector and we're going to store the output gonna story
output in this buffer that we've created it in predicted vector values.
So I'm gonna see hidden predicted vector here.
That's where we store the output.
And after this the next argument is what is shown here with the color blue is output land.
Now after this the next argument is
the next argument is the weight matrix
and the weight.
We're going to use is input to hit in weight so pass in to hit and weight right.
So after this computation we're going to have the result stored over here in this buffer here.
So we're going to take this buffer and then hit it to output weight and perform matrix victim with application
again.
So I'm gonna perform another one.
And if we had multiple layers multiple hidden layers we would have to keep computing like this for each
hidden layer.
So it would be nice for you to try adding another hidden layer to the neural net work example and try
to write the function to compute that one.
So I see a matrix vector multiplication and the input vector this time is hit in predicted vector and
the length of this is Headland and we see in Hidden Land it just so happens that in our example I'll
show you it just so happens that in our example the hidden length or number of nodes and the the input
length or number of nodes and the heat in length and the outputs are the same.
It just happens that all have three nodes but you can have two here three here.
Did they come in different forms.
So that is why our function is not just saying give the length.
If we wrote the function to accept just one length value then it's going to be problematic cause our
lives have different length.
That is why we're dealing with hidden length output lint etc..
So the next argument is the output for buffer and we want to store this in the output buffer.
And after that the next argument is the output lend
and then the weight the weights.
Here is the hit into output weight hit two out weights like this.
So this is it.
We can expose this function
and we can go to our main file to test it out.
Gonna come over here
and
I'm going to add a new defined statement here for hidden layer lent or say define.
I did Len the length of the hidden layer is 3 as well right.
And actually I'm going to keep these weights and this time these weights I'm going to make sure these
are the weight for the hidden layer.
So this will be hit zero
hit 1
head to
like we have over here right.
And we need a new set of weight.
We've got to change the name to now.
This is called
input to hit in weight
and it's hidden lent by input land
right.
Okay so we need to create a different set of weights.
Come here
turbo the
this is going to be hit into output layer weight
and output line and then hidden Len
and we can just assign certain weights here let me see.
I'm gonna say minus one point zero
and one point one five zero point one one.
This next one can be minus zero point twenty eight zero point one five minus two points you're one.
And this last one can be zero point two five minus zero point to five minus zero point one.
These are just like I said random numbers
to put a bit of comment here.
So this would give the sad result.
This over here for sick or not sick
and this is for active or not.
And we know that this one is from if want to put this here.
This is input from it and let it hit in here.
Um no.
Zero.
And this is from head 1 and this is form hit 2 right.
Once we have this we can um let's see put a semicolon here
we can use the same input vector we have input vector here so we can come down here and call our function
the function is called hidden layer and then you can simply see it in the
or hidden n in does the name of the function the first argument is the input vector
the second argument is the input lent
the next argument is the hidden layer lent then the next argument is the input to hidden wait
then the next argument is the output lent then the next argument is hidden to output wait
do we have more argument
the next argument is the output vector we don't have which not created an output vector here I'm gonna
come over here.
Okay this one hit predicted output I'm gonna copy this
put it in here put it some call on here like this and um yeah everything else remains the same sad prediction
is going to go here and then seek prediction here and then active prediction here.
Right let's run out code and see what we have.
Click here to build it to be successfully download onto the board let's see Terra to
or reset my board and this is where we have sad prediction sick prediction and active prediction right.
So this order is for this lesson and I'll see you later.