-
Notifications
You must be signed in to change notification settings - Fork 756
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
STMsFNN
performs poorly on the 2D wave equation
#492
Comments
The initial loss is 1.03e+16, so it seems the scaling has an issue. |
Thank you for the suggestions, @lululxvi! I made some changes to my code and now it seems to do a bit better. But I still am not able to get the desired output - import numpy as np
import pandas as pd
import deepxde as dde
from deepxde.backend import tf
import matplotlib.pyplot as plt
c = 10 # wave equation constant
C = 1 # Fourier constant
n = 1
m = 1
# dimensions
a = 1
b = 1
def pde(x, u):
u_tt = dde.grad.hessian(u, x, i=2, j=2)
u_xx = dde.grad.hessian(u, x, i=0, j=0)
u_yy = dde.grad.hessian(u, x, i=1, j=1)
return u_tt - ((c ** 2) * (u_xx + u_yy))
def sol(x):
return (
C
* np.sin(m * np.pi * x[:, 0:1] / a)
* np.sin(n * np.pi * x[:, 1:2] / b)
* np.cos(np.sqrt(2) * np.pi * c * x[:, 2:3]) # (m^2/a^2 + n^2/b^2) = 2
)
def boundary_init(x, _):
return np.isclose(x[-1], 0)
def get_initial_loss(model):
model.compile("adam", lr=0.001, metrics=["l2 relative error"])
losshistory, _ = model.train(0)
return losshistory.loss_train[0]
spatial_domain = dde.geometry.Rectangle(xmin=[0, 0], xmax=[a, b])
temporal_domain = dde.geometry.TimeDomain(0, 1)
spatio_temporal_domain = dde.geometry.GeometryXTime(spatial_domain, temporal_domain)
d_bc = dde.DirichletBC(
spatio_temporal_domain, lambda x: 0, lambda _, on_boundary: on_boundary
)
ic = dde.IC(
spatio_temporal_domain,
lambda x: np.sin(np.pi * x[:, 0:1]) * np.sin(np.pi * x[:, 1:2]),
lambda _, on_initial: on_initial,
)
ic_2 = dde.OperatorBC(
spatio_temporal_domain,
lambda x, u, _: dde.grad.jacobian(u, x, i=0, j=1),
boundary_init,
)
data = dde.data.TimePDE(
spatio_temporal_domain,
pde,
[d_bc, ic, ic_2],
num_domain=360,
num_boundary=360,
num_initial=360,
num_test=10000,
solution=sol,
)
net = dde.nn.STMsFFN(
[3] + [100] * 3
# + [300] * 2 + [100] * 2
+ [1],
"tanh",
"Glorot uniform",
# sigmas_x=[100, 250, 500, 1000, 1250],
# sigmas_t=[100, 250, 500, 1000, 1250, 1500, 2500],
sigmas_x=[100, 150, 200, 250, 500,],
sigmas_t=[100, 150, 200, 250, 500, 750, 1000],
)
net.apply_feature_transform(lambda x: x / 250)
model = dde.Model(data, net)
initial_losses = get_initial_loss(model)
loss_weights = 1 / (2 * initial_losses)
model.compile(
"adam",
lr=0.001,
metrics=["l2 relative error"],
# decay=("inverse time", 5000, 0.9),
decay=("inverse time", 10000, 0.9),
loss_weights=loss_weights,
)
pde_residual_resampler = dde.callbacks.PDEResidualResampler(period=1)
losshistory, train_state = model.train(epochs=20000, callbacks=[pde_residual_resampler], display_every=500)
dde.saveplot(
losshistory,
train_state,
issave=True,
isplot=True,
test_fname="../dat_data/wave_2D.dat",
)
|
The loss seems still large. You have only trained for 20000 steps. Have you tried the similar PDE but for a simpler solution (smoother)? |
Is it possible to use STMsFFN without an exact solution? |
Yes, the same usage as other networks. |
@Saransh-cpp Hey, just wanted to add here. Incase any else faces this issue!
It should be I was using operatorBC as used above, and spent almost 2 days and 100 experiments, to get stupid results. Since, this is a 2D case, your input vector would be [X,Y,T]. |
Greetings,
I have been trying to use the
Spatio Temporal Multi-scale Fourier feature networks
on the 2-dimensional wave equation, but the network performs poorly and is not able to pick up high-frequency details.Plots
Losses and metric
Plot 1 (y, u, and t)
Plot 2 (x, u, and t)
Code
Output
I have tried varying every hyperparameter but I can't get the network to learn the solution accurately. Could someone please help me with this?
Thank you!
The text was updated successfully, but these errors were encountered: