1
00:00:00,490 --> 00:00:07,180
Now we need to calculate the loss and actually calculating the loss in neural network is a very big

2
00:00:07,180 --> 00:00:12,190
deal because what we basically do, we feed data.

3
00:00:12,900 --> 00:00:15,480
Calculate the loss and change the weights.

4
00:00:15,480 --> 00:00:22,800
So it's quite important and this is why we need to be very careful about it.

5
00:00:24,050 --> 00:00:26,450
And it will take a big chunk of our coal.

6
00:00:27,450 --> 00:00:28,770
So self.

7
00:00:29,740 --> 00:00:30,430
Dot.

8
00:00:31,090 --> 00:00:34,240
We start by, of course, identifying the loss.

9
00:00:34,240 --> 00:00:37,120
We need a criterion.

10
00:00:38,380 --> 00:00:41,170
Equals torch dot n n.

11
00:00:41,350 --> 00:00:46,210
And we will use the sample mean squared error loss.

12
00:00:50,470 --> 00:00:53,500
And we give an iteration value.

13
00:00:54,850 --> 00:00:55,510
Of one.

14
00:00:56,020 --> 00:01:01,090
So here we already finished the defining the init method.

15
00:01:02,380 --> 00:01:07,570
And now what we will do is we need to define the loss function.

16
00:01:09,280 --> 00:01:10,210
Function.

17
00:01:12,020 --> 00:01:15,200
And we call self.

18
00:01:16,380 --> 00:01:24,420
And then we, we well, we, we start by zero zero gradient.

19
00:01:24,450 --> 00:01:28,890
Of course, this function is not just defining the loss, it's actually the process of calculating the

20
00:01:28,890 --> 00:01:29,280
loss.

21
00:01:29,290 --> 00:01:37,350
So we will actually it's it's it's many times this process or this part of the code is is they put it

22
00:01:37,350 --> 00:01:40,680
in a different place like they put it in the training place.

23
00:01:40,680 --> 00:01:48,990
But it like we will do different ways of writing a code but let's let's put it just in the loss function.

24
00:01:50,090 --> 00:01:51,920
So, Grant.

25
00:01:52,830 --> 00:02:00,600
We zero the Adam grade gradient and we will zero the optimizer gradient.

26
00:02:02,450 --> 00:02:04,730
And then we will predict.

27
00:02:06,200 --> 00:02:09,050
Predict equals self.

28
00:02:09,640 --> 00:02:11,380
Dot model.

29
00:02:12,140 --> 00:02:15,650
And self dot x.

30
00:02:16,510 --> 00:02:17,170
Train.

31
00:02:20,540 --> 00:02:21,620
And.

32
00:02:22,410 --> 00:02:23,220
Los.

33
00:02:24,060 --> 00:02:27,180
Data will equals self.

34
00:02:27,210 --> 00:02:32,460
Of course, we took the extent and we predict all the values and.

35
00:02:35,430 --> 00:02:36,480
Self.

36
00:02:37,730 --> 00:02:38,540
Dot.

37
00:02:41,040 --> 00:02:42,690
The criterion.

38
00:02:44,100 --> 00:02:51,510
And we will have the predicted one and we will have also our data.

39
00:02:53,500 --> 00:02:54,400
Of course not.

40
00:02:54,430 --> 00:02:54,850
Why?

41
00:02:54,880 --> 00:02:55,570
But not.

42
00:02:55,780 --> 00:02:56,680
But why?

43
00:02:56,920 --> 00:03:00,910
So here what we did is we calculate the first type of loss.

44
00:03:00,910 --> 00:03:04,300
We said there are two types of losses in in pens.

45
00:03:04,330 --> 00:03:06,220
The first type is the.

46
00:03:07,430 --> 00:03:08,170
Data loss.

47
00:03:08,180 --> 00:03:10,400
The second type is the loss.

48
00:03:10,550 --> 00:03:16,520
So this is going to be the first type, which is the loss related to data.

49
00:03:16,790 --> 00:03:21,230
And now what we will do is we will calculate the U.

50
00:03:21,680 --> 00:03:25,190
The actual U value for the whole thing.

51
00:03:25,220 --> 00:03:27,530
Dot model.

52
00:03:28,690 --> 00:03:29,890
Self.

53
00:03:32,230 --> 00:03:33,520
Just the same thing.

54
00:03:35,510 --> 00:03:37,340
So this is going to be you.

55
00:03:37,370 --> 00:03:39,320
It's actually predict it's the same.

56
00:03:39,320 --> 00:03:45,680
But but we we will put it here because we need to use it to actually do the.

57
00:03:47,260 --> 00:03:48,070
Derivation.

58
00:03:49,590 --> 00:04:03,450
So d u over d t We said the component of burgers equation we have du over this one and we have of course

59
00:04:03,450 --> 00:04:06,780
u which now we just calculated it du over.

60
00:04:07,140 --> 00:04:11,100
We have du over and over x square.

61
00:04:11,130 --> 00:04:17,130
Now du over and over will be calculated from this one.

62
00:04:18,240 --> 00:04:20,070
I will show you how, basically.

63
00:04:20,070 --> 00:04:21,360
And um.

64
00:04:22,510 --> 00:04:23,590
Or do you not?

65
00:04:24,220 --> 00:04:26,260
The x the whole data.

66
00:04:26,470 --> 00:04:33,460
So sorry, because we have you and it will change with x and it will change with time.

67
00:04:33,730 --> 00:04:42,490
So we take the data which is which is basically a grid of x and time and we will calculate the change

68
00:04:42,490 --> 00:04:44,080
of you with x.

69
00:04:44,940 --> 00:04:53,250
With X means with both sides the time and and the actual x.

70
00:04:53,430 --> 00:04:57,090
So torch dot auto.

71
00:04:59,540 --> 00:05:00,300
Auto grid.

72
00:05:02,110 --> 00:05:03,610
And Dot.

73
00:05:04,880 --> 00:05:05,690
Grad.

74
00:05:07,110 --> 00:05:09,870
And we need to add you.

75
00:05:19,190 --> 00:05:21,020
We need to add you.

76
00:05:22,770 --> 00:05:25,740
Self dot x.

77
00:05:25,770 --> 00:05:31,800
This is the the the the component we need to compute which is you.

78
00:05:31,800 --> 00:05:40,410
This is self x, which is the component we need to basically the dominator or the the the basically

79
00:05:40,410 --> 00:05:48,030
the change of you, the regarding the x in relation to x and.

80
00:05:50,140 --> 00:05:53,830
The ground output.

81
00:05:53,860 --> 00:05:59,320
Outputs equals torch dot ones.

82
00:06:00,310 --> 00:06:11,290
Like you and this is needed in the training regarding the some change of it will measure the change

83
00:06:11,290 --> 00:06:19,630
of loss when we basically to itself when we change some parameters, how the loss will change.

84
00:06:19,630 --> 00:06:22,510
So this is why we put it like this.

85
00:06:23,020 --> 00:06:25,810
But for this is basically it's the same.

86
00:06:25,810 --> 00:06:28,720
We always put it this the same along with what's coming next.

87
00:06:28,720 --> 00:06:34,990
But the most important thing for us is the change of U with change of we define it, which is in our

88
00:06:34,990 --> 00:06:39,880
case, X and then retrain.

89
00:06:40,830 --> 00:06:42,450
Or actually create.

90
00:06:42,480 --> 00:06:43,650
Create.

91
00:06:45,240 --> 00:06:47,730
Create graph.

92
00:06:48,870 --> 00:06:49,440
Equals.

93
00:06:49,440 --> 00:06:50,160
True.

94
00:06:51,390 --> 00:06:54,210
And return retain.

95
00:06:55,000 --> 00:06:59,080
The graph will also equals true.

96
00:06:59,410 --> 00:07:12,730
So basically this is just a it's you want the the the computation has to to to be stored and you have

97
00:07:12,730 --> 00:07:13,670
to keep it.

98
00:07:13,690 --> 00:07:22,420
So this is creating the graph, creating this like storage of the computation of the over and retain

99
00:07:22,420 --> 00:07:25,700
it means we keep it as as simple as this.

100
00:07:25,720 --> 00:07:29,680
Now think this just housekeeping a little bit here.

101
00:07:29,680 --> 00:07:30,790
I don't like.

102
00:07:32,840 --> 00:07:34,160
This way, it's better.

103
00:07:39,610 --> 00:07:41,060
Yeah, this looks better.

104
00:07:42,280 --> 00:07:42,730
Okay.

105
00:07:44,140 --> 00:07:46,750
But there's one thing here I didn't say.

106
00:07:46,750 --> 00:07:48,190
Here we have to put zero.

107
00:07:53,640 --> 00:07:55,140
And the reason?

108
00:07:56,350 --> 00:07:56,950
Zero.

109
00:07:58,250 --> 00:07:59,810
The reason If you.

110
00:08:00,200 --> 00:08:02,660
If we didn't put zero, I will.

111
00:08:03,570 --> 00:08:05,400
And basically show this.

112
00:08:05,400 --> 00:08:06,270
So.

113
00:08:07,280 --> 00:08:14,680
If we if we didn't put zero this or okay, I will just print it and I will show.

114
00:08:14,690 --> 00:08:20,720
So they're putting the the actual tensor in, in in containment.

115
00:08:20,720 --> 00:08:22,250
It's kind of like in a tuple.

116
00:08:22,370 --> 00:08:23,690
But we don't want that.

117
00:08:23,690 --> 00:08:25,010
We want the value of the tensor.

118
00:08:25,220 --> 00:08:28,850
I will show it just like later.

119
00:08:28,850 --> 00:08:29,630
I will show it.

120
00:08:29,630 --> 00:08:32,720
So this we will print it, this one.

121
00:08:33,050 --> 00:08:34,340
And we print.

122
00:08:34,340 --> 00:08:35,150
Print.

123
00:08:36,180 --> 00:08:40,410
Just some kind of separator and print later will show this one.

124
00:08:40,410 --> 00:08:42,540
But basically is just we.

125
00:08:45,650 --> 00:08:47,030
Just this way.

126
00:08:47,150 --> 00:08:52,130
Later I will, of course, when we run the whole code, because it's not ready now.

127
00:08:54,020 --> 00:08:59,570
Basically, this will be they will put it in in tuple and just want to get it from tuple.

128
00:08:59,570 --> 00:09:06,350
It's as simple as simple as this, but I will show it anyway, like just for you to have a very clear

129
00:09:06,350 --> 00:09:07,910
understanding of what's happening.

130
00:09:08,900 --> 00:09:13,030
Okay, now we found the change of view to X.

131
00:09:13,040 --> 00:09:15,850
Now we don't want that.

132
00:09:15,860 --> 00:09:26,210
What we want is the change of U with change of T and we change of u with change of x, not x the data

133
00:09:26,240 --> 00:09:31,400
this x capital x we call the data, but we're changing the whole thing.

134
00:09:31,400 --> 00:09:32,780
So d u.

135
00:09:33,470 --> 00:09:41,150
We take basically this one, maybe it's better than X, We just put data as I feel is better and we

136
00:09:41,150 --> 00:09:44,480
need basically everything with zero.

137
00:09:45,540 --> 00:09:48,030
This will be basically.

138
00:09:49,440 --> 00:09:51,330
Well, a tensor everything is tensor.

139
00:09:51,330 --> 00:09:59,430
But what we will get is basically we will have two values, which is the change of U in relation to

140
00:09:59,430 --> 00:10:01,580
X and the change of U in relation to T.

141
00:10:01,590 --> 00:10:09,930
So this we take the first one, the not this one actually the first, the second one, it will be the

142
00:10:09,930 --> 00:10:14,880
time and the first one will be basically the.

143
00:10:17,430 --> 00:10:18,410
The X.

144
00:10:19,890 --> 00:10:20,370
Okay.

145
00:10:20,370 --> 00:10:21,540
That's that's good.

146
00:10:21,540 --> 00:10:22,020
That's.

147
00:10:22,050 --> 00:10:24,170
That's quite useful.

148
00:10:24,180 --> 00:10:26,400
Now, we need to repeat this one.

149
00:10:27,030 --> 00:10:27,570
Why?

150
00:10:27,570 --> 00:10:28,410
We need to repeat it?

151
00:10:28,410 --> 00:10:34,350
Because we need to compute the two dimensions.

