Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
net = dde.maps.FNN(layer_size, activation, initializer)
model = dde.Model(data, net)
model.compile("adam", lr=0.001, metrics=["l2 relative error"])
checkpointer = dde.callbacks.ModelCheckpoint(
"./model/model.ckpt", verbose=1, save_better_only=True
)
movie = dde.callbacks.MovieDumper(
"model/movie", [-1], [1], period=100, save_spectrum=True, y_reference=func
)
losshistory, train_state = model.train(
epochs=10000, callbacks=[checkpointer, movie]
)
dde.saveplot(losshistory, train_state, issave=True, isplot=True)
# Plot PDE residue
x = geom.uniform_points(1000, True)
y = model.predict(x, operator=pde)
plt.figure()
plt.plot(x, y)
plt.xlabel("x")
plt.ylabel("PDE residue")
plt.show()
func=func,
num_test=10000,
)
layer_size = [2] + [32] * 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"])
variable = dde.callbacks.VariableValue(C, period=1000)
losshistory, train_state = model.train(epochs=50000, callbacks=[variable])
dde.saveplot(losshistory, train_state, issave=True, isplot=True)
return np.zeros([len(x), 1])
geom = dde.geometry.Polygon([[0, 0], [1, 0], [1, -1], [-1, -1], [-1, 1], [0, 1]])
bc = dde.DirichletBC(geom, func, boundary)
data = dde.data.PDE(
geom, 1, pde, bc, num_domain=1200, num_boundary=120, num_test=1500
)
net = dde.maps.FNN([2] + [50] * 4 + [1], "tanh", "Glorot uniform")
model = dde.Model(data, net)
model.compile("adam", lr=0.001)
model.train(epochs=50000)
model.compile("L-BFGS-B")
losshistory, train_state = model.train()
dde.saveplot(losshistory, train_state, issave=True, isplot=True)
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)
return x * np.sin(5 * x)
geom = dde.geometry.Interval(-1, 1)
num_train = 16
num_test = 100
data = dde.data.Func(geom, func, num_train, num_test)
activation = "tanh"
initializer = "Glorot uniform"
net = dde.maps.FNN([1] + [20] * 3 + [1], 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)
activation = "tanh"
initializer = "Glorot uniform"
regularization = ["l2", 0.01]
net = dde.maps.MfNN(
[1] + [20] * 4 + [1],
[10] * 2 + [1],
activation,
initializer,
regularization=regularization,
)
model = dde.Model(data, net)
model.compile("adam", lr=0.001, metrics=["l2 relative error"])
losshistory, train_state = model.train(epochs=80000)
dde.saveplot(losshistory, train_state, issave=True, isplot=True)
)
layer_size = [2] + [32] * 3 + [1]
activation = "tanh"
initializer = "Glorot uniform"
net = dde.maps.FNN(layer_size, activation, initializer)
net.outputs_modify(
lambda x, y: x[:, 1:2] * (1 - x[:, 0:1] ** 2) * y + tf.sin(np.pi * x[:, 0:1])
)
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)