You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def rad_resampler(model, geomtime, num_resample, k=1, c=1):
"""
Resample residual points based on the Residual-based Adaptive Distribution (RAD) method.
"""
# Generate a dense set of candidate points
candidate_points = geomtime.random_points(10 * num_resample)
# Evaluate the PDE residual at candidate points
candidate_points_tensor = paddle.to_tensor(candidate_points, dtype='float32')
y_pred = model.predict(candidate_points_tensor)
residuals = pde(candidate_points_tensor, y_pred)
# Compute the probability density function (PDF) based on residuals
residuals = np.abs(residuals)
pdf = residuals ** k / (np.mean(residuals ** k) + c)
pdf /= np.sum(pdf)
# Sample new residual points based on the PDF
indices = np.random.choice(len(candidate_points), size=num_resample, p=pdf)
new_rps = candidate_points[indices]
return new_rps
Backend tkagg is interactive backend. Turning interactive mode on.
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.1\plugins\python-ce\helpers\pydev\pydevd.py", line 1570, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.1\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "E:\deepxde-study\1dproblems\1dxdeburgers-rad.py", line 88, in
new_resample_points = rad_resampler(model, geomtime, num_resample=2500, k=1, c=1)
File "E:\deepxde-study\1dproblems\1dxdeburgers-rad.py", line 33, in rad_resampler
residuals = pde(candidate_points_tensor, y_pred)
File "E:\deepxde-study\1dproblems\1dxdeburgers-rad.py", line 16, in pde
dy_x = dde.grad.jacobian(y, x, i=0, j=0)
File "E:\deepxde-study\1dproblems\venv\lib\site-packages\deepxde\gradients\gradients.py", line 34, in jacobian
return gradients_reverse.jacobian(ys, xs, i=i, j=j)
File "E:\deepxde-study\1dproblems\venv\lib\site-packages\deepxde\gradients\gradients_reverse.py", line 73, in jacobian
return jacobian._Jacobians(ys, xs, i=i, j=j)
File "E:\deepxde-study\1dproblems\venv\lib\site-packages\deepxde\gradients\jacobian.py", line 126, in call
if key not in self.Js:
TypeError: unhashable type: 'numpy.ndarray'
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
冒昧求教,我现在想迭代若干次后,重新采样。在原始代码中添加了等号之间的部分:
geom = dde.geometry.Interval(-1, 1)
timedomain = dde.geometry.TimeDomain(0, 0.99)
geomtime = dde.geometry.GeometryXTime(geom, timedomain)
bc = dde.icbc.DirichletBC(geomtime, lambda x: 0, lambda _, on_boundary: on_boundary)
ic = dde.icbc.IC(geomtime, lambda x: -np.sin(np.pi * x[:, 0:1]), lambda _, on_initial: on_initial)
data = dde.data.TimePDE(geomtime, pde, [bc, ic], num_domain=2500, num_boundary=100, num_initial=160)
net = dde.nn.FNN([2] + [20] * 3 + [1], "tanh", "Glorot normal")
model = dde.Model(data, net)
model.compile("adam", lr=1.0e-3)
np.savetxt("training_points.dat", data.train_x_all)
model.train(iterations=1000)
#===============================================================================
new_resample_points = rad_resampler(model, geomtime, num_resample=2500, k=1, c=1)
data.replace_with_anchors(new_resample_points)
np.savetxt("training_points.dat", data.train_x_all)
#================================================================================
model.compile("L-BFGS")
losshistory, train_state = model.train()
其中rad_resampler的定义如下:
def rad_resampler(model, geomtime, num_resample, k=1, c=1):
"""
Resample residual points based on the Residual-based Adaptive Distribution (RAD) method.
"""
# Generate a dense set of candidate points
candidate_points = geomtime.random_points(10 * num_resample)
#-------------------------------------------------------------------------------------------------
运行报错如下信息
Backend tkagg is interactive backend. Turning interactive mode on.
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.1\plugins\python-ce\helpers\pydev\pydevd.py", line 1570, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2023.1\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "E:\deepxde-study\1dproblems\1dxdeburgers-rad.py", line 88, in
new_resample_points = rad_resampler(model, geomtime, num_resample=2500, k=1, c=1)
File "E:\deepxde-study\1dproblems\1dxdeburgers-rad.py", line 33, in rad_resampler
residuals = pde(candidate_points_tensor, y_pred)
File "E:\deepxde-study\1dproblems\1dxdeburgers-rad.py", line 16, in pde
dy_x = dde.grad.jacobian(y, x, i=0, j=0)
File "E:\deepxde-study\1dproblems\venv\lib\site-packages\deepxde\gradients\gradients.py", line 34, in jacobian
return gradients_reverse.jacobian(ys, xs, i=i, j=j)
File "E:\deepxde-study\1dproblems\venv\lib\site-packages\deepxde\gradients\gradients_reverse.py", line 73, in jacobian
return jacobian._Jacobians(ys, xs, i=i, j=j)
File "E:\deepxde-study\1dproblems\venv\lib\site-packages\deepxde\gradients\jacobian.py", line 126, in call
if key not in self.Js:
TypeError: unhashable type: 'numpy.ndarray'
冒昧求教,问题出在哪里?谢谢!
Beta Was this translation helpful? Give feedback.
All reactions