Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
dy_xx = tf.gradients(dy_x, x)[0]
return -dy_xx - np.pi ** 2 * tf.sin(np.pi * x)
def boundary_l(x, on_boundary):
return on_boundary and np.isclose(x[0], -1)
def boundary_r(x, on_boundary):
return on_boundary and np.isclose(x[0], 1)
def func(x):
return np.sin(np.pi * x)
geom = dde.geometry.Interval(-1, 1)
bc1 = dde.DirichletBC(geom, func, boundary_l)
bc2 = dde.PeriodicBC(geom, 0, boundary_r)
data = dde.data.PDE(geom, 1, pde, [bc1, bc2], 16, 2, func=func, num_test=100)
layer_size = [1] + [50] * 3 + [1]
activation = "tanh"
initializer = "Glorot uniform"
net = dde.maps.FNN(layer_size, activation, initializer)
model = dde.Model(data, net)
model.compile("adam", lr=0.001, metrics=["l2 relative error"])
losshistory, train_state = model.train(epochs=10000)
dde.saveplot(losshistory, train_state, issave=True, isplot=True)
return [dy1_x - y2, dy2_x + y1]
def boundary(x, on_boundary):
return on_boundary and np.isclose(x[0], 0)
def func(x):
"""
y1 = sin(x)
y2 = cos(x)
"""
return np.hstack((np.sin(x), np.cos(x)))
geom = dde.geometry.Interval(0, 10)
bc1 = dde.DirichletBC(geom, np.sin, boundary, component=0)
bc2 = dde.DirichletBC(geom, np.cos, boundary, component=1)
data = dde.data.PDE(geom, 2, ode_system, [bc1, bc2], 35, 2, func=func, num_test=100)
layer_size = [1] + [50] * 3 + [2]
activation = "tanh"
initializer = "Glorot uniform"
net = dde.maps.FNN(layer_size, activation, initializer)
model = dde.Model(data, net)
model.compile("adam", lr=0.001, metrics=["l2 relative error"])
losshistory, train_state = model.train(epochs=20000)
dde.saveplot(losshistory, train_state, issave=True, isplot=True)