So now we will start doing the the kind of the training loop we start writing it.
But of course this time also the optimizer.
I as I said it will I will use quite simple optimizer which is Adam.
So.
Let's write it.
Let's write the basically the training loop, but will leave a little bit here space because I want
to put the loss function in here because in this code, other than in the past code, the things used
to be a little bit messy.
I would say here it's a little bit more organized into functions that in your case, if you want to
change the the future, how these things will look, you can simply do that.
So just.
So this will be the the actual description of PDA.
So here, let's do the.
Optimization part to follow kind of the same methodology.
And of course we will write the the main training loop, but this time is a little bit more organized,
I would say, rather than the 1D situation.
Now here a train with pin underscore.
Underscore pin.
And model.
It will take and number of iterations.
Integrations and number of points.
Optimizer to miser equals optimum.
Dot.
Adam.
And model dot parameters.
With a learning rate of one e to the power minus three.
I will just check it a little bit.
Parameters.
Parameters Here.
There's.
Yeah.
Okay.
That's it for the optimizer.
However, we just need to define the the the points as we did before, just a little bit more for this
step.
And later, we will focus only on calculating the losses.
So iteration in range of well number of iterations.
Number of iterations.
Optimizer.
Is zero grid.
Zero grad.
Grad not great.
Grant.
And now we will generate the training data.
And these are the training data.
That means they are the points in the domain.
These are points in the domain, not on the boundary.
They might get in the boundary, but we don't really care because it's.
Well yeah, I need to check but basically it they might even if they are some points that is generated
randomly on the boundary, it will not cause a problem because we are generating a good amount of boundary
points.
But I think in this case, like when we have the points, it will I think it will generate from 0 to
1 these points.
So there is there are some a bit of risk, but but we don't really care because.
We have boundary condition.
And even if there are one training case that is a little bit strange, it will kind of.
A be modified and even even this boundary condition.
Well, it's about around that it will be zero.
So and the boundary condition is already zero.
So even this function, this boundary, it's think its value is near to zero.
But yeah, it's if you if you have, um, well, just be careful about the points inside the boundary
is different than the points in the boundary that these points are.
At the point in the domain which is here, which we are generating random points in X, Y and T.
And here we will just put it like generate this and we pass the number of points.
Number of points.
So that's it.
That's the the that's the point that is in the domain that the need that we need to calculate.
And then later I don't want to like too much, but basically we will use them to calculate the the loss
which is we said there is a data loss which basically from the boundary condition and the initial condition
and they have another loss that is generated from the actual, um, the points to follow the physics
laws, which is the we have the 2D heat equation.
Okay.
So these are the points in the domain and now we have the points in the boundary.
So y underscore b x underscore b t underscore b equals generate training data.
Actually just take it all of them.
This one and of course, points we have to put it here.
And that's it.
So these are now we created.
Now we have points in the middle.
And we have points in the, uh, in the boundary.
So just to be visually, uh, we put it, we put it to green, we have these points, that is.
Synthesize.
We have these points.
The domain, which will be located randomly spread in the middle.
And of course, in the in the time domain.
So we are calculating not just X and Y, we're also calculating in the time.
And of course, we have the other points.
We'll put them.
Maybe.
Uh, this like orange.
We we will be generated points around here also.
Randomly, but only on the boundary.
So this.
This too is.
This is.
The functions of this.
Okay.
So.
So t initial.
We have the time at the initial condition is torch dot.
Zero.
Like.
Picks.
It actually doesn't matter.
We can just put it to evil because all of them have the same.
Size.
Number of points.
Yeah.
They all have a number of points and one column, so it doesn't really matter.
Whatever it is.
But because if we can call it.
Yeah.
T initial equals initial.
Condition which the function we wrote and what we need to pass.
X and Y.
Y, X and Y because.
We have to pass.
We need the initial condition to be on the whole domain, not the boundary condition.
These are just boundary points.
So now we have the initial time, which is zero.
We have a we take these X and Y these and we have the initial.
Now the boundary value we talked about, there is a custom value in here, the boundary.
A boundary.
The costume.
This one.
The boundary condition.
We have a custom value so we can set this custom value equals zero.
And.
Now we define the.
Values of the boundary.
You.
A bond.
Will, just let me just take it.
I'm not the best in spelling.
So be boundary.
In the X direction.
Equals.
Equals what?
The boundary condition.
We need the whole thing.
The boundary condition.
At what?
We need to pass.
The.
What is it?
No, this is the training, the boundary.
This one we need X, Y and T, So we need the boundary X and the boundary Y and the T, of course,
T, We don't.
Just remember, we generated these points at random time.
So here we take it.
A boundary condition.
And what is it?
Yeah.
This.
Exp.
We'll just take it like this.
Wipe and.
A teepee and we need to pass the custom value that is.
These points.
These points will have a custom value of.
Uh, well, zero, basically.
So the thing is, if you notice, like if we this initial condition, we only have x, Y, and this
we have X, Y and Z.
Why do we have this?
Because in initial condition, it's always time is zero.
In in in the boundary condition, time can change and or time will change.
And we're actually sampling the whole time domain in different like random basically.
So here we have the boundary condition.
We define it in for the x like boundary in the X direction.
And then we have the Y direction.
And this time we will use these boundary points.
But.
But we need to flip them.
Flipping them.
The reason is, is is that I think we we don't Yeah.
I think it's better to do like this.
We have these boundaries that is going to be generated.
We divide them on two.
So we will do the boundary condition for both.
Sorry, this is you.
For the random points.
And because we divide on two, it's better to have them two ways just because it's random.
We just flip it to basically multiply the amount of points we have.
So here.
That's it.
That's it for the optimization.
Or we put the optimum and then we call these initial conditions and boundary conditions.
The next way is we will need to calculate the losses.
It's a little bit maybe confusing and to define the to make everything random rather than a mesh, but
it actually uses the power of the neural networks by having random we don't care about mesh is is this
is why I wrote the code like this because I want to show you decide where these points are.
You decide.
How they are spread and you don't really care to have a mesh.