1
00:00:00,690 --> 00:00:07,800
So now we will start doing the the kind of the training loop we start writing it.

2
00:00:07,800 --> 00:00:11,040
But of course this time also the optimizer.

3
00:00:11,040 --> 00:00:15,840
I as I said it will I will use quite simple optimizer which is Adam.

4
00:00:16,470 --> 00:00:17,430
So.

5
00:00:18,510 --> 00:00:19,560
Let's write it.

6
00:00:19,560 --> 00:00:28,560
Let's write the basically the training loop, but will leave a little bit here space because I want

7
00:00:28,560 --> 00:00:37,170
to put the loss function in here because in this code, other than in the past code, the things used

8
00:00:37,170 --> 00:00:39,300
to be a little bit messy.

9
00:00:39,300 --> 00:00:46,140
I would say here it's a little bit more organized into functions that in your case, if you want to

10
00:00:46,140 --> 00:00:52,680
change the the future, how these things will look, you can simply do that.

11
00:00:52,680 --> 00:00:54,060
So just.

12
00:00:55,040 --> 00:00:58,400
So this will be the the actual description of PDA.

13
00:00:58,700 --> 00:01:01,550
So here, let's do the.

14
00:01:02,470 --> 00:01:07,340
Optimization part to follow kind of the same methodology.

15
00:01:07,520 --> 00:01:13,730
And of course we will write the the main training loop, but this time is a little bit more organized,

16
00:01:13,730 --> 00:01:17,510
I would say, rather than the 1D situation.

17
00:01:17,810 --> 00:01:23,240
Now here a train with pin underscore.

18
00:01:23,630 --> 00:01:25,100
Underscore pin.

19
00:01:25,780 --> 00:01:28,330
And model.

20
00:01:29,360 --> 00:01:34,760
It will take and number of iterations.

21
00:01:35,580 --> 00:01:40,890
Integrations and number of points.

22
00:01:42,780 --> 00:01:47,220
Optimizer to miser equals optimum.

23
00:01:48,220 --> 00:01:48,940
Dot.

24
00:01:49,150 --> 00:01:49,900
Adam.

25
00:01:50,880 --> 00:01:56,190
And model dot parameters.

26
00:01:57,750 --> 00:02:03,930
With a learning rate of one e to the power minus three.

27
00:02:06,470 --> 00:02:08,690
I will just check it a little bit.

28
00:02:08,720 --> 00:02:10,320
Parameters.

29
00:02:10,340 --> 00:02:12,700
Parameters Here.

30
00:02:13,310 --> 00:02:13,750
There's.

31
00:02:13,790 --> 00:02:14,000
Yeah.

32
00:02:14,630 --> 00:02:15,170
Okay.

33
00:02:17,150 --> 00:02:18,560
That's it for the optimizer.

34
00:02:18,560 --> 00:02:27,740
However, we just need to define the the the points as we did before, just a little bit more for this

35
00:02:27,740 --> 00:02:28,190
step.

36
00:02:28,190 --> 00:02:31,640
And later, we will focus only on calculating the losses.

37
00:02:31,880 --> 00:02:38,600
So iteration in range of well number of iterations.

38
00:02:40,160 --> 00:02:42,220
Number of iterations.

39
00:02:44,610 --> 00:02:45,810
Optimizer.

40
00:02:47,430 --> 00:02:49,440
Is zero grid.

41
00:02:50,350 --> 00:02:52,270
Zero grad.

42
00:02:52,300 --> 00:02:53,350
Grad not great.

43
00:02:54,810 --> 00:02:55,410
Grant.

44
00:02:57,160 --> 00:03:00,430
And now we will generate the training data.

45
00:03:00,430 --> 00:03:02,260
And these are the training data.

46
00:03:02,260 --> 00:03:05,380
That means they are the points in the domain.

47
00:03:05,530 --> 00:03:09,040
These are points in the domain, not on the boundary.

48
00:03:09,160 --> 00:03:12,370
They might get in the boundary, but we don't really care because it's.

49
00:03:12,550 --> 00:03:20,050
Well yeah, I need to check but basically it they might even if they are some points that is generated

