1
00:00:00,820 --> 00:00:07,450
Okay, so now what we need to do is to write the training function.

2
00:00:07,450 --> 00:00:13,390
So we start by Def Train Self.

3
00:00:14,140 --> 00:00:15,880
And then self.

4
00:00:15,880 --> 00:00:18,490
And of course the model is quite big.

5
00:00:18,520 --> 00:00:22,120
Or we we wrote a lot of code without actually running.

6
00:00:22,120 --> 00:00:25,750
So most likely we'll have some trouble.

7
00:00:27,440 --> 00:00:28,670
Or like debugging.

8
00:00:29,370 --> 00:00:36,180
So first one is to train the model and for I in range.

9
00:00:37,840 --> 00:00:40,480
Range 1000.

10
00:00:40,720 --> 00:00:43,810
We will do the Adam selfie.

11
00:00:43,960 --> 00:00:44,680
Adam.

12
00:00:45,800 --> 00:00:47,030
Step.

13
00:00:48,250 --> 00:00:51,100
Self dot loss.

14
00:00:52,060 --> 00:00:53,110
Function.

15
00:00:55,180 --> 00:00:57,280
Uh, loss function.

16
00:01:00,250 --> 00:01:05,650
And after that we will self dot.

17
00:01:06,980 --> 00:01:09,380
Basically optimizer.

18
00:01:15,610 --> 00:01:17,230
Dot step.

19
00:01:18,170 --> 00:01:20,630
And actually, this guy will do his own.

20
00:01:21,550 --> 00:01:22,570
The iteration.

21
00:01:23,830 --> 00:01:25,540
But we have to also.

22
00:01:26,360 --> 00:01:30,050
Thus the loss, which is always important.

23
00:01:30,860 --> 00:01:32,270
And then death.

24
00:01:33,580 --> 00:01:37,090
Evaluation eval uation.

25
00:01:38,850 --> 00:01:39,990
Self.

26
00:01:41,860 --> 00:01:43,440
And just a little.

27
00:01:45,320 --> 00:01:49,430
Self-taught mode eval.

28
00:01:52,350 --> 00:01:53,340
And.

29
00:01:54,200 --> 00:01:55,340
That's it.

30
00:01:56,000 --> 00:02:02,690
It seems fast, but of course, actually I didn't put.

31
00:02:05,650 --> 00:02:06,700
And it's just.

32
00:02:08,510 --> 00:02:09,500
Myself.

33
00:02:10,660 --> 00:02:14,380
We didn't put the model declared the model.

34
00:02:15,250 --> 00:02:16,510
Model equals.

35
00:02:16,540 --> 00:02:17,630
Neural network.

36
00:02:17,650 --> 00:02:18,310
This.

37
00:02:19,160 --> 00:02:20,000
Neural network.

38
00:02:20,000 --> 00:02:21,260
We didn't put it here.

39
00:02:24,490 --> 00:02:25,540
To device.

40
00:02:26,760 --> 00:02:27,870
Yeah, this is.

41
00:02:27,870 --> 00:02:29,880
We should put it just.

42
00:02:30,900 --> 00:02:31,300
Okay.

43
00:02:31,350 --> 00:02:33,050
Seems good.

44
00:02:33,060 --> 00:02:34,200
This one.

45
00:02:35,490 --> 00:02:38,430
This one, I change its location.

46
00:02:42,830 --> 00:02:43,580
And here.

47
00:02:49,410 --> 00:02:49,950
Okay.

48
00:02:49,950 --> 00:02:55,650
Now the moment of truth will be actual train.

49
00:02:57,030 --> 00:03:00,000
Three training.

50
00:03:01,210 --> 00:03:02,830
Net equals.

51
00:03:02,860 --> 00:03:03,760
Net.

52
00:03:06,100 --> 00:03:09,160
Basically the whole this.

53
00:03:10,680 --> 00:03:13,440
And train.

54
00:03:15,410 --> 00:03:18,320
Knit dot train.

55
00:03:19,910 --> 00:03:22,940
And shift enter and

56
00:03:24,890 --> 00:03:26,450
47.

57
00:03:29,730 --> 00:03:30,800
Let's just.

58
00:03:32,340 --> 00:03:33,420
Syntax.

59
00:03:36,390 --> 00:03:40,200
A trained self optimizer loss function.

60
00:03:41,910 --> 00:03:42,680
It.

61
00:03:42,750 --> 00:03:43,910
Adam, Step.

62
00:03:46,590 --> 00:03:48,990
97.

63
00:03:53,710 --> 00:03:55,060
Adam step.

64
00:03:56,620 --> 00:03:59,740
This seems no problem.

65
00:04:03,350 --> 00:04:05,810
We go to the Adam part?

66
00:04:17,740 --> 00:04:19,000
Torch Optim.

67
00:04:20,580 --> 00:04:21,180
Adam.

68
00:04:30,290 --> 00:04:31,220
Okay.

69
00:04:41,520 --> 00:04:42,780
The Los.

70
00:04:44,470 --> 00:04:45,850
Modules are.

71
00:04:47,950 --> 00:04:49,450
Autograd.

72
00:04:49,480 --> 00:04:51,910
Not autograd gradient.

73
00:04:51,940 --> 00:04:52,990
Not grad.

74
00:04:53,860 --> 00:04:54,670
So.

75
00:04:56,390 --> 00:04:56,710
To.

76
00:04:59,190 --> 00:05:03,840
Grant just means we have another one because we could best it.

77
00:05:04,900 --> 00:05:07,000
The execs here.

78
00:05:07,000 --> 00:05:07,960
Also two grand.

79
00:05:07,980 --> 00:05:08,800
Total grand.

80
00:05:09,810 --> 00:05:10,770
Okay.

81
00:05:16,650 --> 00:05:18,380
Well, let's run it again.

82
00:05:18,390 --> 00:05:19,290
All of it.

83
00:05:27,130 --> 00:05:29,560
The first one is.

84
00:05:31,450 --> 00:05:36,700
The grad location, this auto grad, which is.

85
00:05:39,160 --> 00:05:39,540
Um.

86
00:05:39,940 --> 00:05:42,840
Do we already have this size?

87
00:05:42,850 --> 00:05:46,870
And this one's like, is different size.

88
00:05:46,870 --> 00:05:52,240
So we have to put it here and like this and this should match, so.

89
00:05:53,810 --> 00:05:57,010
Uh, we also have the error.

90
00:06:19,950 --> 00:06:22,230
And we have also.

91
00:06:23,290 --> 00:06:26,890
This size is not matching, so it's better.

92
00:06:27,880 --> 00:06:28,900
Move.

93
00:06:31,790 --> 00:06:34,100
We said we move this one here.

94
00:06:34,250 --> 00:06:36,040
We just keep it as is.

95
00:06:36,050 --> 00:06:39,710
So this side of the equation should be equal this side of the equation.

96
00:06:39,770 --> 00:06:40,800
It's, um.

97
00:06:41,180 --> 00:06:41,690
It's.

98
00:06:41,690 --> 00:06:48,500
This is better because this have as a tensor it will have a different size than the other one.

99
00:06:48,500 --> 00:06:52,040
So it's better to this one rather than minus.

100
00:06:52,040 --> 00:06:57,170
We just separate it like this and remove this zero.

101
00:06:59,140 --> 00:07:01,090
And this one just.

102
00:07:07,460 --> 00:07:09,050
Another issue here.

103
00:07:09,050 --> 00:07:13,160
I found that it's quite strange, actually.

104
00:07:13,160 --> 00:07:18,050
Here we have when we declare.

105
00:07:26,370 --> 00:07:26,970
The.

106
00:07:31,070 --> 00:07:33,980
And here at.

107
00:07:35,050 --> 00:07:38,350
This one has to be u X, not x train.

108
00:07:38,350 --> 00:07:40,180
So line 56.

109
00:07:41,130 --> 00:07:42,630
Line 56.

110
00:07:42,660 --> 00:07:44,940
It's strange that we use Xtrain.

111
00:07:44,950 --> 00:07:46,500
It's actually the whole domain.

112
00:07:46,500 --> 00:07:49,920
We need the you the value of U for the whole domain.

113
00:07:49,920 --> 00:07:53,460
So this is why it should be X, I think.

114
00:07:53,700 --> 00:07:55,920
I think now it will run.

