Hello.
Welcome back.
So let's see how to randomly initialize our weights.
So I'm gonna make a copy of the last project and then I should mention that over here we gonna use this
and uh we're gonna use a sort of random number generator but ordinarily or I should say wait till I'm
type this first.
Ideally we should use the random number generator of our microcontroller or so a microcontroller comes
with a hardware random number generator and that is much more precise compared to using the C standard
library round function.
So later on we want to see how to use the hardware random number generator on the microcontroller.
But for this let's just try these thunder to see um run function.
So we said Um let's see let's see this of architecture.
So we piece these sign ups over here sign up so we send up someone.
Basically this is a way to matrix.
This is a matrix a matrix of weights containing the weights and this input here interact with the weights
within this and up 0 to produce the output for this layer and then we'll take this and its Iraq to which
this other weights to produce this sort of output and to start off in machine then in the weights are
often initialized to random values rather than 0 we initialize the weights to random values so we would
have to find a way to always have a random number generator to initialize it for us sort of to keep
the ball in the air like a sports like volley someone has to throw the ball in the air and then a player
that gets it first you stop playing with it.
So the initialization is like getting the Portlandia so you start somewhere randomly and then the learning
begins from the wrong random point right.
Um yeah.
So I'm gonna go to the simple neural network don't see.
And I'm gonna come over here which show creates a function called the um the way to random initialization.
And like I said this will be improved later on when we use the hardware.
This over here we are focusing on understanding not efficiency in these initial sections.
The focus is on understanding.
Right.
So I'm gonna say Wait.
Um random initialization does a descriptive name which random initialization.
And this is going to take a number of factors meant to be precise.
It's gonna take three argument.
The first one is going to be the hidden layer lend the input lint and the um the weight matrix.
But this implies one is hidden layer.
Right.
So I suppose.
Yeah.
This the this the hidden layer.
So when we get here.
Okay let's take a step by step sorry about that.
I'm gonna come over here and see you into 32 unescorted T.
He didn't land
and this means the number of notes in the hidden layer and then you in that to
and then input lent
and then a matrix to store the the output weight that will be generated.
So say double weight matrix and the size of this number of roses.
He didn't length number of columns as inputs land like this.
Right.
So open and close over here
okay.
And when I put a global variable here I see a double T on the score around and I'm gonna seed it
with a comment seed random number generator
No not C S front I should always take him into
it with one or whatever the reason we have in this red mark is because we've not included DC standard
library so come over here include STV end this Tedy lib sorry that H and should be find a typo fixed.
Good right.
So once this is done we can call our function or we can complete our function.
So I'm simply going to say
for int i equals zero.
I it's less than the number of rows which is the hidden Len I plus plus open and close.
And then for int
for int j equals you j is less than number of columns which is input Len
J plus plus open and close and over here
I generate
random numbers
between 0 and 1.
So come over here see a different global variable equals round
percentage 10
then dethroned because divided by 10.
And then
I simply say wait wait.
Matrix index.
Hi
next J.
Right
and um this doesn't have to be global.
Bring it in here.
Sure.
Weather across the front.
Okay.
So I'm gonna grab this.
The prototype gonna put over here the head of a put a semicolon here and we can go into our main the
c file to test it out.
We can start off by wiping off the current content in the main function.
So this what we have we have our data already here.
So I'm simply going to create a number of variables.
I'm gonna come over here.
Let's test a simple test.
We'll see a double
um.
Let's see the names we gave it to the names you gave them.
This is S N zero s and one s and for sign ups.
So I'm gonna say s and I'm 0.
How about a comment first.
So this is input layer 2 hidden layer
which matrix after the gonna have another one.
You didn't layer to pull layer where it.
Matrix right.
So let's start with this.
We're gonna create a buffer for it.
So this is double S N zero and number of rows because number of rows because the number of hidden nodes
number of columns equals number of features.
Let's see how many hidden nodes.
So we have three nodes here.
Does the length and one note here.
I'm gonna come over here include a defined statement I'll say a defined number of each I.D. mean in
hidden nodes is three
defined number of output nodes as one like this.
So over here the size of this matrix is number of hidden nodes and number of features which is input
number of inputs
then this is synopsis.
I was in OPs one double S and one the size of this is number of output nodes
and number of hidden nodes
right.
So once this is done we can go and test this out by calling our function
come way to random initialization and then we pass this length of hidden node number of hidden nodes.
Then number of features and then we pass this into the synopsis zero matrix
and then we initialize the other one which random initialization
number of output nodes
number of hidden notes.
And put this in Snopes one.
No we can go ahead and print the resort
not sure.
Wait.
Use unless that loop over here.
For int I Coursera.
It's less than
a number of
no.
Hit note.
All right.
Plus plus open inclusion and then
J equals zero G is less than the number of features J.
Plus plus open and close and what we want to do is
print f
percentage curve then shut up sheer index by index J and then we can print some new lines here.
Print f
n print another one
right.
Once this is done we can do the same for the second set ups which is set ups one and simply going to
copy this and change it appropriately.
This is an ops one and this becomes output notes and then this becomes the hidden nodes
and is not one.
Everything else remains the same right.
So we can do that see what we have.
Click over here to build Click here to download onto the board.
Let's see to write a
reset my board.
And this is what we have.
So we can see the way to matrix for forcing up 0 is 3 by 3 is 3 by 2 Sorry.
Why must see cause we have two inputs to input 3 notes we have 2 inputs coming here 3 nodes.
So we have 3 by 2 and the way to matrix for sign ups 1 is 1 by 3 because we have one node and then 3
inputs entering into the single node but we should talk about dimensions later.
Now just focus on understanding later on we have a section on how to take all of this from scratch again
and in that section with formalized the ways in which you can tell the dimensions of the various layers
and the matrices that they work with but thus far without case study this explanation should suffice.
If you have any questions just send me a message on this or there is for this lesson and I'll see you
later.
Have a nice day.