-
Notifications
You must be signed in to change notification settings - Fork 762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question on Learning Function from Formula #1816
Comments
For two inputs you can use a 2D geometry such as a rectangle. geom = dde.geometry.Rectangle([0, 0], [1, 1]) |
Yes, I tried using 2D Geometry and changed the net to 2 input nodes. It now looks like: geom = dde.geometry.Rectangle([-1, -1], [1, 1]) activation = "tanh" model = dde.Model(data, net) dde.saveplot(losshistory, train_state, issave=True, isplot=True) But it gives an error: TypeError: func() missing 1 required positional argument: 'y'. (in function.py) If I changed the function to an array: return np.sin(x[:,0]) + x[:,1]^2), it gives another error: Any idea on how to solve this? Or how can I define the function with >1 variables? Thank you very much! |
Try this. def func(x):
return np.sin(x[:,0]) + x[:,1]**2
geom = dde.geometry.Rectangle([-1, -1], [1, 1])
num_train = 16
num_test = 100
data = dde.data.Function(geom, func, num_train, num_test)
activation = "tanh"
initializer = "Glorot uniform"
net = dde.nn.FNN([2] + [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(iterations=10000)
dde.saveplot(losshistory, train_state, issave=True, isplot=True) You will still get an error when using |
Yeah, I tried that as well, it gives an Exception error: ValueError: Cannot feed value of shape (16,) for Tensor Placeholder_3:0, which has shape (None, 1) The complete error messages look like below: The error happens in model.train, so I think this is not due to dde.saveplot |
I see. Then it's probably a backend problem. I'm using tensorflow backend. I'll try checking for compatibility again. Thank you very much! |
@praksharma @LHLevin Have you found what the bug is? |
@lululxvi I did not continue to find the reason why it doesn't work with tensorflow. I changed my backend to pytorch as @praksharma suggested and it works. |
Hi Dr. Lu,
I'm trying to understand how the "Learning a function from a formula" works. From the docs, an example with an unknown is given. If I have a formula of more than one unknown, for instance: f(x,y) = sin(x) + y^2, how do I introduce another unknown to be learned?
Thank you in advance for any reply.
The text was updated successfully, but these errors were encountered: