I have been trying to learn this project. When I was reproducing the solution to the Lotka-Volterra equations, the generated graph showed that the data no longer matched at all after one cycle. Could you please tell me the reason for this? Below is the code I entered according to the study document. #2036
-
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
|
`"""Backend supported: tensorflow.compat.v1, tensorflow, pytorch, paddle, jax""" Import tf if using backend tensorflow.compat.v1 or tensorflowfrom deepxde.backend import tf Import torch if using backend pytorchimport torchImport paddle if using backend paddleimport paddleImport jax.numpy if using backend jaximport jax.numpy as jnpub = 200 def func(t, r): def gen_truedata(): def ode_system(x, y): geom = dde.geometry.TimeDomain(0, 1.0) layer_size = [1] + [64] * 6 + [2] Backend tensorflow.compat.v1 or tensorflowdef input_transform(t): Backend pytorchdef input_transform(t):return torch.cat([torch.sin(t),],dim=1,)Backend paddledef input_transform(t):return paddle.concat((paddle.sin(t),),axis=1,)Backend jaxdef input_transform(t):if t.ndim == 1:t = t[None]return jnp.concatenate([jnp.sin(t),],axis=1)hard constraints: x(0) = 100, y(0) = 15Backend tensorflow.compat.v1 or tensorflowdef output_transform(t, y): Backend pytorchdef output_transform(t, y):y1 = y[:, 0:1]y2 = y[:, 1:2]return torch.cat([y1 * torch.tanh(t) + 100 / ub, y2 * torch.tanh(t) + 15 / ub], dim=1)Backend paddledef output_transform(t, y):y1 = y[:, 0:1]y2 = y[:, 1:2]return paddle.concat([y1 * paddle.tanh(t) + 100 / ub, y2 * paddle.tanh(t) + 15 / ub], axis=1)Backend jaxdef output_transform(t, y):y1 = y[:, 0:1]y2 = y[:, 1:2]return jnp.concatenate([y1 * jnp.tanh(t) + 100 / ub, y2 * jnp.tanh(t) + 15 / ub],axis=1).squeeze()net.apply_feature_transform(input_transform) model.compile("adam", lr=0.001) Most backends except jax can have a second fine tuning of the solutionmodel.compile("L-BFGS") plt.xlabel("t") t = np.linspace(0, 1, 100) t = t.reshape(100, 1) plt.plot(t, x_pred, color="red", linestyle="dashed", label="x_pred") |
Beta Was this translation helpful? Give feedback.
-
|
新建 文本文档 (2).txt |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.

L-BFGS isn't working properly with Tensorflow backend. Try Pytorch: