1
00:00:00,780 --> 00:00:06,750
So let's see how to build to multiple inputs single output neural network.

2
00:00:06,750 --> 00:00:13,170
I'm gonna make a copy of our last project copy paste or rename this

3
00:00:28,970 --> 00:00:30,250
and I'm going to open it

4
00:00:42,220 --> 00:00:42,810
right.

5
00:00:42,820 --> 00:00:43,660
So.

6
00:00:43,660 --> 00:00:45,900
So let's take a look at our neural network.

7
00:00:46,720 --> 00:00:53,680
So this time we said we have temperature humidity and air quality and all of these three parameters

8
00:00:53,800 --> 00:01:01,030
influence what a person is happy or sad and what we want to see how to design a neuro network that takes

9
00:01:01,030 --> 00:01:07,360
these three inputs to produce the the output which is whether the person is feeling happy or sad.

10
00:01:07,840 --> 00:01:09,670
Let's see how we do that.

11
00:01:09,670 --> 00:01:17,700
So let's go to our simple neural networks dot see file and create a new function the right.

12
00:01:18,720 --> 00:01:23,820
And we said we have to perform what is known as the weighted sum in order to compute this.

13
00:01:24,270 --> 00:01:27,630
So I'm going to create a new function over here known as weighted sum

14
00:01:30,450 --> 00:01:35,530
and one thing we can do actually is to make this interest.

15
00:01:35,550 --> 00:01:39,380
And we can start using double as the data type.

16
00:01:40,920 --> 00:01:41,910
I'll just train the dog.

17
00:01:42,080 --> 00:01:46,440
Uh the data type of our first function here too of type double.

18
00:01:46,440 --> 00:02:00,230
So we can have floating point numbers gonna change over here as well in the dot age for.

19
00:02:00,920 --> 00:02:06,170
So if we come over here to the main this has to be double

20
00:02:08,900 --> 00:02:11,960
this has to be double as well.

21
00:02:11,960 --> 00:02:19,040
And this over here percentage D becomes spits percentage F right.

22
00:02:19,640 --> 00:02:22,310
So let's implement our new function.

23
00:02:22,940 --> 00:02:23,930
I'll come over here.

24
00:02:23,930 --> 00:02:27,860
This function is going to return type double and I'll call this weighted some

25
00:02:32,750 --> 00:02:33,650
open closed.

26
00:02:34,160 --> 00:02:37,220
This function is going to take three arguments.

27
00:02:37,220 --> 00:02:44,330
The first argument is going to be a pointer to the input the input could be a vector which is a one

28
00:02:44,330 --> 00:02:45,750
dimensional Larry.

29
00:02:45,800 --> 00:02:52,370
The second argument is going to be the pointer to the weight the weight is going to be a vector as well

30
00:02:52,550 --> 00:02:54,950
which is a one dimensional array for this example.

31
00:02:54,950 --> 00:02:56,730
It doesn't always have to be a vector.

32
00:02:56,930 --> 00:03:02,150
When we start dealing with real world machine learning examples all of this will begin to make sense

33
00:03:02,240 --> 00:03:03,960
and you would understand.

34
00:03:04,010 --> 00:03:08,020
And the third argument of the function is going to be the length of the input.

35
00:03:08,160 --> 00:03:15,710
So I'm gonna come over here and simply see a double star input and then

36
00:03:18,730 --> 00:03:21,630
double star wait.

37
00:03:21,740 --> 00:03:23,360
And this last one.

38
00:03:23,360 --> 00:03:28,870
We can see you in 3 2 score T.

39
00:03:29,030 --> 00:03:30,780
And we can call this inputs land

40
00:03:33,610 --> 00:03:37,510
like this open and close.

41
00:03:37,800 --> 00:03:39,040
Right.

42
00:03:39,070 --> 00:03:41,320
So let's come over here.

43
00:03:41,320 --> 00:03:48,230
Create a local variable here which I shall call double output.

44
00:03:48,310 --> 00:03:53,210
And I'm simply going to use a for loop to implement the weighted sum.

45
00:03:53,410 --> 00:03:53,950
Right.

46
00:03:53,980 --> 00:04:01,610
We implement a weighted sum over here is basically input 1 multiplied by which 1.

47
00:04:02,080 --> 00:04:08,890
And then we get product 1 input to multiply by we 2 we get product to input 3 multiplied by we 3 we

48
00:04:08,890 --> 00:04:14,170
get product 3 and then we do product 1 plus product 2 plus product 3.

49
00:04:14,170 --> 00:04:18,910
That is how we get the output that is essentially the weighted sum.