152
00:10:34,350 --> 00:10:35,070
So.

153
00:10:36,340 --> 00:10:38,290
We need to calculate x.

154
00:10:38,290 --> 00:10:38,940
X.

155
00:10:39,850 --> 00:10:43,060
So in order to do so, we do the same.

156
00:10:43,060 --> 00:10:46,030
But now we change the input.

157
00:10:46,060 --> 00:10:47,530
We take this input.

158
00:10:48,270 --> 00:10:52,800
Which is this one should not have this.

159
00:10:55,600 --> 00:10:58,750
This just looks it will have.

160
00:10:58,780 --> 00:11:08,050
We want to derive the thing again so we derive it again in response to again the X and it will give

161
00:11:08,050 --> 00:11:08,770
us this one.

162
00:11:08,770 --> 00:11:13,870
But again, we don't want that or even that second derivative of time.

163
00:11:13,870 --> 00:11:23,650
What we want is do the x x the second derivative of regarding the space and this will will be.

164
00:11:25,030 --> 00:11:27,490
Everything and zero.

165
00:11:27,820 --> 00:11:30,370
So this is will derive already.

166
00:11:30,370 --> 00:11:34,750
The first derivative will derive it again, this means the second derivative.

167
00:11:34,750 --> 00:11:37,030
And then we assign the zero.

168
00:11:38,790 --> 00:11:39,630
Are we done?

169
00:11:40,080 --> 00:11:41,400
Just a little bit.

170
00:11:41,430 --> 00:11:44,550
We need to put the loss now.

171
00:11:45,140 --> 00:11:45,920
PD.

172
00:11:46,220 --> 00:11:48,500
PD equals.

173
00:11:49,410 --> 00:11:49,770
And.

174
00:11:51,050 --> 00:11:51,560
Again.

175
00:11:51,590 --> 00:11:52,020
The list.

176
00:11:52,040 --> 00:11:53,540
The Self Criterion.

177
00:11:58,960 --> 00:12:02,440
Of predicted and the actual thing.

178
00:12:02,440 --> 00:12:12,910
But first, let's see what is the predicted one and it will be we need to well, basically we need to

179
00:12:12,910 --> 00:12:24,310
write the equation we have over dt plus u d u over d x equals a viscosity d the second derivative of

180
00:12:24,310 --> 00:12:26,710
d of u and x.

181
00:12:26,740 --> 00:12:31,720
This has to be all well, basically it has to be zero.

182
00:12:32,170 --> 00:12:33,220
So.

183
00:12:34,620 --> 00:12:41,250
So actually, we don't need this one or actually we can put here zero, but just having this way, it

184
00:12:41,250 --> 00:12:42,660
will consider it zero.

185
00:12:42,750 --> 00:12:43,590
So.

186
00:12:45,520 --> 00:12:48,820
We need to move this guy here.

187
00:12:49,780 --> 00:12:51,010
And this will be zero.

188
00:12:51,040 --> 00:12:53,440
You can put it zero, but of course.

189
00:12:53,860 --> 00:13:01,360
Or just by having the value itself, because at the end, what we're trying always to do is to minimize

190
00:13:01,360 --> 00:13:01,990
the loss.

191
00:13:02,080 --> 00:13:05,920
So by computing it as a loss is already.

192
00:13:07,250 --> 00:13:13,910
Oh, well, it's already computed as a loss, so we don't really need to compare it with an actual Y

193
00:13:13,910 --> 00:13:17,060
train because the value itself is the loss.

194
00:13:18,440 --> 00:13:20,390
So do over.

195
00:13:22,580 --> 00:13:25,120
Plus you dot.

196
00:13:25,860 --> 00:13:29,520
This time we need to squeeze.

197
00:13:30,690 --> 00:13:31,800
This value.

198
00:13:34,740 --> 00:13:36,090
Squeeze.

199
00:13:37,060 --> 00:13:43,990
And this is just again, like it's the reverse with Unsqueezed what we did, we have these values will

200
00:13:43,990 --> 00:13:48,250
be separated because it's an output of the prediction.

201
00:13:48,250 --> 00:13:55,420
We need to make it into a list which these losses are already formatted into this list.

202
00:13:56,320 --> 00:13:56,640
Um.

203
00:13:58,030 --> 00:14:01,210
So the equation just we look at it a little bit.

204
00:14:03,090 --> 00:14:04,440
It's over.

205
00:14:04,950 --> 00:14:08,580
This is the u over d t u d u over d.

206
00:14:09,210 --> 00:14:11,730
We need to u.

207
00:14:14,330 --> 00:14:15,790
And squeeze or squeeze.

208
00:14:15,800 --> 00:14:16,400
Sorry.

209
00:14:16,940 --> 00:14:20,900
And d u over d x.

210
00:14:20,930 --> 00:14:22,190
Okay.

211
00:14:28,830 --> 00:14:29,670
And.

212
00:14:31,510 --> 00:14:36,160
Well, actually, we can just put it.

213
00:14:37,060 --> 00:14:38,080
Minus.

214
00:14:44,440 --> 00:14:45,730
Minus.

215
00:14:48,370 --> 00:14:53,080
0.01 divided by.

216
00:14:54,190 --> 00:14:56,620
Math dot pi.

217
00:14:56,650 --> 00:14:58,030
This is just a.

218
00:14:59,400 --> 00:15:03,810
A basically diffusion term.

219
00:15:05,810 --> 00:15:08,560
U over the x x.

220
00:15:13,830 --> 00:15:14,130
Yeah.

221
00:15:17,630 --> 00:15:21,000
So this is the diffusion part of the equation.

222
00:15:21,020 --> 00:15:23,240
And it all has to.

223
00:15:23,980 --> 00:15:25,180
B equals.

224
00:15:28,740 --> 00:15:31,650
And actually we can compare it to zero.

225
00:15:32,970 --> 00:15:41,220
So d u over t u d u d minus all this part.

226
00:15:42,860 --> 00:15:44,990
The EU over the.

227
00:15:48,010 --> 00:15:49,320
As he.

228
00:15:56,140 --> 00:15:56,590
Okay.

229
00:15:56,590 --> 00:15:57,580
This way.

230
00:15:59,070 --> 00:15:59,970
Or the final thing.

231
00:15:59,970 --> 00:16:02,940
What we need to do is we need to.

232
00:16:09,560 --> 00:16:10,460
Los.

233
00:16:13,140 --> 00:16:15,480
Well equals loss.

234
00:16:17,970 --> 00:16:18,170
P.

235
00:16:18,270 --> 00:16:19,510
D e.

236
00:16:23,200 --> 00:16:25,000
Plus loss.

237
00:16:26,600 --> 00:16:27,140
Date.

238
00:16:28,240 --> 00:16:30,770
But actually maybe this one a little bit.

239
00:16:31,620 --> 00:16:33,720
She seems dangerous.

240
00:16:38,060 --> 00:16:39,960
The thing this way is better.

241
00:16:41,260 --> 00:16:42,370
The U.S..

242
00:16:44,870 --> 00:16:47,240
And then loss dot.

243
00:16:48,980 --> 00:16:50,780
Backward.

244
00:16:52,390 --> 00:16:54,040
Backpropagation.

245
00:16:55,210 --> 00:17:00,430
And if self dot letter.

246
00:17:03,650 --> 00:17:05,420
Divide by 100.

247
00:17:05,420 --> 00:17:08,840
So every 100 steps we need to print the loss.

248
00:17:11,880 --> 00:17:12,690
Print.

249
00:17:14,400 --> 00:17:15,690
Self.

250
00:17:17,790 --> 00:17:19,500
Dot editor.

251
00:17:21,130 --> 00:17:22,120
And the loss.

252
00:17:37,090 --> 00:17:44,470
And of course, we need to increase the iteration number by one.

253
00:17:45,220 --> 00:17:46,630
Return.

254
00:17:48,290 --> 00:17:48,830
Los.

255
00:17:52,490 --> 00:17:53,930
Okay, this way.

256
00:17:54,530 --> 00:18:02,060
We finished computing the loss and of course, later we will see this one.

257
00:18:02,060 --> 00:18:06,890
Why I put it like this is just simply it's just the way it went out from this.

258
00:18:06,920 --> 00:18:08,510
We need to a little bit modified.
