1
00:00:01,150 --> 00:00:07,330
Now what we need to do is to calculate the losses.

2
00:00:07,360 --> 00:00:14,380
Now losses we have the residual loss or what we call loss or the equation loss.

3
00:00:14,620 --> 00:00:17,470
And the other loss we have is the data loss.

4
00:00:17,620 --> 00:00:21,280
So the first thing is let's calculate the residual loss.

5
00:00:21,280 --> 00:00:26,680
And the residual loss will basically depends on equation.

6
00:00:26,980 --> 00:00:32,980
So in order to do that, let's have a class or not a class, actually.

7
00:00:34,160 --> 00:00:36,170
Diff means like function.

8
00:00:38,720 --> 00:00:47,450
And what we will have, we will have X, we have Y, we have T, and we have the model.

9
00:00:48,350 --> 00:00:49,520
What do we need?

10
00:00:49,550 --> 00:00:52,480
Now this a pde.

11
00:00:53,180 --> 00:00:58,220
What it, what it going to to do is we need to calculate the.

12
00:00:59,040 --> 00:01:04,020
The the basically the residual that is, um.

13
00:01:07,470 --> 00:01:08,450
I will explain it.

14
00:01:08,460 --> 00:01:14,370
So basically, you have this part of the equation, all of this part of the equation.

15
00:01:14,370 --> 00:01:24,000
And then by moving this part to here, we will get an equation that will basically look like a like

16
00:01:24,000 --> 00:01:25,080
this.

17
00:01:27,310 --> 00:01:28,450
Minus.

18
00:01:31,070 --> 00:01:33,620
I will move the things here.

19
00:01:34,820 --> 00:01:37,370
Minus due.

20
00:01:39,020 --> 00:01:44,180
RT and all of this will will equal to.

21
00:01:46,050 --> 00:01:46,710
Zero.

22
00:01:48,670 --> 00:01:49,450
Now.

23
00:01:50,170 --> 00:01:52,570
The reality is it will not equal to zero.

24
00:01:53,350 --> 00:01:54,640
And this.

25
00:01:56,750 --> 00:01:59,690
This will have or not this one.

26
00:01:59,720 --> 00:02:02,150
This will have a value.

27
00:02:02,540 --> 00:02:09,020
So what we will do, we'll try to the loss will be we will have this equation that equals to zero.

28
00:02:09,050 --> 00:02:10,820
Of course, it can work for any equation.

29
00:02:10,820 --> 00:02:14,300
Just put everything on one side and equal it to zero.

30
00:02:14,390 --> 00:02:16,520
But make sure later we will see.

31
00:02:16,520 --> 00:02:19,160
Like this zero means every data point.

32
00:02:19,160 --> 00:02:21,710
So we need to be careful about the size.

33
00:02:21,980 --> 00:02:23,580
I will show how to do this.

34
00:02:23,600 --> 00:02:27,080
So this is has to be zero.

35
00:02:27,230 --> 00:02:30,800
If we calculate how much is this, then we will get a value.

36
00:02:30,800 --> 00:02:34,400
And this value we will say, I want the loss to be zero.

37
00:02:38,090 --> 00:02:39,140
So let's do it.

38
00:02:39,410 --> 00:02:41,960
In order to do it first, we need to.

39
00:02:42,440 --> 00:02:44,240
Well, basically, we will.

40
00:02:45,650 --> 00:02:46,580
Start.

41
00:02:47,130 --> 00:02:48,260
Just a minute.

42
00:02:52,190 --> 00:02:56,060
Yeah, we will start by the input data.

43
00:02:56,630 --> 00:02:58,430
Input data.

44
00:02:59,220 --> 00:03:02,700
Equals torch dot.

45
00:03:06,400 --> 00:03:14,350
Concatenate X, y, and T with a dimension equals one.

46
00:03:15,660 --> 00:03:21,420
The main reason why we said like this because X, Y, and T is actually a tensor here.

47
00:03:21,420 --> 00:03:27,990
We generated a tensor like we remember here a random tensor of x, a random tensor of Y and a random

48
00:03:28,020 --> 00:03:29,310
tensor with t.

49
00:03:29,340 --> 00:03:39,540
Now we will cut concatenate these x, y and T because we want to pass this these values to the model

50
00:03:39,660 --> 00:03:42,510
and basically get the.

51
00:03:43,210 --> 00:03:44,560
Input data.

52
00:03:45,580 --> 00:03:47,620
Look, we get that you.

53
00:03:48,480 --> 00:03:53,160
So the model will, will, will generate the data points.

54
00:03:53,160 --> 00:03:56,910
So we have three tensors we use them to make.

55
00:03:57,030 --> 00:03:58,500
Well, basically data.

