1
00:00:00,750 --> 00:00:01,310
Hello.

2
00:00:01,380 --> 00:00:02,040
Welcome back.

3
00:00:02,040 --> 00:00:07,220
So let's see how to build these multiple input multiple output neural network.

4
00:00:07,230 --> 00:00:09,840
I'm gonna make a copy of the last project

5
00:00:32,260 --> 00:00:33,290
can open it

6
00:00:46,230 --> 00:00:46,670
right.

7
00:00:46,820 --> 00:00:50,980
So let's take a look at the um the neural network again.

8
00:00:51,050 --> 00:00:52,310
So this what we have.

9
00:00:53,060 --> 00:01:01,550
So we set this time given the temperature humidity and air quality we not only we don't want to only

10
00:01:01,550 --> 00:01:04,080
predict whether you are sad or happy.

11
00:01:04,580 --> 00:01:11,390
We also want to predict whether you are sick or healthy active or inactive.

12
00:01:11,390 --> 00:01:16,550
So given the three inputs we want to get three outputs from it.

13
00:01:16,550 --> 00:01:20,330
And this is what we have right.

14
00:01:20,480 --> 00:01:28,640
So a way of viewing this as we mentioned earlier is to view this as a multiple input single output neural

15
00:01:28,970 --> 00:01:29,780
network.

16
00:01:29,900 --> 00:01:35,940
We can view this as three multiple inputs single output neural networks put together.

17
00:01:36,170 --> 00:01:37,460
And what do I mean by this.

18
00:01:37,460 --> 00:01:44,380
See if we take the the input we can just map all of them to a single output.

19
00:01:44,660 --> 00:01:49,460
If we take the input again we map all of them to another single output and then we take all the input

20
00:01:49,460 --> 00:01:52,550
we map all of them to a single output again.

21
00:01:52,550 --> 00:01:59,090
So essentially this is three X multiple inputs single output neural networks put together.

22
00:01:59,660 --> 00:02:01,960
So let's see how to implement this.

23
00:02:02,320 --> 00:02:08,330
I'm going to come to our neural network to see file and what we're going to do is create a function

24
00:02:08,330 --> 00:02:11,730
known as matrix vector multiplication.

25
00:02:12,040 --> 00:02:21,140
And why am I saying matrix vector multiplication is because our weights are going to be stored in a

26
00:02:21,140 --> 00:02:23,350
matrix right.

27
00:02:24,230 --> 00:02:29,880
We're going to have the weight we're going to have a two dimensional array.

28
00:02:29,930 --> 00:02:33,710
And when I say matrix just think of a two dimensional array.

29
00:02:33,710 --> 00:02:34,970
For those of you who don't know.

30
00:02:35,600 --> 00:02:36,090
Um.

31
00:02:36,140 --> 00:02:38,900
So over here we have a two dimensional array.

32
00:02:38,990 --> 00:02:50,160
The first row belongs to side the first row it's made up of weight that we use to compute the sad result.

33
00:02:50,180 --> 00:02:55,830
The second row belongs to weight that we used to compute the sick resort.

34
00:02:55,850 --> 00:02:59,760
The third row belongs to weight that we used to compute the active resort.

35
00:03:00,140 --> 00:03:07,120
And when we want to view them in column in terms of columns all fares columns belong to weight that

36
00:03:07,130 --> 00:03:13,400
we compute with the temperature input all second columns belong to weights that we compute with the

37
00:03:13,400 --> 00:03:19,520
humidity input and all third columns belong to weights that we compute the air quality input.

38
00:03:20,120 --> 00:03:27,290
So we're going to keep all of this back together in a matrix or two dimensional array and then we're

39
00:03:27,290 --> 00:03:27,860
going to

40
00:03:30,910 --> 00:03:40,170
and then we're going to sort of multiplied by effector rights and the vector is going to be our input

41
00:03:40,180 --> 00:03:45,930
because we have just three inputs and we have this weight.

42
00:03:45,980 --> 00:03:48,120
The input is going to be one dimensional Larry.

43
00:03:48,140 --> 00:03:49,400
Therefore it is a vector.

44
00:03:50,030 --> 00:03:53,800
And the weight as we've described here is a matrix two dimensional.

45
00:03:53,800 --> 00:04:01,420
Hence we going to write a function to perform matrix vector multiplication or vector make matrix multiplication.

46
00:04:01,430 --> 00:04:03,790
However you want to call it so.

47
00:04:03,800 --> 00:04:08,450
Okay I'll come down here and then

48
00:04:15,390 --> 00:04:18,080
let's see come down here.

49
00:04:18,100 --> 00:04:20,270
I'll create a new function void.

50
00:04:21,460 --> 00:04:22,240
I'm assuming a bit

51
00:04:28,250 --> 00:04:30,050
void matrix

52
00:04:34,590 --> 00:04:38,440
vector multiplication like this.

53
00:04:39,270 --> 00:04:44,930
The first argument is going to be of type double and we're going to take a pointer to the input for

54
00:04:44,930 --> 00:04:45,240
actual

55
00:04:52,300 --> 00:05:01,700
The second argument is gonna be the inputs length.

56
00:05:02,450 --> 00:05:04,910
We can see you into 30 to 40

57
00:05:10,430 --> 00:05:12,150
inputs land.

58
00:05:12,470 --> 00:05:19,070
The third argument is going to be effector to store the output because the output is going to be three

59
00:05:19,070 --> 00:05:19,940
different values.

60
00:05:20,030 --> 00:05:22,250
So we can store them in a one dimensional array.

61
00:05:23,210 --> 00:05:33,490
So we are going to go back to you into 30 to underscore t and we said a vector to store the output.

62
00:05:33,500 --> 00:05:38,090
So we see a double star you can call this output vector

63
00:05:44,750 --> 00:05:47,380
and we can to improve readability.

64
00:05:47,390 --> 00:05:51,700
We can just see another variable to store the outputs leant in.

65
00:05:51,730 --> 00:05:55,340
In our case the output length is the same as the inputs length.

66
00:05:55,470 --> 00:05:56,830
It's not always the case.

67
00:05:56,930 --> 00:06:03,890
If we said we just wanted to uh if we said if we said we just wanted to predict sad and sick without

68
00:06:03,980 --> 00:06:07,230
active then the outputs length it would be just too.

69
00:06:07,260 --> 00:06:12,470
But this is just a coincidence that the input length is the same as the output length.

70
00:06:12,470 --> 00:06:17,960
So if you want to try with a different neural network then let's make the output length flexible such

71
00:06:17,960 --> 00:06:25,240
that you can pass an argument for your new output length or your custom output land.

72
00:06:25,370 --> 00:06:31,220
I'm gonna say in that to underscore T over here you outlined

73
00:06:34,080 --> 00:06:43,680
and the last argument is going to be a matrix to hold the weights and it's gonna be of type double

74
00:06:49,280 --> 00:06:52,670
going to call this weight matrix

75
00:06:55,760 --> 00:07:00,860
put an S over here and the size of this

76
00:07:04,140 --> 00:07:05,760
is gonna be output length.

77
00:07:06,270 --> 00:07:09,360
How do we know the size we can see from our image here.

78
00:07:09,510 --> 00:07:18,600
The size of this is going to be the rows equal to the number of output at the columns because the number

79
00:07:18,600 --> 00:07:22,800
of input you see the first row belongs to side which is an output.

80
00:07:22,890 --> 00:07:26,470
Second row sic output third row active.

81
00:07:26,580 --> 00:07:33,030
So the rows number of rows of course number of output and number of columns because number of inputs

82
00:07:34,260 --> 00:07:37,110
so the size here is going to be output length

83
00:07:40,590 --> 00:07:42,510
and input length here like this

84
00:07:47,530 --> 00:07:48,490
and open

85
00:07:52,390 --> 00:07:54,630
and close.

86
00:07:54,820 --> 00:07:55,570
Right.

87
00:07:55,630 --> 00:08:04,450
So now we can implement this and we are going to use a that for loop to help us do this.

88
00:08:04,830 --> 00:08:07,900
Let's see you start off by saying for

89
00:08:12,150 --> 00:08:18,580
I say 4 into K equals zero K is less than the output lent

90
00:08:26,620 --> 00:08:33,040
K plus plus an inside this I'm going to do for I

91
00:08:36,800 --> 00:08:43,580
for int i equals your eye is less than the input line.

92
00:08:46,350 --> 00:08:50,830
And a plus plus open and close.

93
00:08:50,830 --> 00:08:58,040
And what we are essentially trying to do is come over here take this.

94
00:08:58,490 --> 00:09:01,820
Finish processing this row and then go to the next row.

95
00:09:02,140 --> 00:09:05,680
Because remember input Len represent the rows.

96
00:09:05,680 --> 00:09:11,850
The number of rows so the outer loop is the number of rows the inner loop is the number of input.

97
00:09:11,860 --> 00:09:19,870
So when we come we first come to rule 1 and then we we process these values and then we go to row to

98
00:09:19,870 --> 00:09:22,450
process these values and they rule 3.

99
00:09:22,450 --> 00:09:31,660
That is what our nested for loop here would do for us and all we have to do here is say output vector

100
00:09:31,870 --> 00:09:47,750
index K plus we use our accumulator we say input vector index I times.

101
00:09:47,750 --> 00:09:49,920
Wait wait.

102
00:09:49,920 --> 00:09:54,760
Matrix index K index I.

103
00:09:55,180 --> 00:09:57,380
So you understand index K here.

104
00:09:57,400 --> 00:10:00,220
So we first though it k equals zero.

105
00:10:00,400 --> 00:10:01,980
And then ask k equals zero.

106
00:10:01,990 --> 00:10:05,020
We do K equals zero equals zero K.

107
00:10:05,030 --> 00:10:09,520
Cause your I equals 1 k equals zero aqueous 2.

108
00:10:09,520 --> 00:10:12,100
So K equals zero represent this rule.

109
00:10:12,100 --> 00:10:15,250
K equals zero equals zero is zero point two K.

110
00:10:15,250 --> 00:10:22,870
Close your eyes because 1 it represents you point one K cause your eye equals to represent zero point

111
00:10:22,870 --> 00:10:23,310
five.

112
00:10:23,590 --> 00:10:30,750
So we process this and then it becomes k equals 1 and then we do K K was 1 equals U K equals 1 I of

113
00:10:30,790 --> 00:10:33,370
course one in a K cos one equals two.

114
00:10:33,370 --> 00:10:35,570
And then it becomes k equals 2.

115
00:10:35,710 --> 00:10:38,170
Over here I know you get it.

116
00:10:38,500 --> 00:10:39,470
Okay.

117
00:10:39,910 --> 00:10:42,440
So that's how we will process this.

118
00:10:42,490 --> 00:10:47,290
So this all we have to write for this and we can wrap it around our function known as multiple input

119
00:10:47,320 --> 00:10:51,490
multiple output and n come over here.

120
00:10:51,500 --> 00:10:52,240
Void

121
00:10:55,130 --> 00:10:56,830
what will inputs

122
00:11:01,250 --> 00:11:04,770
which will outputs n n.

123
00:11:06,000 --> 00:11:10,950
And we take the same document a copy over here.

124
00:11:13,530 --> 00:11:13,950
Okay

125
00:11:18,510 --> 00:11:19,680
um let's see

126
00:11:22,800 --> 00:11:29,070
come down here and open and close.

127
00:11:35,980 --> 00:11:36,480
Right.

128
00:11:36,500 --> 00:11:44,300
And we simply need to call our function our matrix vector multiplication function

129
00:11:49,930 --> 00:11:54,010
and we pass the same document the first one is input vector

130
00:11:57,990 --> 00:11:59,490
the second one is input lent

131
00:12:02,700 --> 00:12:04,200
the first output vector

132
00:12:07,350 --> 00:12:12,420
then outputs land and then way to matrix

133
00:12:16,430 --> 00:12:17,290
right.

134
00:12:17,330 --> 00:12:23,540
So put a semicolon here and we can expose this function

135
00:12:29,130 --> 00:12:30,040
bring it over here

136
00:12:38,600 --> 00:12:41,150
patient over here on a semicolon here

137
00:12:53,120 --> 00:12:54,970
right.

138
00:12:55,280 --> 00:13:00,100
So we can try it out in our main file.

139
00:13:00,110 --> 00:13:01,700
We can start off okay.

140
00:13:01,700 --> 00:13:05,000
We have sat here at zero point nine.

141
00:13:06,140 --> 00:13:07,610
We don't need this.

142
00:13:07,670 --> 00:13:10,820
We can just clean everything to prevent confusion.

143
00:13:17,200 --> 00:13:17,560
Right.

144
00:13:18,220 --> 00:13:23,260
So I'm gonna put some defined statements here to hold the indices.

145
00:13:23,560 --> 00:13:33,960
I'm gonna see a sad prediction index.

146
00:13:34,990 --> 00:13:44,140
So the resort offside is going to be stored in the first index of the output vector.

147
00:13:44,140 --> 00:13:46,140
Then we're gonna have six prediction index.

148
00:13:50,950 --> 00:13:57,340
So it's sad or happy sick or healthy active or inactive

149
00:14:16,020 --> 00:14:22,570
and then when I say define output length here

150
00:14:38,820 --> 00:14:40,320
defined in Poland

151
00:14:43,020 --> 00:14:47,470
and we know our input is three in our output is three as well.

152
00:14:47,470 --> 00:14:53,890
That's why I'm pausing three and three here and we have to create the effect or to hold the predicted

153
00:14:53,890 --> 00:14:54,400
values

154
00:15:11,260 --> 00:15:12,410
like this.

155
00:15:12,940 --> 00:15:13,790
Right.

156
00:15:13,840 --> 00:15:15,220
So this what we have now.

157
00:15:15,250 --> 00:15:20,250
Okay let's declare our wait let's say double.

158
00:15:20,980 --> 00:15:31,050
Remember we said a way is a two dimensional array and I'm going to say weights and the sizes outputs

159
00:15:31,060 --> 00:15:42,600
led by inputs Len.

160
00:15:44,360 --> 00:15:50,240
So the first row belongs to the decide prediction.

161
00:15:50,240 --> 00:15:52,910
So we can see it a way to minus zero point two

162
00:15:55,630 --> 00:15:57,780
hope on nine point five.

163
00:15:59,120 --> 00:16:05,530
And then let's see two points 0 1 over there and then we go to row 2.

164
00:16:05,640 --> 00:16:07,860
This is going to be for the sake of prediction

165
00:16:11,410 --> 00:16:20,160
C minus four point eight seven point two six point three.

166
00:16:20,320 --> 00:16:22,310
And then we can go to the third row.

167
00:16:22,750 --> 00:16:27,170
There's going to be for the active prediction.

168
00:16:27,600 --> 00:16:32,990
C minus four point five point four five.

169
00:16:33,010 --> 00:16:34,660
And let's say zero point nine

170
00:16:38,080 --> 00:16:38,890
like this.

171
00:16:38,890 --> 00:16:41,350
And so I just put a bit of comment here.

172
00:16:53,890 --> 00:16:57,880
The first column belongs to temperature.

173
00:16:57,880 --> 00:17:04,770
The temperature puts the second column as humidity and this one the last one is air quality.

174
00:17:04,780 --> 00:17:08,950
And when we want to view it according to Rose The first rule belongs to Saad

175
00:17:12,110 --> 00:17:13,660
Sardo happy.

176
00:17:13,700 --> 00:17:24,000
The second rule is sick or healthy and the last rule is active or inactive.

177
00:17:24,890 --> 00:17:25,340
Right.

178
00:17:25,430 --> 00:17:32,090
So once we've done this less let's say we have some input I'm going to create an input vector here

179
00:17:42,140 --> 00:17:44,860
and the length of the vector is the inline

180
00:17:50,680 --> 00:18:01,610
and we can see temperatures 30 degrees Celsius and humidity we can see it's 87.

181
00:18:01,720 --> 00:18:11,140
Air quality can be at 110 and it will be helpful to have a comment here showing you our input arrangement

182
00:18:11,140 --> 00:18:11,590
as well

183
00:18:30,140 --> 00:18:30,710
right.

184
00:18:30,710 --> 00:18:34,760
So once they start we can call our new network function.

185
00:18:34,970 --> 00:18:37,880
So I'm going to come over here and say

186
00:18:41,540 --> 00:18:48,830
multiple inputs multiple up and the first document as you can see over here is the input vector which

187
00:18:48,830 --> 00:18:53,860
we call input or input vector here.

188
00:18:53,960 --> 00:18:59,340
The second argument as you can see over here is the output vector.

189
00:19:00,650 --> 00:19:08,460
And we call that I think the second argument is the input length and we have a defined statement to

190
00:19:08,580 --> 00:19:11,780
that in Len.

191
00:19:11,780 --> 00:19:21,080
The third argument is the output vector which we call predicted output.

192
00:19:21,080 --> 00:19:26,890
The next argument is the output length which we have out Len.

193
00:19:28,310 --> 00:19:32,900
The argument following that is the the weight matrix which we call weight

194
00:19:36,500 --> 00:19:40,090
and that's all right.

195
00:19:40,820 --> 00:19:48,470
So we can print some resorts here or come over here and see print f

196
00:19:52,070 --> 00:20:05,570
sad prediction but this percentage F and then output courage return and then what I want is a one to

197
00:20:05,570 --> 00:20:14,870
go to our predicted output vector and navigate to the sad prediction sad prediction index and I can

198
00:20:14,870 --> 00:20:20,990
do the same for the rest sake prediction and active prediction

199
00:20:46,620 --> 00:20:47,210
right.

200
00:20:47,220 --> 00:20:51,130
So this order is I've got to build and see what it looks like.

201
00:20:52,290 --> 00:20:58,710
We've got no arrow Click here to download onto the board let us open to return

202
00:21:03,080 --> 00:21:05,370
or reset my board.

203
00:21:05,400 --> 00:21:07,650
So this what we have.

204
00:21:08,100 --> 00:21:08,820
Right.

205
00:21:08,850 --> 00:21:17,310
So based on the weight this what we get sad prediction is this sick prediction is that an active prediction

206
00:21:17,470 --> 00:21:25,350
and like I said the meaning of all of this can just be a way of encode in words to numbers such that

207
00:21:25,350 --> 00:21:31,380
we know a particular numerical value represents what are you sad or sick.

208
00:21:31,540 --> 00:21:37,170
And that I want to represent what you are you know whether you are sad or happy and I want to represent

209
00:21:37,170 --> 00:21:45,510
what I you are sick or healthy etc. So this how to implement the multiple input multiple output neural

210
00:21:45,520 --> 00:21:47,730
network and I'll see you in the next lesson.
