So now let's start building the data.
So the first thing is, well, we we start by this the easiest thing.
So let's first define the initial condition.
So def.
Initial.
Condition can.
Edition.
Well, take X and Y and it will return the initial condition.
So torch dot sine.
This is of course we can, um, I mean we can add here like if we want a little bit, uh.
More customization.
But let's take it simple.
And when just we return the actual initial condition as we write the equation in here, not kind of
customized.
If you want to customize it, you need to actually go to here and change the return function.
So dot sign torch.py.
Of course we can use math.py as well, but let's just use torches as it will work.
And then torch.
Dot sign.
And torch dot pi.
Multiply.
Multiply two.
Y.
So this is the initial condition and it will give us a like a kind of hump, a peak around the zero.
And as the the time goes, this peak will collapse.
It will diffuse.
You can use other, of course, networks or other sorry like functions.
Def boundary.
Boundary.
Same condition can.
On duration.
We will have X, we will have Y, and we will have T, and we have a custom value.
Custom.
Value and this will return.
Torch dot.
Full.
Like basically we will have the same.
X the same shape as x.
And with we will give it the custom value.
Custom.
And this core value, of course, I mean, in this example, it's a bit kind of simple.
So x y it will be A3A box like a three, not triangle or a square.
We have X and Y is the same.
And so this shape is the same for.
So if we if we have different like if we have X and Y is different, you need to return a different
way.
Of course this is it depends on you as a coder.
And here I'm just trying to keep things as simple as possible.
This is a box or the problem we are trying to to, to make or to solve is as simple as or it is just
a triangle, a square with x and Y.
And then.
With X and y and x will equal to Y.
And then what we will have is we will have something like in the middle, a hump like this, that we
will give it the the value of this will be computed or it will be generated by the sine wave, the sine
wave.
And then as the time goes and of course, this this direction, this direction is you or the temperature.
And as the time goes, the heat will start to diffuse.
So.
So this is what we what we're doing.
And so initial condition, boundary condition, shift, enter.
Now, after that, what do we need to do?
So far, we don't have really a domain.
We don't we just have a function that you give it X and Y, give you back the initial condition and
x and Y give you back the Or.
Yeah, X and y and give you back the boundary condition.
So now what we want to do is we want to a function that generate a training data.
Training data.
And actually this is more like, well, the correct thing is, of course it's all training data.
But the correct analogy here is this function is going to generate a domain points.
So generating the points we start by x equals torch dot random and we will have the number of points
and so that we will have the rows, it will be number of points, say 1000 point whatever number of
points we want for training.
And the column is one.
So for our case, we don't need more than one.
And actually this way of generation it will generate points from 0 to 1.
Here requires grad equals.
True.
And.
We do the same thing for.
Why.
And same thing for tea.
So why random?
All of it is the same.
And tea also the same.
And returns the X, Y and T.
And we shift enter.
So now we have the first function is initial condition, the second function boundary condition.
Third function is the function that generates a point.
The fourth thing is we need to do is all these are just points in the middle.
We need another generator or this.
These points are just spread all the way around the network, but around the domain.
But what we need is we need a function.
That generates points Generate boundary points.
Rate.
Boundary.
Points.
And we will have also the same thing, number of points.
And then what we will do is X.
Boundary equals torch dot.
Tensor.
And we will generate from zero 0 to 1.0.
Dot re.
Pete.
This thing of number.
Number.
A number of points.
Over to.
To.
And.
Why?
Boundary.
Will equals torch dot tensor.
And.
Uh, will.
Random.
Rent.
And we will also have them as number of points.
One thing to note is this operator like divide.
Divide by two means we need to repeat this operation, the tensor like generating having this tensor
from 0 to 1 two.
Well, basically, let's say if we have ten times, we need to repeat it five times.
If the number of points enter is a little bit odd, like let's say like 11, the 11 divide by two,
it will be five point something and then then it will be basically five again.
So why boundary equals tensor dot random.
And now we just generate so we make first the first tensor, it will generate a point that is like kind
of a spaced like in a mesh wise and this one, it will generate just random values from a like just
number of points that it will be random for Y, but here it will be only zero and one.
So the tensor will be at zero and at one and it will keep having a so the x axis has to be left or right
and the y axis we just random whatever it is.
This is the boundary, of course, in the x axis.
But what we need to do is we need also to generate boundaries in the y axis.
For that, we need to if we make another random thing if torch dot random.
More than.
Well, like, basically it will generate from 0 to 1 random value or 0.5.
And X.
We just switched them Expounder.
Why boundary.
Equals.
We switch the thing, so x boundary will be y boundary.
And why boundary.
This one will be expanded.
Why did we do that?
What we did is we went to the domain and from 0 to 1 we made some points or we want to make these points.
That is X is set a value of zero and or and one.
So x is is zero and y is x is zero.
And the first value and the second value is one.
And what we did is we generate random values around it.
So here we have X will be zero and x will be one.
And what we did, the first thing is we went here and we made just any random value in this location,
just any random values here and here.
The same thing here in random values.
And then what we did is we took part of these random values and we put them here.
So now we have boundary values around this area.
So the last thing we need to do is return.
X x boundary.
And we reshape it.
Into minus one.
One.
So one only one point.
So the dimension is the rows.
And it is just to make sure it is only one row.
Same thing for Y.
For why?
And we reshape it this way.
No, this is generating the boundary points.
Now what we need is to generate the training data, the boundary training data generate.
Boundary.
Raining.
Data and we will add number number of points.
And here.
What we will do is, Well, we need the first generator.
Which is generating the points, this function and we will pass on the number of points.
And think I need a little bit space.
And then the.
Time will be torch dot again random.
We don't really care.
Number of points.
And we will have the column one and requires.
Great.
And.
That equals true.
Return.
Expunging.
Why boundary.
Empty.
And shift enter.
With that.
We'll just make housekeeping a little bit.
Just like this.
So with that, what did we do?
We actually generated.
A boundary point.
And with this function, what we did, we ordered a boundary point.
And this function gave us this boundary point that is split somehow, randomly.
And the other one is we just took some random from 0 to 1.
The time just we took again some random points in time.
Again, we're training the network is not really explicit solution.
It's more like implicit solution.
But but this time we don't really have a grid.
We don't need a grid.
We just randomly separate these points or generate these points to actually get the required data.