56
00:03:58,710 --> 00:04:06,120
And then this data we put them into the model and by that we generate a values of U.

57
00:04:06,660 --> 00:04:09,750
After that, what we need to do is we need to.

58
00:04:10,800 --> 00:04:12,330
And differentiate you.

59
00:04:12,330 --> 00:04:14,760
And this is another.

60
00:04:16,120 --> 00:04:19,210
Like another way to do it, but okay, I will write it this way.

61
00:04:19,510 --> 00:04:29,350
X UX and UI equals torch dot the same we did like before auto.

62
00:04:30,120 --> 00:04:30,930
Grad.

63
00:04:32,040 --> 00:04:39,750
The things we want to differentiate is you risk in corresponding to x, y.

64
00:04:39,780 --> 00:04:45,570
Now here x, Y, or we just write two times like x here and y here.

65
00:04:48,860 --> 00:04:50,450
And actually I'll just put it.

66
00:04:50,490 --> 00:04:53,420
I like the simplification.

67
00:04:54,510 --> 00:05:04,030
Just like this you and then we want to like, basically two x.

68
00:05:05,460 --> 00:05:06,680
And this too.

69
00:05:06,690 --> 00:05:07,410
Why?

70
00:05:11,250 --> 00:05:12,000
Grad.

71
00:05:13,210 --> 00:05:14,770
Outputs.

72
00:05:15,820 --> 00:05:16,780
Equals.

73
00:05:16,900 --> 00:05:18,940
Same thing we did before.

74
00:05:22,240 --> 00:05:23,290
George.

75
00:05:25,320 --> 00:05:25,780
Dot.

76
00:05:26,950 --> 00:05:29,020
Ones like.

77
00:05:29,750 --> 00:05:30,470
You.

78
00:05:31,720 --> 00:05:32,860
Create.

79
00:05:34,210 --> 00:05:35,230
Graph.

80
00:05:37,750 --> 00:05:38,380
Equals.

81
00:05:38,380 --> 00:05:39,160
True.

82
00:05:40,750 --> 00:05:41,590
She threw.

83
00:05:43,770 --> 00:05:45,360
And retain.

84
00:05:46,700 --> 00:05:47,600
Graph.

85
00:05:48,490 --> 00:05:50,020
Equals also true.

86
00:05:51,840 --> 00:05:54,210
This one we repeated.

87
00:05:55,740 --> 00:05:56,340
It.

88
00:05:58,030 --> 00:05:58,780
Two times.

89
00:05:58,780 --> 00:06:08,830
Of course we can do it like this or just just put it this way or just make it a bit concise.

90
00:06:09,470 --> 00:06:10,440
UX.

91
00:06:11,730 --> 00:06:17,430
You I am just worried about might be another value that will pop up here.

92
00:06:17,430 --> 00:06:21,420
And yeah, need to be careful about the dimension.

93
00:06:22,530 --> 00:06:24,660
So this.

94
00:06:28,100 --> 00:06:29,510
This is the first one.

95
00:06:30,190 --> 00:06:31,930
And what we need to use.

96
00:06:31,930 --> 00:06:33,980
Actually, we're not really using this one.

97
00:06:34,000 --> 00:06:37,090
What we will do is use x x.

98
00:06:38,730 --> 00:06:45,270
The second derivative we will is the same, but we need to be attention of some things.

99
00:06:45,840 --> 00:06:47,820
We need to use.

100
00:06:49,320 --> 00:06:49,980
To.

101
00:06:52,560 --> 00:06:56,640
To to use for differentiation.

102
00:06:57,720 --> 00:06:59,280
This is the second derivative.

103
00:06:59,280 --> 00:07:02,280
And here it will be.

104
00:07:02,790 --> 00:07:04,230
For X.

105
00:07:05,130 --> 00:07:08,790
Tortured, cried like not you.

106
00:07:08,820 --> 00:07:14,640
It will be UX and everything will be the same.

107
00:07:14,640 --> 00:07:15,480
But.

108
00:07:16,240 --> 00:07:16,870
Here.

109
00:07:16,870 --> 00:07:18,640
We need only zero.

110
00:07:19,940 --> 00:07:24,590
And we said about this, it will well, it will make a tuple and we don't want the tuple.

111
00:07:24,590 --> 00:07:25,970
We want just the value.

112
00:07:25,970 --> 00:07:28,880
It would put one value, one tensor value in the tuple.

113
00:07:28,880 --> 00:07:30,830
And this is how it works.

114
00:07:30,830 --> 00:07:37,820
Like it's just this is of course, using PyTorch is not made only for pens, but we don't need the tuple

115
00:07:37,820 --> 00:07:46,460
and we this is why we take this value of zero you and now we do the same thing with you.

116
00:07:46,940 --> 00:07:47,940
Well, we.

117
00:07:49,190 --> 00:07:52,070
You y y.

118
00:07:52,160 --> 00:07:54,950
And we also be careful here.

119
00:07:54,950 --> 00:08:05,960
You have to put UI and we have to derivate in relation to U to Y and here we have to pass y and graph,

120
00:08:06,140 --> 00:08:14,930
create, create, not like create here and then here, create, retrain, retain the graph equals true.

121
00:08:14,930 --> 00:08:17,840
Everything is seems in place.

122
00:08:17,840 --> 00:08:23,340
The only thing we need to care about is u t.

123
00:08:25,170 --> 00:08:26,190
Which is.

124
00:08:27,430 --> 00:08:28,680
The division.

125
00:08:28,680 --> 00:08:32,310
With time you will be with.

126
00:08:32,310 --> 00:08:33,810
You should be.

127
00:08:34,260 --> 00:08:36,000
So we.

128
00:08:37,080 --> 00:08:41,490
But you and we derive it with time.

129
00:08:43,070 --> 00:08:45,560
And we put again.

130
00:08:47,130 --> 00:08:48,630
You hear?

131
00:08:49,600 --> 00:08:50,710
And create graph.

132
00:08:50,710 --> 00:08:54,430
Everything is seems okay.

133
00:08:55,720 --> 00:08:58,450
Heat equation.

134
00:08:58,990 --> 00:09:00,430
Residual.

135
00:09:00,610 --> 00:09:01,720
Residual.

136
00:09:02,570 --> 00:09:06,200
Equals, I will put the coefficient of one.

137
00:09:07,310 --> 00:09:10,580
So we put it this is going to be the equation.

138
00:09:11,390 --> 00:09:14,330
Well, we have this will be one.

139
00:09:14,330 --> 00:09:16,880
So this will be one multiplied.

140
00:09:17,000 --> 00:09:22,700
The second derivative of u over x and the second derivative of u over y minus du over dt.

141
00:09:23,030 --> 00:09:27,130
So this is one multiplied UX x.

142
00:09:28,320 --> 00:09:30,360
Plus one multiplied.

143
00:09:31,530 --> 00:09:33,570
We'll just make it look nice.

144
00:09:33,730 --> 00:09:36,450
You y minus.

145
00:09:37,540 --> 00:09:38,140
UT.

146
00:09:40,820 --> 00:09:43,340
And we return.

147
00:09:44,310 --> 00:09:46,530
Of course, we just can't put it all of this here.

148
00:09:46,530 --> 00:09:49,260
But anyway, return residual.

149
00:09:52,170 --> 00:09:53,610
And shift enter.

150
00:09:55,220 --> 00:10:05,060
So we go back to the main loop and what we will do is we are going to define residual, which is the

151
00:10:05,060 --> 00:10:07,190
residual error equals.

152
00:10:09,070 --> 00:10:13,690
And we just pass and model.

153
00:10:18,080 --> 00:10:19,850
The model is here.

154
00:10:19,880 --> 00:10:25,010
Of course, the model will be we will will define it later in the actual training process.

155
00:10:25,010 --> 00:10:30,380
But basically the model in the in the training class, we have to pass it.

156
00:10:30,920 --> 00:10:33,350
So now we have the residual.

157
00:10:37,150 --> 00:10:38,320
Calculate the loss.

158
00:10:38,650 --> 00:10:43,000
Loss is in mean squared error.

159
00:10:43,030 --> 00:10:44,470
Keep it simple loss.

160
00:10:44,500 --> 00:10:47,650
Of course we will keep it simple.

161
00:10:47,680 --> 00:10:50,320
But in usual case it might.

162
00:10:50,350 --> 00:10:51,610
We need more maybe.

163
00:10:51,610 --> 00:10:53,800
Or different losses.

164
00:10:53,800 --> 00:10:55,270
But this is just.

165
00:10:55,270 --> 00:10:59,290
It works in this simple equations.

166
00:10:59,740 --> 00:11:02,590
Model dot torch Dot.

167
00:11:04,460 --> 00:11:05,810
Concatenate.

168
00:11:06,900 --> 00:11:07,550
Cut.

169
00:11:08,480 --> 00:11:11,180
And we will add X.

170
00:11:11,930 --> 00:11:15,980
Y and T initial.

171
00:11:18,910 --> 00:11:19,660
And.

172
00:11:20,520 --> 00:11:25,740
Uh, we need to consider the same dimension here.

173
00:11:26,250 --> 00:11:28,650
Dimension equals one.

174
00:11:29,820 --> 00:11:31,140
And.

175
00:11:32,860 --> 00:11:33,780
Plus.

176
00:11:38,310 --> 00:11:39,810
Or just.

177
00:11:47,960 --> 00:11:49,730
It's not shifting.

178
00:11:51,010 --> 00:11:51,820
Anyway.

179
00:11:51,820 --> 00:11:56,860
So we have we need again this loss.

180
00:12:01,990 --> 00:12:02,230
Mm.

181
00:12:17,030 --> 00:12:23,540
I wanted to be in this direction, but somehow it's not moving anyway, you initial.

182
00:12:24,290 --> 00:12:30,530
This initial value has to equal the points.

183
00:12:31,510 --> 00:12:36,250
That we calculated will equal the the output of the model itself.

184
00:12:37,060 --> 00:12:38,080
And.

185
00:12:44,770 --> 00:12:45,190
Yeah.

186
00:12:46,800 --> 00:12:47,910
And.

187
00:12:48,840 --> 00:12:52,350
The loss of you boundary.

188
00:12:55,740 --> 00:12:58,160
Will do the same.

189
00:12:58,170 --> 00:13:00,030
X underscore b.

190
00:13:01,100 --> 00:13:01,980
Y.

191
00:13:02,420 --> 00:13:02,810
Aw.

192
00:13:02,930 --> 00:13:03,170
Yeah.

193
00:13:03,260 --> 00:13:06,320
Y underscore V and this one.

194
00:13:07,310 --> 00:13:07,880
And.

195
00:13:14,070 --> 00:13:18,330
Yeah, not initial because we don't really need that.

196
00:13:19,170 --> 00:13:20,460
Because the time will change.

197
00:13:20,460 --> 00:13:23,130
Here is already it's only zero.

198
00:13:25,640 --> 00:13:26,540
And.

199
00:13:35,930 --> 00:13:41,180
And we have also the other loss we have.

200
00:13:43,970 --> 00:13:44,410
Now.

201
00:13:44,410 --> 00:13:45,790
It's kind of working.

202
00:14:00,380 --> 00:14:04,790
Is boundary condition of you.

203
00:14:05,030 --> 00:14:06,740
And here we flipped it.

204
00:14:06,740 --> 00:14:08,630
So why be?

205
00:14:09,570 --> 00:14:13,560
We flipped it to generate more points and dimension is the same.

206
00:14:14,550 --> 00:14:15,720
And.

207
00:14:18,260 --> 00:14:23,990
Here we have the last error is the residual error.

208
00:14:26,640 --> 00:14:27,900
So residual.

209
00:14:35,520 --> 00:14:40,620
And torch dot zero like.

210
00:14:41,960 --> 00:14:43,640
A residual.

211
00:14:43,730 --> 00:14:47,300
So it has to be the same size as, as I said.

212
00:14:54,270 --> 00:15:00,720
Now, after that, what we will do is loss dot back.

213
00:15:02,890 --> 00:15:05,080
Propagation backward.

214
00:15:06,450 --> 00:15:08,040
And the Optimizer.

215
00:15:08,170 --> 00:15:09,570
Optimizer.

216
00:15:13,080 --> 00:15:14,880
We will have a step.

217
00:15:18,990 --> 00:15:22,050
If it ration.

218
00:15:23,480 --> 00:15:27,870
Residual 100 equals or equals equal zero.

219
00:15:27,890 --> 00:15:33,740
Basically, we need to print it every 100 step print.

220
00:15:36,840 --> 00:15:38,430
Iteration.

221
00:15:39,840 --> 00:15:40,010
He.

222
00:15:41,460 --> 00:15:42,900
The iteration.

223
00:15:43,880 --> 00:15:45,410
And Los.

224
00:15:51,180 --> 00:15:52,110
Los.

225
00:15:57,520 --> 00:15:58,510
Los.

226
00:16:00,070 --> 00:16:00,760
This one.

227
00:16:02,660 --> 00:16:08,600
Okay, so this way I think it's quite good.

228
00:16:10,650 --> 00:16:16,260
Next step, of course, shift enter and we have a little bit problem.

229
00:16:21,110 --> 00:16:21,710
And.

230
00:16:25,980 --> 00:16:26,600
Are here.

231
00:16:26,610 --> 00:16:28,050
Extra one.

232
00:16:29,310 --> 00:16:31,050
Just to be safe.

233
00:16:31,050 --> 00:16:34,140
I think here it's better to have it like this.

234
00:16:35,730 --> 00:16:38,340
Like this will be continuation for this.

235
00:16:45,640 --> 00:16:48,580
And shift into seems okay.

236
00:16:49,270 --> 00:16:49,720
Okay.

237
00:16:49,750 --> 00:16:53,980
This now we already finished how to define the loss.

238
00:16:53,980 --> 00:16:56,410
And next step we will train this model.