115
00:07:57,780 --> 00:08:00,660
So just run it again.

116
00:08:07,720 --> 00:08:12,850
Yeah, now it's running and it will take some not so much time.

117
00:08:13,240 --> 00:08:20,110
And basically it's a lot of moving parts, a lot of coding.

118
00:08:20,650 --> 00:08:25,260
We have to be careful just as it runs.

119
00:08:25,270 --> 00:08:27,730
I will just summarize what we did so far.

120
00:08:27,760 --> 00:08:33,370
It's basically we have imported the libraries, we have defined the network.

121
00:08:33,370 --> 00:08:38,230
After that, we set here the model to be a neural network.

122
00:08:38,230 --> 00:08:39,940
This is what we forgot before.

123
00:08:40,510 --> 00:08:49,540
And the first thing is here we after the setting the model, we start computing the we start creating

124
00:08:49,540 --> 00:08:58,150
the domain to actually create the data and define the initial condition and the boundary condition we

125
00:08:58,180 --> 00:08:58,930
set.

126
00:09:00,130 --> 00:09:06,030
The initial condition and boundary condition as we wish, which is in boundary condition, is zeros.

127
00:09:06,130 --> 00:09:10,060
And the initial condition is a sine wave.

128
00:09:11,100 --> 00:09:11,970
Uh, this is the.

129
00:09:11,970 --> 00:09:13,620
The values of all of this.

130
00:09:13,950 --> 00:09:20,520
We later after that, we define the optimizer functions, and then we define the method to calculate

131
00:09:20,520 --> 00:09:21,040
the loss.

132
00:09:21,060 --> 00:09:29,680
The loss means, uh, like when we have two, the two components we need to use the mean squared error.

133
00:09:29,700 --> 00:09:33,810
Now, the type of loss we need to calculate is basically.

134
00:09:34,870 --> 00:09:42,070
And the data loss, which we need to create a data, which is why predict and the loss of data is simply

135
00:09:42,070 --> 00:09:46,660
the difference between y predicted and Y train.

136
00:09:48,300 --> 00:10:01,380
And then we will calculate you and the X and the D and d, u d, t, and the second derivative of x

137
00:10:01,380 --> 00:10:03,960
with a with u.

138
00:10:03,960 --> 00:10:04,800
With x.

139
00:10:04,830 --> 00:10:12,330
All this has to be calculated in order to put into a loss, which is simply the whole equation.

140
00:10:12,330 --> 00:10:20,670
And here is this part D dt plus Udu has to equal this part.

141
00:10:22,640 --> 00:10:24,920
We can move it to this area here.

142
00:10:24,920 --> 00:10:33,860
But if we want to do that, we have to make sure that this side has the same tensor size as all of these

143
00:10:33,860 --> 00:10:34,190
data.

144
00:10:34,190 --> 00:10:42,740
So to avoid this, just keep the equation as is and put the right side to be this way.

145
00:10:42,860 --> 00:10:45,170
And then this is the loss.

146
00:10:45,740 --> 00:10:49,580
We calculate the whole loss based on that.

147
00:10:49,580 --> 00:10:59,030
And with that we already finished and the actual convergence has been achieved.

148
00:11:00,530 --> 00:11:09,200
A one thing I didn't note is basically this one why we put the zero and we just now test it here.

149
00:11:10,040 --> 00:11:11,630
Here and here.

150
00:11:13,710 --> 00:11:21,120
And just let's remove the zero and see how it looks without the zero and then how it looks with zero.

151
00:11:21,120 --> 00:11:24,210
So we shift enter and we run it.

152
00:11:24,300 --> 00:11:28,260
Of course it will blow up because it's simply.

153
00:11:30,470 --> 00:11:31,400
And not.

154
00:11:34,190 --> 00:11:39,440
Yeah, it's not the size is not compatible, but you can see here.

155
00:11:44,130 --> 00:11:51,300
That the tensor here will will be into a tuple and we don't want that.

156
00:11:51,300 --> 00:11:53,720
So we need to take this one out.

157
00:11:53,730 --> 00:12:02,700
And once we put this zero, the tensor here, we don't have this, um, this parentheses thing here.

158
00:12:02,700 --> 00:12:05,550
So this is why we put zero.
