How do I understand the component, and how to set its value? #859
-
Dear Lu Lu, How do I understand the component, and how to set its value? Take the following code as an example.
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Thank you very much for your help. My problem is described as followsWe will solve a simple ODE system: with the initial conditions The reference solution is here, where the parameters My code can't predict the parameters correctly. I would like to ask where is the problem.import deepxde as dde
import numpy as np
import torch
C1 = dde.Variable(50.0) # g_Na
C2 = dde.Variable(50.0) # g_K
C3 = dde.Variable(1.0) # g_L
# Most backends
def HH(t, y):
V, m, h, n= y[:, 0:1], y[:, 1:2], y[:, 2:3], y[:, 3:4]
dy1_x = dde.grad.jacobian(y, t, i=0)
dy2_x = dde.grad.jacobian(y, t, i=1)
dy3_x = dde.grad.jacobian(y, t, i=2)
dy4_x = dde.grad.jacobian(y, t, i=3)
def I_inj(t):
return 10*(t>10) - 10*(t>20) + 35*(t>30) - 35*(t>40)
def alpha_m(V):
return 0.1*(V+40.0)/(1.0 - torch.exp(-(V+40.0) / 10.0))
def beta_m(V):
return 4.0*torch.exp(-(V+65.0) / 18.0)
def alpha_h(V):
return 0.07*torch.exp(-(V+65.0) / 20.0)
def beta_h(V):
return 1.0/(1.0 + torch.exp(-(V+35.0) / 10.0))
def alpha_n(V):
return 0.01*(V+55.0)/(1.0 - torch.exp(-(V+55.0) / 10.0))
def beta_n(V):
return 0.125*torch.exp(-(V+65) / 80.0)
return [
dy1_x - I_inj(t) - C1 * m**3 * h * (V - 50) - C2 * n**4 * (V + 77.0) - C3 * (V + 54.387),
dy2_x - alpha_m(V)*(1.0-m) - beta_m(V)*m,
dy3_x - alpha_h(V)*(1.0-h) - beta_h(V)*h,
dy4_x - alpha_n(V)*(1.0-n) - beta_n(V)*n,
]
def boundary(_, on_initial):
return on_initial
geom = dde.geometry.TimeDomain(0, 20)
# Initial conditions -65, 0.05, 0.6, 0.32
ic1 = dde.icbc.IC(geom, lambda X: -65, boundary, component=0) # 数据的初始数值
ic2 = dde.icbc.IC(geom, lambda X: .05, boundary, component=0)
ic3 = dde.icbc.IC(geom, lambda X: .6, boundary, component=0)
ic4 = dde.icbc.IC(geom, lambda X: .32, boundary, component=0)
# 使用仿真的数据 the train data
observe_t = np.expand_dims(observe_t,axis=1) # 扩充纬度
observe_y0 = dde.icbc.PointSetBC(observe_t, ob_y[:, 0:1], component=0)
observe_y1 = dde.icbc.PointSetBC(observe_t, ob_y[:, 1:2], component=0)
observe_y2 = dde.icbc.PointSetBC(observe_t, ob_y[:, 2:3], component=0)
observe_y3 = dde.icbc.PointSetBC(observe_t, ob_y[:, 3:4], component=0)
data = dde.data.PDE(
geom,
HH,
[ic1, ic2,ic3,ic4, observe_y0, observe_y1, observe_y2, observe_y3],
num_domain=4000,
num_boundary=6,
anchors=observe_t,
)
net = dde.nn.FNN([1] + [32] * 3 + [4], "sin", "Glorot uniform")
model = dde.Model(data, net)
epochs = 60000
vari_save_filename="fhn_variables_datasize_{}_epochs_{}.dat".format(ob_y.shape[0],epochs)
model.compile("adam", lr=0.00001, external_trainable_variables=[C1, C2, C3])
variable = dde.callbacks.VariableValue(
[C1, C2, C3], filename=vari_save_filename
)
losshistory, train_state = model.train(iterations=epochs, callbacks=[variable])
print(variable.get_value())
# dde.saveplot(losshistory, train_state, issave=True, isplot=True) My complete code is in this link https://gitee.com/squarefaceyao/pinn_inverse_pes/blob/master/Simulation_HH.ipynb |
Beta Was this translation helpful? Give feedback.
-
See the ODE system example at https://deepxde.readthedocs.io/en/latest/demos/pinn_inverse.html |
Beta Was this translation helpful? Give feedback.
See