lu-group / mionet Goto Github PK
View Code? Open in Web Editor NEWMIONet: Learning multiple-input operators via tensor product
License: Apache License 2.0
MIONet: Learning multiple-input operators via tensor product
License: Apache License 2.0
Hi @lululxvi , @ShuaiMeng0601 and @jpzxshi.
Thank you for such a great work. I was looking for a version of PINN model and went through your multiple articles and decided to use MIONet since I need to use more than one 'u'. I could generate the data and train the model and save it in my local repository. I could also successfully restore the saved model.
At this stage, I am trying to predict with the test data that was generated in the step 1 using the restored model.
However, I am facing issue with using this model with new data. I looked at the FAQ of DeepXDE and issues in DeepONet and could not find the fix/solution.
Please find the code and the error below. Looking forward for your reply.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import itertools
import numpy as np
from deepxde.backend import tf
import os
from scipy.integrate import solve_ivp
import deepxde as dde
from spaces import FinitePowerSeries, FiniteChebyshev, GRF
from utils import merge_values, trim_to_65535, mean_squared_error_outlier, safe_test
from deepxde.nn.tensorflow_compat_v1.mionet import MIONetCartesianProd
from deepxde.data.quadruple import QuadrupleCartesianProd
def int_index(x, t, T):
mat = np.linspace(0, T, x)
return int(t / mat[1])
def ode(m, T, sensor_values1, sensor_values2):
"""ODE system"""
s0 = [0, 0] # initial condition
def model(t, s):
k = 1
u1 = lambda t: sensor_values1[t]
u2 = lambda t: sensor_values2[t]
return [
s[1] + u1(int_index(m, t, T)),
-k * np.sin(s[0]) + u2(int_index(m, t, T)),
]
res = solve_ivp(model, [0, T], s0, method="RK45", t_eval=np.linspace(0, T, m), vectorized = True)
return res.y[0, :], res.y[1, :]
def network(problem, m):
if problem == "ODE":
branch = [m, 200, 200]
trunk = [1, 200, 200]
elif problem == "DR":
branch = [m, 200, 200]
trunk = [2, 200, 200]
elif problem == "ADVD":
branch = [m, 300, 300, 300]
trunk = [2, 300, 300, 300]
return branch, trunk
problem = "ODE"
T = 1
m = 100
lr = 0.0002 if problem in ["ADVD"] else 0.001
epochs = 100000
activation = (
["relu", None, "relu"] if problem in ["ADVD"] else ["relu", "relu", "relu"]
)
initializer = "Glorot normal"
training_data = np.load("../data/" + problem + "_train_1.npz", allow_pickle=True)
testing_data = np.load("../data/" + problem + "_test_1.npz", allow_pickle=True)
X_train = training_data["X_train"]
y_train = training_data["y_train"]
X_test = testing_data["X_test"]
y_test = testing_data["y_test"]
branch_net, trunk_net = network(problem, m)
data = QuadrupleCartesianProd(X_train, y_train, X_test, y_test)
net = MIONetCartesianProd(
branch_net,
branch_net,
trunk_net,
{"branch1": activation[0], "branch2": activation[1], "trunk": activation[2]},
initializer,
regularization=None,
)
model = dde.Model(data, net)
model.compile("adam", lr=lr)
checker = dde.callbacks.ModelCheckpoint(
"model/mionet_model", save_better_only=True, period=1000
)
model.restore(os.path.normpath("model/mionet_model-96000.ckpt"), verbose=1)
model.predict(X_test)
I get the below error when I predict with the X_test which was the same data that was used while training the model.
print(
"# Parameters:",
np.sum(
[
np.prod(v.get_shape().as_list())
for v in tf.compat.v1.trainable_variables()
]
)
If I use pytorch as backend, how can I modify this part of code to calculate parameters
Hi,
I noted that in your code, it is suitable for 2 input situations, if I want to extend it to 3D or even more situations.
Which part of your code should I modify?
Regards,
Peng
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.