I am a beginner in this area. I am trying to modify the 'ode_system.py' to solve an ODE that describes a simple pendulum movement. I always got very large test metrics and it changed very slowly. Shall I need to add something or change the hyperparameter of the FNN?
The following is my codes, hope you can give me some advice to improve it. Thank you in advance!
import deepxde as dde
import numpy as np
import tensorflow as tf
Hi, Lulu!
I am a beginner in this area. I am trying to modify the 'ode_system.py' to solve an ODE that describes a simple pendulum movement. I always got very large test metrics and it changed very slowly. Shall I need to add something or change the hyperparameter of the FNN?
The following is my codes, hope you can give me some advice to improve it. Thank you in advance!
import deepxde as dde import numpy as np import tensorflow as tf
def ode_system(t, theta): """ODE theta''(t) = -g*sin(theta(t))/L """
dtheta1_dt = dde.grad.jacobian(theta, t, i=0) dtheta2_dt = dde.grad.jacobian(dtheta1_dt, t, i=0) return [dtheta2_dt + tf.sin(theta)]
def boundary(_, on_initial): return on_initial
def func(t): """ theta = cos(t) """ return np.cos(t)
geom = dde.geometry.TimeDomain(0, 10) ic1 = dde.IC(geom, np.cos, boundary, component=0) data = dde.data.PDE(geom, ode_system, [ic1], 30, 1, solution=func, num_test=50) #
layer_size = [1] + [30] * 3 + [1] activation = "sigmoid" initializer = "Glorot uniform" net = dde.maps.FNN(layer_size, activation, initializer)
model = dde.Model(data, net) model.compile("adam", lr=0.1, metrics=["l2 relative error"]) losshistory, train_state = model.train(epochs=20000)
dde.saveplot(losshistory, train_state, issave=False, isplot=True)