50
00:03:20,050 --> 00:03:27,460
randomly on the boundary, it will not cause a problem because we are generating a good amount of boundary

51
00:03:27,550 --> 00:03:28,300
points.

52
00:03:28,300 --> 00:03:34,920
But I think in this case, like when we have the points, it will I think it will generate from 0 to

53
00:03:34,920 --> 00:03:36,190
1 these points.

54
00:03:36,190 --> 00:03:41,950
So there is there are some a bit of risk, but but we don't really care because.

55
00:03:42,570 --> 00:03:43,860
We have boundary condition.

56
00:03:43,860 --> 00:03:49,860
And even if there are one training case that is a little bit strange, it will kind of.

57
00:03:50,820 --> 00:03:55,650
A be modified and even even this boundary condition.

58
00:03:57,010 --> 00:04:00,530
Well, it's about around that it will be zero.

59
00:04:00,540 --> 00:04:03,090
So and the boundary condition is already zero.

60
00:04:03,090 --> 00:04:09,090
So even this function, this boundary, it's think its value is near to zero.

61
00:04:09,810 --> 00:04:19,740
But yeah, it's if you if you have, um, well, just be careful about the points inside the boundary

62
00:04:19,770 --> 00:04:25,500
is different than the points in the boundary that these points are.

63
00:04:26,720 --> 00:04:32,350
At the point in the domain which is here, which we are generating random points in X, Y and T.

64
00:04:33,330 --> 00:04:41,550
And here we will just put it like generate this and we pass the number of points.

65
00:04:42,420 --> 00:04:43,320
Number of points.

66
00:04:43,770 --> 00:04:46,080
So that's it.

67
00:04:46,580 --> 00:04:53,390
That's the the that's the point that is in the domain that the need that we need to calculate.

68
00:04:53,390 --> 00:05:01,850
And then later I don't want to like too much, but basically we will use them to calculate the the loss

69
00:05:01,850 --> 00:05:07,850
which is we said there is a data loss which basically from the boundary condition and the initial condition

70
00:05:08,030 --> 00:05:17,990
and they have another loss that is generated from the actual, um, the points to follow the physics

71
00:05:17,990 --> 00:05:22,430
laws, which is the we have the 2D heat equation.

72
00:05:23,450 --> 00:05:23,900
Okay.

73
00:05:23,900 --> 00:05:28,940
So these are the points in the domain and now we have the points in the boundary.

74
00:05:28,940 --> 00:05:38,420
So y underscore b x underscore b t underscore b equals generate training data.

75
00:05:38,540 --> 00:05:40,190
Actually just take it all of them.

76
00:05:40,340 --> 00:05:44,360
This one and of course, points we have to put it here.

77
00:05:46,680 --> 00:05:47,550
And that's it.

78
00:05:48,910 --> 00:05:50,980
So these are now we created.

79
00:05:50,980 --> 00:05:53,770
Now we have points in the middle.

80
00:05:54,730 --> 00:05:58,720
And we have points in the, uh, in the boundary.

81
00:05:58,720 --> 00:06:08,200
So just to be visually, uh, we put it, we put it to green, we have these points, that is.

82
00:06:10,550 --> 00:06:11,570
Synthesize.

83
00:06:12,870 --> 00:06:14,280
We have these points.

84
00:06:14,280 --> 00:06:19,170
The domain, which will be located randomly spread in the middle.

85
00:06:20,150 --> 00:06:23,000
And of course, in the in the time domain.

86
00:06:23,000 --> 00:06:26,900
So we are calculating not just X and Y, we're also calculating in the time.

87
00:06:27,080 --> 00:06:30,500
And of course, we have the other points.

88
00:06:30,590 --> 00:06:31,880
We'll put them.

89
00:06:32,640 --> 00:06:33,390
Maybe.

90
00:06:34,450 --> 00:06:37,300
Uh, this like orange.

91
00:06:37,300 --> 00:06:41,830
We we will be generated points around here also.

92
00:06:44,450 --> 00:06:46,760
Randomly, but only on the boundary.