50
00:04:19,180 --> 00:04:19,450
Right.

51
00:04:19,450 --> 00:04:25,300
So I'm gonna come over here and play a trick using the for loop.

52
00:04:25,580 --> 00:04:35,590
So for int i equals zero is less than the input length I plus plus.

53
00:04:35,590 --> 00:04:38,740
And we're going to do exactly what I just explained.

54
00:04:38,740 --> 00:04:41,860
We're going to use this as an accumulator.

55
00:04:42,070 --> 00:04:46,180
So I'm gonna say output accumulates

56
00:04:48,970 --> 00:04:53,980
input array remember input.

57
00:04:54,160 --> 00:05:01,930
This is a pointer to an input our race or we can say input array index I multiply by weight array index

58
00:05:01,930 --> 00:05:06,960
i and it's as simple as this.

59
00:05:06,970 --> 00:05:07,670
Right.

60
00:05:07,750 --> 00:05:12,870
And we can come out here and return the output.

61
00:05:13,030 --> 00:05:18,040
Right okay so this are a weighted sum function.

62
00:05:18,150 --> 00:05:26,250
So are we going to wrap our multiple inputs single output and end around this weighted sum just to make

63
00:05:26,250 --> 00:05:27,600
it much more readable.

64
00:05:27,600 --> 00:05:30,690
So I'm going to come here and create a new function by saying double

65
00:05:34,370 --> 00:05:36,270
call this mutable inputs

66
00:05:39,480 --> 00:05:43,970
single outputs an end to a long name.

67
00:05:44,670 --> 00:05:51,000
And this takes exactly the same argument as the weighted sample since it's just a wrapper so I'll say

68
00:05:52,170 --> 00:06:03,930
double pointer to an input vector and double pointer to a weight vector and you intended to underscore

69
00:06:04,020 --> 00:06:06,960
T which is input length

70
00:06:11,590 --> 00:06:16,690
open and close over here like this.

71
00:06:16,690 --> 00:06:21,600
And over here I'm gonna have a local variable which I shall call.

72
00:06:21,970 --> 00:06:29,980
Remember these um these functions that we are right in here we know we know sort of right in the most

73
00:06:30,130 --> 00:06:33,480
efficient function to execute the neural network.

74
00:06:33,520 --> 00:06:41,170
This function is optimized for understand ability for you to understand but not for me to run the fastest.

75
00:06:41,170 --> 00:06:48,380
So you need not worry about the fastest most optimized functions will get there we'll write those functions.

76
00:06:48,670 --> 00:06:55,240
And in fact we'll use the CMC as neural network library which already has some of these functions already

77
00:06:55,240 --> 00:07:02,020
implemented in assembly language and we are also going to use that cubed at a library which we would

78
00:07:02,020 --> 00:07:04,780
see how it's optimizes our neural network.

79
00:07:04,780 --> 00:07:10,750
But before we start using such libraries I want you to understand how neural networks work first in

80
00:07:10,750 --> 00:07:11,500
C language.

81
00:07:11,500 --> 00:07:14,710
Dan in Python 10 we use the libraries.

82
00:07:14,890 --> 00:07:17,840
So let's get on with it.

83
00:07:18,190 --> 00:07:24,070
So I'm going to have this local variable here which I shall call double predicted

84
00:07:27,910 --> 00:07:31,010
predicted value like this.

85
00:07:31,030 --> 00:07:37,770
And basically we can call what we did some here wait at some.

86
00:07:37,960 --> 00:07:45,280
And we pass the first argument is inputs which is this one here.

87
00:07:45,280 --> 00:07:48,040
The second argument is wait.

88
00:07:48,560 --> 00:07:54,760
And the third inputs length and the result is going to be

89
00:07:57,870 --> 00:08:02,670
predicted value of course this and we can simply return predicted value

90
00:08:06,760 --> 00:08:08,160
as simple as this.

91
00:08:08,270 --> 00:08:15,730
But this over here has to be this like this right.

92
00:08:15,730 --> 00:08:23,500
Once we are done with this we can expose the function by putting it in the dot each fall like this and

93
00:08:23,590 --> 00:08:25,460
we close this over here.

94
00:08:26,170 --> 00:08:30,810
And once that is done we can try this out in our main function.

95
00:08:31,030 --> 00:08:36,030
So I can clean the old test right.

96
00:08:36,040 --> 00:08:37,870
So let's try it out.

97
00:08:37,900 --> 00:08:43,030
I'm going to put a defined statement just to see the number of input we have going to see a defined

98
00:08:48,410 --> 00:08:52,080
norm on the score of inputs.

99
00:08:53,180 --> 00:09:00,830
And we are going to have three inputs and let's say we have we have data for temperature humidity and

100
00:09:01,970 --> 00:09:02,570
air quality.

101
00:09:02,600 --> 00:09:05,290
And these are stored in the respective arrays.

102
00:09:05,300 --> 00:09:08,240
So let's create such an array in C double

103
00:09:12,880 --> 00:09:14,000
temperature.

104
00:09:14,770 --> 00:09:21,880
Let's say we have five temperature values the first one is 12 Hubble.

105
00:09:21,970 --> 00:09:26,590
Twenty three fifty minus ten.

106
00:09:26,650 --> 00:09:28,660
Just don't mix it up a bit and 16

107
00:09:31,600 --> 00:09:36,670
and we have our humidity data as well

108
00:09:47,460 --> 00:09:58,410
and this one is sixty sixty seven fifty sixty five sixty three top of that and let's say we have our

109
00:09:58,500 --> 00:10:00,190
air quality data as well.

110
00:10:08,310 --> 00:10:18,480
And this is 60 47 167 1 8 2 7 9 2 4.

111
00:10:18,540 --> 00:10:18,920
Okay.

112
00:10:18,930 --> 00:10:20,520
These are just made up values.

113
00:10:20,520 --> 00:10:22,590
I hope you keep that in mind.

114
00:10:22,590 --> 00:10:23,140
Right.

115
00:10:23,160 --> 00:10:25,460
And let's say we have our weight.

116
00:10:25,860 --> 00:10:26,790
Remember let's see.

117
00:10:26,790 --> 00:10:28,060
I want your network again.

118
00:10:28,080 --> 00:10:32,180
You see there is way one way to weight three.

119
00:10:32,580 --> 00:10:34,380
And we have our inputs.

120
00:10:34,530 --> 00:10:39,540
Over here we are showing just the single inputs MLSE.

121
00:10:39,720 --> 00:10:44,880
This is twenty five and there's an entire array of temperature inputs we've just selected one here and

122
00:10:44,880 --> 00:10:49,770
we've selected one from humidity array we've selected another one from air quality and we're showing

123
00:10:49,770 --> 00:10:51,660
how it is computed.

124
00:10:51,930 --> 00:10:58,110
So over here we keep declaring the weight back in neural network when we are dealing with real world

125
00:10:58,110 --> 00:10:59,490
implementation.

126
00:10:59,490 --> 00:11:06,300
We're going to sort of initialize the weights with random numbers we're going to use a random number

127
00:11:06,300 --> 00:11:09,270
generator to initialize random values.

128
00:11:09,270 --> 00:11:14,940
And when we get to the part about learning in machine learning and things like gradient descent you

129
00:11:14,940 --> 00:11:20,470
would understand why we need to start from random numbers rather than stuff from 0 0.

130
00:11:20,580 --> 00:11:22,640
So let's just see our weights here.

131
00:11:22,650 --> 00:11:27,270
We've got minus 2 2 and then 1.

132
00:11:28,080 --> 00:11:31,560
Right.

133
00:11:31,830 --> 00:11:32,230
Right.

134
00:11:32,400 --> 00:11:40,650
So I'm going to say okay I'll come over here and see training example one when to create another variable

135
00:11:40,650 --> 00:11:42,090
here double

136
00:11:49,030 --> 00:11:52,850
green e.g. one and this one array.

137
00:11:52,840 --> 00:12:02,170
Training example one would have the face the first input from temperature humidity and air quality cause

138
00:12:02,380 --> 00:12:10,570
we put we put a representative of temperature on that I want a representative of humidity and a representative

139
00:12:11,020 --> 00:12:15,580
of air quality into the neuro network and then we compute how the person feels.

140
00:12:15,580 --> 00:12:19,120
So example one is made up of twelve sixty sixty.

141
00:12:19,990 --> 00:12:25,240
Let me align this properly example one is made up of twelve sixty sixty.

142
00:12:25,270 --> 00:12:29,130
Example Two will be made up of twenty three sixty seven forty seven.

143
00:12:29,140 --> 00:12:33,010
Example three will be made up of fifty fifty one sixty seven.

144
00:12:33,850 --> 00:12:35,970
And so on and so forth by need no.

145
00:12:36,070 --> 00:12:44,500
Uh you know um this is arranged like this because we are right in this neural network and we know how

146
00:12:44,770 --> 00:12:51,610
we've arranged it but if you're using a library example is could be arranged in columns and features

147
00:12:53,150 --> 00:12:53,920
over here.

148
00:12:53,950 --> 00:12:59,620
Temperature is a feature humidity is a feature air quality is a feature the features may be arranged

149
00:13:00,220 --> 00:13:06,250
in columns in and let's see it's training our example could be arranged in rows it doesn't matter.

150
00:13:06,250 --> 00:13:10,960
The library would tell you but over here since we appear within our own neural network functions we

151
00:13:10,960 --> 00:13:19,120
know exactly how our data is arranged and so on and and that allows us to be able to arm to sort of

152
00:13:19,120 --> 00:13:25,600
grasp how it works for those of you who started learning neural network programming just by getting

153
00:13:25,600 --> 00:13:31,910
familiar with a library I hope you would appreciate knowing how things work from behind like this.

154
00:13:32,180 --> 00:13:33,430
Um right.

155
00:13:33,430 --> 00:13:40,390
So um so we said training example one is going to be made up of the first temperature value the second

156
00:13:40,390 --> 00:13:44,650
Hume the first temperature value the first humidity value and the first air quality value.

157
00:13:44,660 --> 00:13:48,250
These are known as our features from when I see a temperature index zero.

158
00:13:48,330 --> 00:13:52,390
We'll grab the first one and um.

159
00:13:52,630 --> 00:13:57,280
Um the next one is humidity index zero.

160
00:13:57,610 --> 00:14:02,070
And the third one is air quality index zero.

161
00:14:02,140 --> 00:14:04,320
Like this.

162
00:14:05,170 --> 00:14:06,210
Right.

163
00:14:06,250 --> 00:14:15,490
So once this is done we can run our prediction we can see a prenup and we can see a prediction for from

164
00:14:15,620 --> 00:14:18,670
train an example or something of that nature

165
00:14:24,300 --> 00:14:28,230
prediction from first

166
00:14:36,700 --> 00:14:44,620
is percentage F and put a new line here and basically

167
00:14:47,870 --> 00:14:51,770
we're simply going to call our function multiple inputs single output function

168
00:14:56,560 --> 00:14:57,580
come over here and see

169
00:15:01,470 --> 00:15:08,670
the first parameter is the input the input vector or the one dimensional array which has the input.

170
00:15:08,790 --> 00:15:15,420
In our case it is straight in example 1 the second parameter is the one dimensional array which has

171
00:15:15,420 --> 00:15:23,540
the weight or the weight vector which we call the weight here and the third argument is the input length.

172
00:15:23,850 --> 00:15:29,240
So this is number of inputs right.

173
00:15:29,280 --> 00:15:30,260
So this is it.

174
00:15:30,330 --> 00:15:32,550
We can build and see what we have

175
00:15:35,760 --> 00:15:42,960
click over here to build it s build successfully Click here to download onto the board it s downloaded

176
00:15:43,300 --> 00:15:45,240
to open terror term.

177
00:15:45,530 --> 00:15:50,660
This is from the old list and I'm going to click to reset my board.

178
00:15:50,700 --> 00:15:52,350
I'm going to come over here.

179
00:15:52,380 --> 00:15:53,340
Claire.

180
00:15:53,340 --> 00:15:54,230
Claire screen.

181
00:15:54,330 --> 00:15:56,490
Reset the board.

182
00:15:56,490 --> 00:15:57,120
And this is it.

183
00:15:57,600 --> 00:16:04,230
So this what we have so you can think of our neural network having a threshold value such that if the

184
00:16:04,230 --> 00:16:07,570
number is above 100 it means the person is happy.

185
00:16:07,830 --> 00:16:11,380
If it's below 100 it means the person is inside.

186
00:16:11,580 --> 00:16:18,750
So we can use we can encode meaning to numerical values and we do that all the time in machine learning.

187
00:16:18,780 --> 00:16:23,390
So this one here has sort of produced a value of 156.

188
00:16:23,610 --> 00:16:28,250
If we've included thresholds and mean into numbers.

189
00:16:28,350 --> 00:16:35,550
We would know what 156 stands for what I happy or sad but in any way this is how to take multiple inputs

190
00:16:35,670 --> 00:16:39,750
and um produce a single output of out of it.

191
00:16:39,750 --> 00:16:43,400
So hence the multiple inputs single output neural network.

192
00:16:43,410 --> 00:16:49,950
But this is a very very simplified way it's designed this way for your understanding so that when you

193
00:16:49,950 --> 00:16:55,710
start dealing with real world examples you can understand it perfectly right.

194
00:16:55,770 --> 00:16:56,750
So that's all there is.

195
00:16:56,760 --> 00:16:58,560
And I'll see you in the next lesson.
