1
00:00:00,960 --> 00:00:01,370
Hello.

2
00:00:01,410 --> 00:00:01,900
Welcome back.

3
00:00:02,190 --> 00:00:09,800
So let's see how to build to the hidden layer neuro network.

4
00:00:10,090 --> 00:00:12,960
I'm gonna make a copy of the last project over here.

5
00:00:12,960 --> 00:00:18,180
Copy paste I'm going to call this hidden layer and then

6
00:00:30,360 --> 00:00:30,830
open it.

7
00:00:42,180 --> 00:00:42,830
Right.

8
00:00:42,870 --> 00:00:45,420
So let's take a look at the architecture again.

9
00:00:47,610 --> 00:00:51,680
So that's what the hidden layer neural network looks like.

10
00:00:51,720 --> 00:01:02,180
So we've got our input here and our outputs pass through another layer before we have.

11
00:01:02,180 --> 00:01:08,600
And before we get our output to this computation to run at a layer before we have our output layer.

12
00:01:08,720 --> 00:01:09,570
Right.

13
00:01:09,620 --> 00:01:13,050
And we're already described how we could do this.

14
00:01:13,100 --> 00:01:14,680
So let's implemented in code.

15
00:01:14,690 --> 00:01:19,730
Now this is the pseudo functions we wrote and we're going to write the actual functions now.

16
00:01:20,030 --> 00:01:20,470
Right.

17
00:01:20,480 --> 00:01:22,300
Or minimize this.

18
00:01:22,860 --> 00:01:30,600
And I'm going to go to our neural network to see file and I'm going to create the function is down here.

19
00:01:31,310 --> 00:01:32,110
Right.

20
00:01:32,150 --> 00:01:38,360
So the function we're going to create is going to be called the hidden layer and n and this function

21
00:01:38,360 --> 00:01:41,150
shall take seven argument.

22
00:01:41,150 --> 00:01:44,510
The first argument is going to be the input vector.

23
00:01:44,600 --> 00:01:50,300
Then the next argument is going to be the length of the input and then after the the third argument

24
00:01:50,300 --> 00:01:58,340
will be the the length of the hidden layer which means the number of nodes or the number of units in

25
00:01:58,340 --> 00:01:59,870
the hidden layer.

26
00:02:00,020 --> 00:02:04,390
Whenever I say node or unit just think of this.

27
00:02:05,290 --> 00:02:05,710
Right.

28
00:02:05,720 --> 00:02:08,790
The Psychos are the nodes or the units.

29
00:02:08,990 --> 00:02:09,350
Right.

30
00:02:09,560 --> 00:02:14,060
So I'll just start right in the function here.

31
00:02:14,160 --> 00:02:17,560
Call a void hidden and

32
00:02:25,440 --> 00:02:32,390
well like I said and like I said it takes a number of argument come over here.

33
00:02:32,390 --> 00:02:42,780
The first argument is a pointer to the input vector.

34
00:02:43,650 --> 00:02:48,540
The next argument is the input land you in 232 on the score t

35
00:02:51,070 --> 00:02:59,900
input line like this.

36
00:03:00,530 --> 00:03:21,400
The next argument after this is the length of the hidden layer.

37
00:03:21,660 --> 00:03:25,560
Then the next argument is the input to hidden layer weight.

38
00:03:26,790 --> 00:03:31,490
And that's what I mean by input to hit only a weight the weight for these snaps.

39
00:03:31,560 --> 00:03:33,080
The weight for these are roots.

40
00:03:33,090 --> 00:03:33,850
Yeah.

41
00:03:34,040 --> 00:03:42,350
Inputs to hidden layer weight these weight we're going to pass them as I comment number four.

42
00:03:42,600 --> 00:03:47,360
So it's going to be a two dimensional array or it matrix if you want to call it that

43
00:03:53,690 --> 00:03:59,030
so I'll just call this in to hit weight

44
00:04:01,880 --> 00:04:03,320
and the size is going to be

45
00:04:06,110 --> 00:04:16,060
hit in length the number of rows of course hit in length and the number of columns of course input land.

46
00:04:16,910 --> 00:04:21,680
Once that is done the next argument is going to be the length of the output

47
00:04:40,870 --> 00:04:41,430
after this.

48
00:04:41,440 --> 00:04:49,900
The next argument is going to be hit into output weight the weight for for this side hidden layer 2

49
00:04:49,960 --> 00:04:52,580
outputs layer the weight we need for them.

50
00:04:53,680 --> 00:05:00,300
Oh come over here and this is going to be a two dimensional array as well.

51
00:05:00,300 --> 00:05:05,920
Double I'll she hit out weight

52
00:05:12,090 --> 00:05:15,810
and the first size is output Lent.

53
00:05:15,980 --> 00:05:27,110
Second of size is it in length like this and the next and last argument is a pointer to a vector to

54
00:05:27,110 --> 00:05:28,850
store the 0 attributes

55
00:05:34,190 --> 00:05:38,980
like this right.

56
00:05:39,260 --> 00:05:46,310
So like I mentioned we simply need to perform we simply need to perform a matrix vector multiplication

57
00:05:47,210 --> 00:05:53,230
of the input vector and DMM to head in to inputs weight.

58
00:05:54,200 --> 00:06:02,950
And once we get a result we perform another matrix vector multiplication with a result with the hit

59
00:06:02,960 --> 00:06:05,200
into output layer weight.

60
00:06:05,660 --> 00:06:11,920
So I'm gonna start off by creating a buffer here which is going to be like a crutch array.

61
00:06:12,140 --> 00:06:17,030
Now we're going to use to store the hidden layer predicted values for the hidden layer.

62
00:06:17,900 --> 00:06:26,930
So we need to perform a matrix to vector multiplication using these inputs and these weights these weights

63
00:06:27,500 --> 00:06:28,900
are represented here.

64
00:06:28,970 --> 00:06:31,360
We need to take these inputs this a vector.

65
00:06:31,650 --> 00:06:38,420
It's gonna be a one dimensional array and this two dimensional array the result that we get is going

66
00:06:38,420 --> 00:06:45,290
to be hit in 0 hit in one hit into these are going to be the result and we take this resort and then

67
00:06:45,290 --> 00:06:49,570
we perform another matrix vector multiplication.

68
00:06:49,610 --> 00:06:56,050
But this time with this weight to hit into output weight and after that we get the results for side

69
00:06:56,110 --> 00:06:57,610
sick and active.

70
00:06:57,620 --> 00:07:02,760
So basically this is how a neural network with hidden layer computes the resort.

71
00:07:02,930 --> 00:07:04,870
Right.

72
00:07:04,880 --> 00:07:12,160
So come over here and see double it in predicted value

73
00:07:19,200 --> 00:07:21,050
it is predicted vector.

74
00:07:24,960 --> 00:07:28,650
And this is going to be the size of the hidden layer to hit it.

75
00:07:28,650 --> 00:07:28,920
Then

76
00:07:32,190 --> 00:07:37,240
and then I'll see matrix vector multiplication.

77
00:07:37,340 --> 00:07:40,830
The first argument is going to be the input vector.

78
00:07:40,910 --> 00:07:47,190
The second argument is going to be the length of the input vector which is input land.

79
00:07:47,200 --> 00:07:54,620
The third argument is going to be the output vector and we're going to store the output gonna story

80
00:07:54,660 --> 00:08:00,480
output in this buffer that we've created it in predicted vector values.

81
00:08:01,740 --> 00:08:06,580
So I'm gonna see hidden predicted vector here.

82
00:08:06,660 --> 00:08:08,390
That's where we store the output.

83
00:08:08,700 --> 00:08:18,880
And after this the next argument is what is shown here with the color blue is output land.

84
00:08:19,010 --> 00:08:21,630
Now after this the next argument is

85
00:08:24,670 --> 00:08:26,790
the next argument is the weight matrix

86
00:08:30,360 --> 00:08:31,150
and the weight.

87
00:08:31,150 --> 00:08:38,710
We're going to use is input to hit in weight so pass in to hit and weight right.

88
00:08:39,600 --> 00:08:47,130
So after this computation we're going to have the result stored over here in this buffer here.

89
00:08:47,130 --> 00:08:53,760
So we're going to take this buffer and then hit it to output weight and perform matrix victim with application

90
00:08:53,760 --> 00:08:54,330
again.

91
00:08:54,830 --> 00:08:56,100
So I'm gonna perform another one.

92
00:08:58,530 --> 00:09:05,010
And if we had multiple layers multiple hidden layers we would have to keep computing like this for each

93
00:09:05,010 --> 00:09:06,480
hidden layer.

94
00:09:06,480 --> 00:09:13,020
So it would be nice for you to try adding another hidden layer to the neural net work example and try

95
00:09:13,020 --> 00:09:15,210
to write the function to compute that one.

96
00:09:16,020 --> 00:09:26,130
So I see a matrix vector multiplication and the input vector this time is hit in predicted vector and

97
00:09:26,130 --> 00:09:34,500
the length of this is Headland and we see in Hidden Land it just so happens that in our example I'll

98
00:09:34,500 --> 00:09:43,590
show you it just so happens that in our example the hidden length or number of nodes and the the input

99
00:09:43,590 --> 00:09:48,570
length or number of nodes and the heat in length and the outputs are the same.

100
00:09:48,600 --> 00:09:52,970
It just happens that all have three nodes but you can have two here three here.

101
00:09:52,970 --> 00:09:54,830
Did they come in different forms.

102
00:09:54,990 --> 00:09:59,910
So that is why our function is not just saying give the length.

103
00:09:59,910 --> 00:10:07,050
If we wrote the function to accept just one length value then it's going to be problematic cause our

104
00:10:07,050 --> 00:10:08,520
lives have different length.

105
00:10:08,520 --> 00:10:13,430
That is why we're dealing with hidden length output lint etc..

106
00:10:14,970 --> 00:10:23,510
So the next argument is the output for buffer and we want to store this in the output buffer.

107
00:10:24,110 --> 00:10:27,020
And after that the next argument is the output lend

108
00:10:39,680 --> 00:10:41,580
and then the weight the weights.

109
00:10:41,570 --> 00:10:49,390
Here is the hit into output weight hit two out weights like this.

110
00:10:49,410 --> 00:10:51,500
So this is it.

111
00:10:52,680 --> 00:10:54,150
We can expose this function

112
00:11:19,020 --> 00:11:23,440
and we can go to our main file to test it out.

113
00:11:23,800 --> 00:11:24,710
Gonna come over here

114
00:11:29,210 --> 00:11:29,380
and

115
00:11:32,450 --> 00:11:39,810
I'm going to add a new defined statement here for hidden layer lent or say define.

116
00:11:40,010 --> 00:11:48,610
I did Len the length of the hidden layer is 3 as well right.

117
00:11:48,920 --> 00:11:55,910
And actually I'm going to keep these weights and this time these weights I'm going to make sure these

118
00:11:55,910 --> 00:11:57,570
are the weight for the hidden layer.

119
00:11:57,770 --> 00:11:59,090
So this will be hit zero

120
00:12:08,480 --> 00:12:09,280
hit 1

121
00:12:13,070 --> 00:12:13,790
head to

122
00:12:17,420 --> 00:12:23,150
like we have over here right.

123
00:12:23,630 --> 00:12:25,500
And we need a new set of weight.

124
00:12:25,570 --> 00:12:28,280
We've got to change the name to now.

125
00:12:28,400 --> 00:12:29,270
This is called

126
00:12:33,800 --> 00:12:35,270
input to hit in weight

127
00:12:45,490 --> 00:12:49,450
and it's hidden lent by input land

128
00:13:01,740 --> 00:13:02,290
right.

129
00:13:03,470 --> 00:13:09,480
Okay so we need to create a different set of weights.

130
00:13:09,510 --> 00:13:10,080
Come here

131
00:13:21,680 --> 00:13:22,240
turbo the

132
00:13:36,080 --> 00:13:38,590
this is going to be hit into output layer weight

133
00:13:48,890 --> 00:13:53,930
and output line and then hidden Len

134
00:14:06,520 --> 00:14:10,650
and we can just assign certain weights here let me see.

135
00:14:10,650 --> 00:14:15,270
I'm gonna say minus one point zero

136
00:14:18,640 --> 00:14:32,310
and one point one five zero point one one.

137
00:14:32,660 --> 00:14:45,770
This next one can be minus zero point twenty eight zero point one five minus two points you're one.

138
00:14:46,940 --> 00:14:57,020
And this last one can be zero point two five minus zero point to five minus zero point one.

139
00:14:57,230 --> 00:14:59,690
These are just like I said random numbers

140
00:15:08,280 --> 00:15:10,800
to put a bit of comment here.

141
00:15:13,400 --> 00:15:16,670
So this would give the sad result.

142
00:15:21,790 --> 00:15:25,630
This over here for sick or not sick

143
00:15:38,640 --> 00:15:42,300
and this is for active or not.

144
00:15:42,710 --> 00:15:51,970
And we know that this one is from if want to put this here.

145
00:15:52,670 --> 00:15:57,700
This is input from it and let it hit in here.

146
00:15:58,050 --> 00:15:58,550
Um no.

147
00:15:58,550 --> 00:15:59,750
Zero.

148
00:15:59,750 --> 00:16:09,780
And this is from head 1 and this is form hit 2 right.

149
00:16:09,950 --> 00:16:15,950
Once we have this we can um let's see put a semicolon here

150
00:16:20,390 --> 00:16:28,220
we can use the same input vector we have input vector here so we can come down here and call our function

151
00:16:36,870 --> 00:16:41,370
the function is called hidden layer and then you can simply see it in the

152
00:16:44,170 --> 00:16:49,900
or hidden n in does the name of the function the first argument is the input vector

153
00:16:55,220 --> 00:16:57,230
the second argument is the input lent

154
00:17:00,410 --> 00:17:07,790
the next argument is the hidden layer lent then the next argument is the input to hidden wait

155
00:17:12,880 --> 00:17:21,650
then the next argument is the output lent then the next argument is hidden to output wait

156
00:17:28,160 --> 00:17:29,530
do we have more argument

157
00:17:33,160 --> 00:17:42,030
the next argument is the output vector we don't have which not created an output vector here I'm gonna

158
00:17:42,040 --> 00:17:42,980
come over here.

159
00:17:42,990 --> 00:17:47,050
Okay this one hit predicted output I'm gonna copy this

160
00:17:50,210 --> 00:18:00,430
put it in here put it some call on here like this and um yeah everything else remains the same sad prediction

161
00:18:00,430 --> 00:18:07,100
is going to go here and then seek prediction here and then active prediction here.

162
00:18:07,180 --> 00:18:10,730
Right let's run out code and see what we have.

163
00:18:10,730 --> 00:18:18,660
Click here to build it to be successfully download onto the board let's see Terra to

164
00:18:24,860 --> 00:18:33,130
or reset my board and this is where we have sad prediction sick prediction and active prediction right.

165
00:18:33,230 --> 00:18:36,260
So this order is for this lesson and I'll see you later.