93
00:06:47,030 --> 00:06:47,930
So this.

94
00:06:47,930 --> 00:06:49,160
This too is.

95
00:06:49,190 --> 00:06:49,940
This is.

96
00:06:50,640 --> 00:06:52,500
The functions of this.

97
00:06:53,570 --> 00:06:54,080
Okay.

98
00:06:54,110 --> 00:06:54,790
So.

99
00:06:54,800 --> 00:06:56,690
So t initial.

100
00:06:58,430 --> 00:07:04,820
We have the time at the initial condition is torch dot.

101
00:07:05,860 --> 00:07:06,520
Zero.

102
00:07:07,450 --> 00:07:08,320
Like.

103
00:07:10,010 --> 00:07:10,610
Picks.

104
00:07:11,560 --> 00:07:12,900
It actually doesn't matter.

105
00:07:12,900 --> 00:07:19,560
We can just put it to evil because all of them have the same.

106
00:07:20,400 --> 00:07:21,030
Size.

107
00:07:22,440 --> 00:07:23,400
Number of points.

108
00:07:23,400 --> 00:07:23,850
Yeah.

109
00:07:23,880 --> 00:07:28,710
They all have a number of points and one column, so it doesn't really matter.

110
00:07:29,130 --> 00:07:29,880
Whatever it is.

111
00:07:29,880 --> 00:07:32,280
But because if we can call it.

112
00:07:32,490 --> 00:07:33,060
Yeah.

113
00:07:33,810 --> 00:07:38,160
T initial equals initial.

114
00:07:39,270 --> 00:07:45,060
Condition which the function we wrote and what we need to pass.

115
00:07:47,140 --> 00:07:47,920
X and Y.

116
00:07:49,350 --> 00:07:52,020
Y, X and Y because.

117
00:07:53,990 --> 00:07:55,490
We have to pass.

118
00:07:55,520 --> 00:07:59,600
We need the initial condition to be on the whole domain, not the boundary condition.

119
00:08:00,530 --> 00:08:02,030
These are just boundary points.

120
00:08:02,030 --> 00:08:06,500
So now we have the initial time, which is zero.

121
00:08:06,800 --> 00:08:13,670
We have a we take these X and Y these and we have the initial.

122
00:08:15,790 --> 00:08:21,130
Now the boundary value we talked about, there is a custom value in here, the boundary.

123
00:08:22,410 --> 00:08:23,460
A boundary.

124
00:08:26,180 --> 00:08:27,410
The costume.

125
00:08:27,470 --> 00:08:28,070
This one.

126
00:08:28,100 --> 00:08:29,240
The boundary condition.

127
00:08:29,240 --> 00:08:34,280
We have a custom value so we can set this custom value equals zero.

128
00:08:35,100 --> 00:08:35,880
And.

129
00:08:37,270 --> 00:08:39,490
Now we define the.

130
00:08:40,200 --> 00:08:41,880
Values of the boundary.

131
00:08:41,910 --> 00:08:42,720
You.

132
00:08:43,930 --> 00:08:44,590
A bond.

133
00:08:44,710 --> 00:08:46,510
Will, just let me just take it.

134
00:08:46,520 --> 00:08:48,280
I'm not the best in spelling.

135
00:08:49,140 --> 00:08:51,540
So be boundary.

136
00:08:52,850 --> 00:08:54,560
In the X direction.

137
00:08:54,560 --> 00:08:55,520
Equals.

138
00:08:55,700 --> 00:08:56,720
Equals what?

139
00:08:56,720 --> 00:08:57,890
The boundary condition.

140
00:08:58,010 --> 00:08:59,190
We need the whole thing.

141
00:08:59,210 --> 00:09:00,440
The boundary condition.

142
00:09:01,140 --> 00:09:02,310
The boundary condition.

143
00:09:02,310 --> 00:09:03,030
At what?

144
00:09:04,570 --> 00:09:05,920
We need to pass.

145
00:09:08,140 --> 00:09:08,440
The.

146
00:09:08,440 --> 00:09:08,950
What is it?

147
00:09:10,320 --> 00:09:12,480
No, this is the training, the boundary.

148
00:09:12,660 --> 00:09:21,420
This one we need X, Y and T, So we need the boundary X and the boundary Y and the T, of course,

149
00:09:21,450 --> 00:09:23,200
T, We don't.

150
00:09:23,400 --> 00:09:27,000
Just remember, we generated these points at random time.

151
00:09:27,750 --> 00:09:29,610
So here we take it.

152
00:09:29,880 --> 00:09:31,320
A boundary condition.

153
00:09:31,880 --> 00:09:33,060
And what is it?

154
00:09:33,920 --> 00:09:34,420
Yeah.

155
00:09:34,430 --> 00:09:35,240
This.

156
00:09:36,840 --> 00:09:37,440
Exp.

157
00:09:40,340 --> 00:09:41,930
We'll just take it like this.

158
00:09:42,000 --> 00:09:43,610
Wipe and.

159
00:09:44,580 --> 00:09:50,820
A teepee and we need to pass the custom value that is.

160
00:09:51,680 --> 00:09:53,150
These points.

161
00:09:53,630 --> 00:09:57,260
These points will have a custom value of.

162
00:09:59,370 --> 00:10:01,460
Uh, well, zero, basically.

163
00:10:01,530 --> 00:10:08,130
So the thing is, if you notice, like if we this initial condition, we only have x, Y, and this

164
00:10:08,130 --> 00:10:09,390
we have X, Y and Z.

165
00:10:09,420 --> 00:10:10,590
Why do we have this?

166
00:10:11,310 --> 00:10:15,900
Because in initial condition, it's always time is zero.

167
00:10:16,140 --> 00:10:21,540
In in in the boundary condition, time can change and or time will change.

168
00:10:21,540 --> 00:10:28,230
And we're actually sampling the whole time domain in different like random basically.

169
00:10:29,340 --> 00:10:32,010
So here we have the boundary condition.

170
00:10:32,100 --> 00:10:39,180
We define it in for the x like boundary in the X direction.

171
00:10:39,180 --> 00:10:42,870
And then we have the Y direction.

172
00:10:42,870 --> 00:10:46,620
And this time we will use these boundary points.

173
00:10:46,620 --> 00:10:47,190
But.

174
00:10:47,190 --> 00:10:49,530
But we need to flip them.

175
00:10:51,270 --> 00:10:52,200
Flipping them.

176
00:10:52,530 --> 00:10:56,820
The reason is, is is that I think we we don't Yeah.

177
00:10:56,820 --> 00:10:58,890
I think it's better to do like this.

178
00:10:59,280 --> 00:11:02,430
We have these boundaries that is going to be generated.

179
00:11:02,700 --> 00:11:04,640
We divide them on two.

180
00:11:04,650 --> 00:11:12,010
So we will do the boundary condition for both.

181
00:11:12,030 --> 00:11:13,320
Sorry, this is you.

182
00:11:15,920 --> 00:11:18,920
For the random points.

183
00:11:18,920 --> 00:11:25,310
And because we divide on two, it's better to have them two ways just because it's random.

184
00:11:25,310 --> 00:11:31,250
We just flip it to basically multiply the amount of points we have.

185
00:11:32,590 --> 00:11:34,210
So here.

186
00:11:34,690 --> 00:11:35,710
That's it.

187
00:11:35,830 --> 00:11:38,890
That's it for the optimization.

188
00:11:39,610 --> 00:11:45,520
Or we put the optimum and then we call these initial conditions and boundary conditions.

189
00:11:45,550 --> 00:11:49,590
The next way is we will need to calculate the losses.

190
00:11:49,600 --> 00:12:00,010
It's a little bit maybe confusing and to define the to make everything random rather than a mesh, but

191
00:12:00,010 --> 00:12:11,770
it actually uses the power of the neural networks by having random we don't care about mesh is is this

192
00:12:11,770 --> 00:12:17,560
is why I wrote the code like this because I want to show you decide where these points are.

193
00:12:17,590 --> 00:12:18,970
You decide.

194
00:12:20,660 --> 00:12:23,570
How they are spread and you don't really care to have a mesh.
