lululxvi / deepxde

A library for scientific machine learning and physics-informed learning
https://deepxde.readthedocs.io
GNU Lesser General Public License v2.1
2.64k stars 739 forks source link

ODE for Simple Pendulum movement #384

Closed kdand35 closed 2 years ago

kdand35 commented 3 years ago

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)

image

lululxvi commented 3 years ago

Try TimeDomain(0, 1) first