Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution Bundle #3

Open
tanmay2798 opened this issue Mar 4, 2024 · 8 comments
Open

Solution Bundle #3

tanmay2798 opened this issue Mar 4, 2024 · 8 comments

Comments

@tanmay2798
Copy link

The solution bundle method is used in this file - https://github.com/Isaac-Somerville/Neural-Networks-for-Solving-Differential-Equations/blob/main/ThreeBodyProblem/threeBodyOriginalMethod.py ?

@Isaac-Somerville
Copy link
Owner

The solution bundle method is used in this file - https://github.com/Isaac-Somerville/Neural-Networks-for-Solving-Differential-Equations/blob/main/ThreeBodyProblem/threeBodyOriginalMethod.py ?

Yes. The other files in the ThreeBodyProblem folder use this method as well, but also include curriculum learning

@tanmay2798
Copy link
Author

Okay, also can you tell me if I use spring mass system where there are double derivatives, according to your naming system, would it be like.
x = trialSolution(x0, xOut, t)
dxTrial = dTrialSolution(xOut, dxOut, t)
d2xTrial = dTrialSolution(***, d2xOut, t)
What should be in place of ***?

should it be the value I get if I pass xOut through the network?

@Isaac-Somerville
Copy link
Owner

For second derivatives, you would require another function, d2TrialSolution, that uses the analytic expression for the second derivative of trialSolution. It would look something like this:

def d2TrialSolution(varOut, dVarOut, d2VarOut, t):
"""
Second derivative w.r.t. t of trial solution for a given variable varOut at times t with initial values varInitial

Arguments:
varOut (tensor of shape (batchSize,1)) -- network output for variable at times t
dVarOut (tensor of shape (batchSize,1)) -- derivative of network output for variable w.r.t. t at times t
d2VarOut (tensor of shape (batchSize,1)) -- second derivative of network output for variable w.r.t. t at times t
t (tensor of shape (batchSize,1)) -- times at which variable is evaluated

Returns:
d2trialSoln (tensor of shape (batchSize,1)) -- second derivative of trial solution for given variable at 
    times t with initial values varInitial"""
# d2TrialSoln = (torch.exp(-t)) * dVarOut  + ((1 - torch.exp(-t)) * d2VarOut) - torch.exp(-t) * varOut + torch.exp(-t) * dVarOut
d2TrialSoln = ((1 - torch.exp(-t)) * d2VarOut) + (torch.exp(-t) * (2 * d2VarOut  - varOut))
return d2TrialSoln

In the train function you would be required to evaluate d2xOut in the same was dxOut was calculated:
d2xOut = grad(dxOut,t,torch.ones_like(dxOut),retain_graph=True, create_graph=True)[0]

Problems 5, 7 and 8 have more examples of doing this for second derivatives, as well as calculating mixed partial derivatives using autograd.

Hope this helps!

@tanmay2798
Copy link
Author

tanmay2798 commented Mar 4, 2024

@Isaac-Somerville
https://github.com/Isaac-Somerville/Neural-Networks-for-Solving-Differential-Equations/blob/main/LagarisProblems/prob5.py

Is this and prob7 and prob8 in LagarisProblems folder are using solution bundle?

@Isaac-Somerville
Copy link
Owner

Isaac-Somerville commented Mar 4, 2024 via email

@tanmay2798
Copy link
Author

Okay, and should it be d2TrialSoln = ((1 - torch.exp(-t)) * d2VarOut) + (torch.exp(-t) * (2 * dVarOut - varOut))

@Isaac-Somerville
Copy link
Owner

Yes that's right

@tanmay2798
Copy link
Author

tanmay2798 commented Mar 5, 2024

@Isaac-Somerville
adam.txt
I modified your code to work for spring mass dampener system (md2x/dt2 + bdx/dt + k(x-L)=0). But, for me it doesn't give promising results. Can you suggest what changes I need to make?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants