Hello.
So let's see how to build the single input multiple output neural network.
I'm going to make a copy of the last project or paste it over here
just a single in
motorboat out
and then I'll open it
right.
So let's go to our neural network stasis file.
So we're going to create a new function known as the single input multiple output.
But let's take a look at the neural network again.
Is what it looks like.
The input is single.
Let's say we have sad end from sad.
We want to derive the temperature the humidity and the air quality.
So all we have is sad and.
Wait.
That would help us derive the temperature the other weight that would help us derive humidity and a
third way to die would help us derive the air quality.
And over here we said we have to do what is known as element wise multiply meaning.
We take these color value which is sad.
This single number.
And then we multiply it by we we sort of multiply it by a vector of weight cause the weight is going
to be an array an array of three elements.
So we multiply this same number by each member this number.
This single number by each member of the array essentially.
And this is what is shown here.
Saad multiplied by which one side multiplied by way two on the side multiplied by weight three.
So what I would advise you do is you post a video and try to implement this on your own.
And once you've done it you can sort of play the video again and see us we do it together.
Right.
Welcome back.
Then I'm going to come over here.
I'm going to create a function known as element y's multiply and then I'm going to wrap a new function
around it for readability.
So I'll see void
and I'll call this element y's multiply.
This function is going to take it's going to take four parameters.
The first parameter is going to be the input which is a scale of value a single number.
And it's of type double I'm going to call this input scalar
The second argument is green to be a pointer to the weight vector or a pointer to the weight one dimensional
rate.
Whenever I mention a vector or just think of a one dimensional array so see weight vector here.
The third argument is going to be a pointer to a one dimensional array to store the output.
So call this output vector
and then the output vector length is going to be the same as the weight vector length.
So I'm going to create a new variable here which is a new argument here which is going to be the length
of the vector.
So call this vector length like this open and then close.
Right.
Very simple very straightforward and we can implement it just like we saw in the theoretical class.
We can use a for loop to do the.
We can just use a for loop to iterate over each item in the vector.
So say for int i 0 0 is less than vector length I plus plus.
And what we want to do is output vector index i equals inputs color
multiply by weight vector index I as simple as this.
Right.
So that's the it element y's multiplication.
Once we've done this we can wrap it around a we can wrap in new function around it by saying void single
input
underscore multiple output n n
and this is going to take exactly the same argument as this
right.
Open Close and all we have to do is call our function the element y's function.
Over here you see element wise multiple and the first argument is the input scalar.
The second argument is the weight vector.
The third argument is the output vector.
The last I comment which is the fourth argument is the vector length.
Simple as this we can expose our function.
We can expose this one.
So you see we only expose these functions these ones aren't exposed element wise it's not exposed weighted
sum it's not exposed.
Just the neural network functions are exposed.
So I'm going to copy this and put it over here and then some call on here we can go to our main file
and test it out.
I'm going to clean everything from here
right.
Right.
So we can say okay we have.
We can define sad.
I'm gonna see sad is zero point nine.
Right.
I'm going to give a symbolic name to zero point nine to me inside.
Okay this is just an example like I say.
Like I said earlier I'm using random numbers here I'll say define temperature
I'm just going to create a symbolic name for the indices.
So I would just say perhaps temperature
prediction index cause we know temperature indexes at index 1 course in the input vector.
The first one is temperature.
So let's just maintain that
index zero I mean temperature is at index you
humidity prediction index
air quality is at index 2 Okay.
And we can define the length of the output which is the same as the vector land because the output land
is equal to the weight linked to the length of the weight.
So we can create a vector here to hold a predicted resort.
I'll say double
predicted resort and it's of size three right.
And we can sort of create let's say we have our weight vector as great a weight vector for example
and the first weight is 20 minus twenty second one could be ninety five let's just say these are weight
for some strange reason these are the weights and the first weight here yes what temperature the second
wait is for humidity.
And this one is for air quality.
I'll show you again
this on your network.
We've got way too one way too with three weight one belongs to temperature way too for humidity with
three for air quality right.
OK so that's it.
Now we can call our function.
I can come over here and see a single input multiple output neural network.
The first argument is the input scalar which is sad.
I simply need to pass that over here.
The second argument is the weight vector.
I'll just make this plural
the third argument is the output vector predicted resort.
The last argument is the vector lent I'll just use output length here.
Right.
So this will predict the resort.
We can print out the resort to zero.
So say print f
predicted temperature
is percentage F R and then n and then we can go to our predicted results.
I read this array here.
We know the first index which is index zero represents temperature so I can just pass temperature index
here just for readability sake I've created this this naming convention right.
And we can copy this and do the same for humidity and air quality
the humidity index is this
and we can do it once more for quality
right.
Let's build and see what we have.
Click over here to build
Click here to download onto the board.
Let's see Terra term
Oh reset my board.
Okay so there's the temperature prediction.
So basically what our neural network is saying is if you're sad given the weight then the temperature
is minus 18 degrees Celsius the humidity is 85.
The air quality is one 80 right.
So there are ways of measuring air quality as the air quality index.
So 180 is it s not so good.
The World Health Organization recommends air quality should be a think below 50 or a hundred.
I don't quite remember that number but one eighty certainly not good.
And again we are using just random numbers and those of you who are not familiar with call your vision
um you can actually view.
You can view all of the resorts without a zero plot.
Just that you wouldn't have sentences you would sort of not without the um the terror term you could
view the resort by just put in the array in the watch window.
This is not zero plot.
This is just a zero software zero.
I said zero plot because I was using arduino the other day in that Reno has the zero plotter.
Um so we can simply say I came I clicked over here had to come to debug view and you can double click
on this global variable which is on read and go to UT to watch window out to watch window one and you
can expand it and you see we have index 0 1 2 here and we click here to run that's going to see a clean
this well this has run again but as you can see the values here are the same
the values here are the same as this and I was zero plot is actually.
Okay.
It's fine.
It s print it accurately it s eighty five point five it s five point five one eighty point nine one
eighty point nine.
So you can view it in the debugger as well in a way this all the rest and I'll see you later.
Have a nice day.