Giter Club home page Giter Club logo

Comments (7)

praksharma avatar praksharma commented on July 22, 2024 2

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.

from deepxde.

praksharma avatar praksharma commented on July 22, 2024 1

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.

from deepxde.

praksharma avatar praksharma commented on July 22, 2024 1

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.

from deepxde.

praksharma avatar praksharma commented on July 22, 2024

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.

from deepxde.

svkarash avatar svkarash commented on July 22, 2024

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.

from deepxde.

svkarash avatar svkarash commented on July 22, 2024

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.

from deepxde.

svkarash avatar svkarash commented on July 22, 2024

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.

from deepxde.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.