PINN model with exogeneous inputs (parameters) simulated at varyed initial conditions #2006
Unanswered
John-Silva-29
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I am trying to simulate a ode system that has a parameter. Moreover, i want to fit a PINN that fits the model at different initial conditions. The final goal is to use in a process control framework. But i am getting errors related to data diensions. Below is the code and the error. Can someone help me please?
import torch as torch
import os
os.environ["DDE_BACKEND"] = "pytorch" # Set backend to PyTorch
import deepxde as dde #type: ignore
import numpy as np
-----------------------------
1. Define the ODE system
-----------------------------
def ode_system(inputs, y):
t = inputs[:, 0:1]
mu = inputs[:, 1:2]
y1_0 = inputs[:, 2:3]
y2_0 = inputs[:, 3:4]
-----------------------------
2. Geometry [t, mu, y1_0, y2_0]
-----------------------------
geom = dde.geometry.Rectangle(
[0.0, 0.1, 0.5, -1.0],
[10.0, 1.0, 2.0, 1.0]
)
-----------------------------
3. Unified initial condition residuals
-----------------------------
def ic_residuals(inputs, outputs):
r1 = outputs[:, 0:1] - inputs[:, 2:3] # y1 - y1_0
r2 = outputs[:, 1:2] - inputs[:, 3:4] # y2 - y2_0
print(r1.size)
print(r2.size)
return r1, r2
-----------------------------
4. Boundary condition: only where t=0
-----------------------------
def boundary(x, on_boundary):
return on_boundary and np.isclose(x[0], 0.0)
bc1 = dde.icbc.OperatorBC(
geom,
lambda x, y, _: ic_residuals(x, y)[0],
boundary,
)
bc2 = dde.icbc.OperatorBC(
geom,
lambda x, y, _: ic_residuals(x, y)[1],
boundary,
)
-----------------------------
5. Data
-----------------------------
data = dde.data.PDE(
geom,
ode_system,
[bc1, bc2],
num_domain=500,
num_boundary=50,
num_test=100
)
-----------------------------
6. Network
-----------------------------
net = dde.nn.FNN([4] + [64] * 3 + [2], "tanh", "Glorot normal")
-----------------------------
7. Model
-----------------------------
model = dde.Model(data, net)
model.compile("adam", lr=0.001)
model.train(iterations=5000)
Traceback (most recent call last):
File "C:\Users\jonil\Desktop\PINN\deepxde-master\deepxde-master\examples\pinn_forward\ex1.py", line 66, in
data = dde.data.PDE(
^^^^^^^^^^^^^
File "C:\Users\jonil\Desktop\PINN\venv_dde\Lib\site-packages\deepxde\data\pde.py", line 135, in init
self.train_next_batch()
File "C:\Users\jonil\Desktop\PINN\venv_dde\Lib\site-packages\deepxde\utils\internal.py", line 39, in wrapper
return func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\jonil\Desktop\PINN\venv_dde\Lib\site-packages\deepxde\data\pde.py", line 199, in train_next_batch
self.train_x_all = self.train_points()
^^^^^^^^^^^^^^^^^^^
File "C:\Users\jonil\Desktop\PINN\venv_dde\Lib\site-packages\deepxde\utils\internal.py", line 39, in wrapper
return func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\jonil\Desktop\PINN\venv_dde\Lib\site-packages\deepxde\data\pde.py", line 298, in train_points
X = np.vstack((tmp, X))
^^^^^^^^^^^^^^^^^^^
File "C:\Users\jonil\Desktop\PINN\venv_dde\Lib\site-packages\numpy\core\shape_base.py", line 289, in vstack
return _nx.concatenate(arrs, 0, dtype=dtype, casting=casting)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: all the input array dimensions except for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 2 and the array at index 1 has size 4
Beta Was this translation helpful? Give feedback.
All reactions