Model doesnot converge even after trying everything #1738
Closed
Luv-crypto
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I am trying to solve this pde
with Drichlet boundary conditions for a rectangular domain from -1 to +1. but even after trying different combinations of network architectures i.e deeper and wider networks, different NNs such as FNN, ResNets and different combinations of optimizers and different distributions of points I cannot get the model to predict better. Can someone help me below is the code
import deepxde as dde
import numpy as np
import tensorflow as tf
def pde(x, y):
""" Function to compute PDE residual """
dy_xx = dde.grad.hessian(y, x, component=0, i=0, j=0)
dy_yy = dde.grad.hessian(y, x, component=0, i=1, j=1)
# The source term S, using TensorFlow operations
S = -(2 + tf.square(np.pi) * x[:, 0:1] * (1 - x[:, 0:1])) * tf.cos(tf.constant(np.pi) * x[:, 1:2])
return dy_xx + dy_yy - S
Define the computational domain
geom = dde.geometry.Rectangle([-1, -1], [1, 1])
Define hard enforcement for the boundary conditions using output transformation
def output_transform(x, output):
""" Custom output transformation function for enforcing hard boundary conditions. """
# Extract x and y coordinates
x_coord = x[:, 0:1] # x coordinate
y_coord = x[:, 1:2] # y coordinate
def func(x):
return x[:,0:1]*(1-x[:,0:1])np.cos(np.pix[:,1:])
data = dde.data.PDE(geom, pde, [], num_domain=20000, num_boundary=1000 , solution= func , num_test=2000) # No explicit boundary conditions are passed here
!# net = dde.maps.ResNet(input_size=2, output_size=1, num_neurons=50, num_blocks=num_res_blocks, activation=activation, kernel_initializer=kernel_initializer)
net = dde.maps.FNN([2] + [100]*10 + [1], "tanh", "Glorot normal")
Apply the output transformation to the neural network
net.apply_output_transform(output_transform)
Combine the PDE and the boundary conditions
!# resampler = dde.callbacks.PDEPointResampler(period=10)
Model
model = dde.Model(data, net)
Train the model
model.compile("adam", lr=1e-3, metrics=["l2 relative error"])
model.train(iterations=8000)
model.compile("L-BFGS-B", metrics=["l2 relative error"])
losshistory, train_state = model.train()
Plotting the results
dde.saveplot(losshistory, train_state, issave=True, isplot=True)
Here the what the solution should look like. The exact solution is x*(1-x)cos(piy)
Beta Was this translation helpful? Give feedback.
All reactions