So let's see how to build to multiple inputs single output neural network.
I'm gonna make a copy of our last project copy paste or rename this
and I'm going to open it
right.
So.
So let's take a look at our neural network.
So this time we said we have temperature humidity and air quality and all of these three parameters
influence what a person is happy or sad and what we want to see how to design a neuro network that takes
these three inputs to produce the the output which is whether the person is feeling happy or sad.
Let's see how we do that.
So let's go to our simple neural networks dot see file and create a new function the right.
And we said we have to perform what is known as the weighted sum in order to compute this.
So I'm going to create a new function over here known as weighted sum
and one thing we can do actually is to make this interest.
And we can start using double as the data type.
I'll just train the dog.
Uh the data type of our first function here too of type double.
So we can have floating point numbers gonna change over here as well in the dot age for.
So if we come over here to the main this has to be double
this has to be double as well.
And this over here percentage D becomes spits percentage F right.
So let's implement our new function.
I'll come over here.
This function is going to return type double and I'll call this weighted some
open closed.
This function is going to take three arguments.
The first argument is going to be a pointer to the input the input could be a vector which is a one
dimensional Larry.
The second argument is going to be the pointer to the weight the weight is going to be a vector as well
which is a one dimensional array for this example.
It doesn't always have to be a vector.
When we start dealing with real world machine learning examples all of this will begin to make sense
and you would understand.
And the third argument of the function is going to be the length of the input.
So I'm gonna come over here and simply see a double star input and then
double star wait.
And this last one.
We can see you in 3 2 score T.
And we can call this inputs land
like this open and close.
Right.
So let's come over here.
Create a local variable here which I shall call double output.
And I'm simply going to use a for loop to implement the weighted sum.
Right.
We implement a weighted sum over here is basically input 1 multiplied by which 1.
And then we get product 1 input to multiply by we 2 we get product to input 3 multiplied by we 3 we
get product 3 and then we do product 1 plus product 2 plus product 3.
That is how we get the output that is essentially the weighted sum.
Right.
So I'm gonna come over here and play a trick using the for loop.
So for int i equals zero is less than the input length I plus plus.
And we're going to do exactly what I just explained.
We're going to use this as an accumulator.
So I'm gonna say output accumulates
input array remember input.
This is a pointer to an input our race or we can say input array index I multiply by weight array index
i and it's as simple as this.
Right.
And we can come out here and return the output.
Right okay so this are a weighted sum function.
So are we going to wrap our multiple inputs single output and end around this weighted sum just to make
it much more readable.
So I'm going to come here and create a new function by saying double
call this mutable inputs
single outputs an end to a long name.
And this takes exactly the same argument as the weighted sample since it's just a wrapper so I'll say
double pointer to an input vector and double pointer to a weight vector and you intended to underscore
T which is input length
open and close over here like this.
And over here I'm gonna have a local variable which I shall call.
Remember these um these functions that we are right in here we know we know sort of right in the most
efficient function to execute the neural network.
This function is optimized for understand ability for you to understand but not for me to run the fastest.
So you need not worry about the fastest most optimized functions will get there we'll write those functions.
And in fact we'll use the CMC as neural network library which already has some of these functions already
implemented in assembly language and we are also going to use that cubed at a library which we would
see how it's optimizes our neural network.
But before we start using such libraries I want you to understand how neural networks work first in
C language.
Dan in Python 10 we use the libraries.
So let's get on with it.
So I'm going to have this local variable here which I shall call double predicted
predicted value like this.
And basically we can call what we did some here wait at some.
And we pass the first argument is inputs which is this one here.
The second argument is wait.
And the third inputs length and the result is going to be
predicted value of course this and we can simply return predicted value
as simple as this.
But this over here has to be this like this right.
Once we are done with this we can expose the function by putting it in the dot each fall like this and
we close this over here.
And once that is done we can try this out in our main function.
So I can clean the old test right.
So let's try it out.
I'm going to put a defined statement just to see the number of input we have going to see a defined
norm on the score of inputs.
And we are going to have three inputs and let's say we have we have data for temperature humidity and
air quality.
And these are stored in the respective arrays.
So let's create such an array in C double
temperature.
Let's say we have five temperature values the first one is 12 Hubble.
Twenty three fifty minus ten.
Just don't mix it up a bit and 16
and we have our humidity data as well
and this one is sixty sixty seven fifty sixty five sixty three top of that and let's say we have our
air quality data as well.
And this is 60 47 167 1 8 2 7 9 2 4.
Okay.
These are just made up values.
I hope you keep that in mind.
Right.
And let's say we have our weight.
Remember let's see.
I want your network again.
You see there is way one way to weight three.
And we have our inputs.
Over here we are showing just the single inputs MLSE.
This is twenty five and there's an entire array of temperature inputs we've just selected one here and
we've selected one from humidity array we've selected another one from air quality and we're showing
how it is computed.
So over here we keep declaring the weight back in neural network when we are dealing with real world
implementation.
We're going to sort of initialize the weights with random numbers we're going to use a random number
generator to initialize random values.
And when we get to the part about learning in machine learning and things like gradient descent you
would understand why we need to start from random numbers rather than stuff from 0 0.
So let's just see our weights here.
We've got minus 2 2 and then 1.
Right.
So I'm going to say okay I'll come over here and see training example one when to create another variable
here double
green e.g. one and this one array.
Training example one would have the face the first input from temperature humidity and air quality cause
we put we put a representative of temperature on that I want a representative of humidity and a representative
of air quality into the neuro network and then we compute how the person feels.
So example one is made up of twelve sixty sixty.
Let me align this properly example one is made up of twelve sixty sixty.
Example Two will be made up of twenty three sixty seven forty seven.
Example three will be made up of fifty fifty one sixty seven.
And so on and so forth by need no.
Uh you know um this is arranged like this because we are right in this neural network and we know how
we've arranged it but if you're using a library example is could be arranged in columns and features
over here.
Temperature is a feature humidity is a feature air quality is a feature the features may be arranged
in columns in and let's see it's training our example could be arranged in rows it doesn't matter.
The library would tell you but over here since we appear within our own neural network functions we
know exactly how our data is arranged and so on and and that allows us to be able to arm to sort of
grasp how it works for those of you who started learning neural network programming just by getting
familiar with a library I hope you would appreciate knowing how things work from behind like this.
Um right.
So um so we said training example one is going to be made up of the first temperature value the second
Hume the first temperature value the first humidity value and the first air quality value.
These are known as our features from when I see a temperature index zero.
We'll grab the first one and um.
Um the next one is humidity index zero.
And the third one is air quality index zero.
Like this.
Right.
So once this is done we can run our prediction we can see a prenup and we can see a prediction for from
train an example or something of that nature
prediction from first
is percentage F and put a new line here and basically
we're simply going to call our function multiple inputs single output function
come over here and see
the first parameter is the input the input vector or the one dimensional array which has the input.
In our case it is straight in example 1 the second parameter is the one dimensional array which has
the weight or the weight vector which we call the weight here and the third argument is the input length.
So this is number of inputs right.
So this is it.
We can build and see what we have
click over here to build it s build successfully Click here to download onto the board it s downloaded
to open terror term.
This is from the old list and I'm going to click to reset my board.
I'm going to come over here.
Claire.
Claire screen.
Reset the board.
And this is it.
So this what we have so you can think of our neural network having a threshold value such that if the
number is above 100 it means the person is happy.
If it's below 100 it means the person is inside.
So we can use we can encode meaning to numerical values and we do that all the time in machine learning.
So this one here has sort of produced a value of 156.
If we've included thresholds and mean into numbers.
We would know what 156 stands for what I happy or sad but in any way this is how to take multiple inputs
and um produce a single output of out of it.
So hence the multiple inputs single output neural network.
But this is a very very simplified way it's designed this way for your understanding so that when you
start dealing with real world examples you can understand it perfectly right.
So that's all there is.
And I'll see you in the next lesson.