Open svkarash opened 9 months ago
Something is wrong. This is the error.
[<ipython-input-128-282feef19924>](https://localhost:8080/#) in pde2(X, U)
4
5 psi_x = dde.grad.jacobian(psi, x)
----> 6 psi_xx = dde.grad.hessian(psi, x)
7 psi_xxx = dde.grad.jacobian(psi_xx, x)
8 psi_xxxx = dde.grad.hessian(psi_xx, x)
and this is the code you've provided.
psi_x = dde.grad.jacobian(psi, x)
psi_xx = dde.grad.hessian(psi, x, i=0, j=0)
psi_xxx = dde.grad.jacobian(psi_xx, x)
psi_xxxx = dde.grad.hessian(psi_xx, x, i=0, j=0)
Please provide the correct error. Also, it will be helpful if yiou provide the entire code.
Dear @praksharma, you are right. However, those are the same as I read manual and command description. Assume that the command is psi_xx = dde.grad.hessian(psi, x). Since I was working on the code, some changes occurred.
Hey I think I found the issue. According to the definition of Jacobian and Hessian here, you need to use I,j to decide which column of x and y you want to use in the differentiation.
Instead use i and j specify the column number in the tensor.
Here is a simple example,
So, don't redefine the X,U in x,z,t and psi, eta. Just use the tensor slice in the Jacobian and Hessian. For example, psi_x = dde.grad.jacobian(U,X, i=0, j=0) psi_xx = dde.grad.hessian(U, X, i=0, j=0)
Psi_xx can also be calculated as psi_xx = dde.grad.jacobian(psi_x, X, i=0, j=0) And so on.
I think slicing X and U as x,z,t and eta, psi detaches the tensor from the graph. If you don't understand this line, just ignore it.
Hey I think I found the issue. According to the definition of Jacobian and Hessian here, you need to use I,j to decide which column of x and y you want to use in the differentiation.
Instead use i and j specify the column number in the tensor.
Here is a simple example,
- for psi_x, i=0, j=0
- For psi_z, i=0, j=1
- for psi_t, i=0, j=2 Similarly,
- for eta_x, i=1, j=0
- For eta_z, i=1, j=1
- for eta_t, i=1, j=2 You see i and j are column index of the X and U. This should be done for both Jacobian and Hessian.
So, don't redefine the X,U in x,z,t and psi, eta. Just use the tensor slice in the Jacobian and Hessian. For example, psi_x = dde.grad.jacobian(U,X, i=0, j=0) psi_xx = dde.grad.hessian(U, X, i=0, j=0)
Psi_xx can also be calculated as psi_xx = dde.grad.jacobian(psi_x, X, i=0, j=0) And so on.
I think slicing X and U as x,z,t and eta, psi detaches the tensor from the graph. If you don't understand this line, just ignore it.
Dear @praksharma
you are correct. I have also adjusted the definition of derivatives according to your explanation regarding X and U. It works. But this structure is not human readable :)
However, I'm encountering an issue with defining independent and dependent variables. In this scenario, all tensors have a single column, essentially forming a vector. Considering this, it seems logical that using i=0 and j=0 should be effective. This approach is also referenced in the manual for the command. I'm keen to understand why the method of defining independent and dependent variables is not proving successful.
Any PDE is combination of derivative of output layers with respect to input layers. So if you are solving 2D fluid flow, the inputs will be x and y, whereas the output will be u,v,p. This is where you need i,j. A neural network is represented as a graph. This is how DeepXDE is designed.
If you don't like this, you can use the good old torch.autograd.grad()
. You can then calculate the gradient as
psi_x_y = torch.autograd.grad(U, X, grad_outputs=torch.ones_like(U), create_graph=True)[0]
psi_x = psi_x_y[:,0]
psi_x = psi_x_y[:,1]
You see, DeepXDE abstracts all these things so you can focus on the problem rather than programming.
Dear @praksharma , Thanks for clear explanation. Consider X=[x,z,t] and U=[psi,eta] Therefore, psi_xx = dde.grad.hessian(U, X, component=0, i=0, j=0) Now to calculate higher order derivatives such as psi_xxxx or psi_xxzz one can write
psi_xxxx = dde.grad.hessian(psi_xx, X, i=0, j=0) psi_xxzz = dde.grad.hessian(psi_xx, X, i=1, j=1)
in these cases, psi_xx is used and component=None. I believe this structure is the same as my definition in the issue. next question is how I can reshape psi_xx = dde.grad.hessian(psi, x) to be the same as psi_xx = dde.grad.hessian(U, X, component=0, i=0, j=0) Actually the error refers to the acceptable shape.
Yes, you just need to read the first line of the docs here. It says,
H[i][j] = d^2y / dx_i dx_j
With component you can decide which y
i.e, the output unit you are picking. Here are more example,
Given
psi_xx = dde.grad.hessian(U, X, component=0, i=0, j=0)
We can write,
psi_xxxx = dde.grad.hessian(psi_xx, X, component=0, i=0, j=0)
psi_xxzz = dde.grad.hessian(psi_xx, X, component=0, i=1, j=1)
eta_xx = dde.grad.hessian(U, X, component=1, i=0, j=0)
eta_xxzt = dde.grad.hessian(eta_xx, X, component=1, i=1, j=2)
I hope this covers all the cases. Just remember in jacobian, the definition changes (here) to J[i][j] = dy_i/dx_j
. So there is no component.
Dear @lululxvi I have specified all essential derivatives as below. However, upon compiling model, an error occurred.
PDE is defined as
Then
The Error is
As you can see the error refers to ----> 6 psi_xx = dde.grad.hessian(psi, x)
How can i solve the error