Replies: 5 comments 5 replies
-
Why 1 / 2.0 * tf.abs(dy_x) ** 2 - f * y |
Beta Was this translation helpful? Give feedback.
-
The loss should not be "MAE". It should be just the mean, as in Eq. 8, there is no abs for g. |
Beta Was this translation helpful? Give feedback.
-
Current version (still not working). I'll edit it as soon as I understand what is wrong here. """Backend supported: tensorflow.compat.v1, tensorflow, pytorch, paddle"""
import deepxde as dde
import matplotlib.pyplot as plt
import numpy as np
from deepxde.backend import tf
def custom_loss(y_true, y_pred):
return tf.reduce_mean(y_true - y_pred)
def pde(x, y):
dy_x = dde.grad.jacobian(y, x)
f = np.pi ** 2 * tf.sin(np.pi * x)
return 1/2. * dy_x ** 2 - f * y
def boundary(x, on_boundary):
return on_boundary
def func(x):
return np.sin(np.pi * x)
geom = dde.geometry.Interval(-1, 1)
bc = dde.icbc.DirichletBC(geom, func, boundary)
data = dde.data.PDE(geom, pde, bc, 16, 2, solution=func, num_test=100)
layer_size = [1] + [50] * 3 + [1]
activation = "tanh"
initializer = "Glorot uniform"
net = dde.nn.FNN(layer_size, activation, initializer)
model = dde.Model(data, net)
model.compile("adam", lr=0.001, metrics=["l2 relative error"], loss = [custom_loss, "MSE"])
losshistory, train_state = model.train(epochs=5000)
dde.saveplot(losshistory, train_state, issave=False, isplot=True)
x = geom.uniform_points(1000, True)
y = model.predict(x, operator=pde)
plt.figure()
plt.plot(x, y)
plt.xlabel("x")
plt.ylabel("PDE residual")
plt.show() |
Beta Was this translation helpful? Give feedback.
-
You may need more points than 16? |
Beta Was this translation helpful? Give feedback.
-
Dear @pescap , |
Beta Was this translation helpful? Give feedback.
-
Dear all,
I was trying to add a simple example using DRM, in order to compare the results with PINNs.
For example, refer to Eqs. (3) and (4) in Sobolev Acceleration and Statistical Optimality for
Learning Elliptic Equations via Gradient Descent
So far, I couldn't obtain convergence for the DRM.
My code, inspired by: this 1D example.
Changes: The loss in
DRMpde
, and the usage of"MAE"
loss.Beta Was this translation helpful? Give feedback.
All reactions