deepxde icon indicating copy to clipboard operation
deepxde copied to clipboard

ODE Inverse problem : Wrong inferred value of parameter , very big and unbalanced loss

Open khaoulaoue opened this issue 2 years ago • 4 comments

Hi @lululxvi,

Thank you for your wonderful framework and documentation!

I have a question on the use of DeepXDE for the inverse problem and after consulting many of the FAQs and examples , I am stuck and I don´t know how to fix the problem. have an ODE equation :

def Emsley_system(t, DP):

global A

k=A*(tf.math.exp(-E / (R * (T+273))))

dy_x = dde.grad.jacobian(DP, t, i=0)

return [

    dy_x + k * (DP**2),

]

and I am trying the infer the value of A. The true value of A is 7.8*(108) and the time domain according to the data that I have is between 1 and 2000 days and DP value range from 1000 to 200. I tried with DeepXDE and used the inverse ODE demo as a basis but the value of A is always wrong and in the order of 10-2 , I tried with many hyperparameters and I tried to include 108 in the expression of the ODE and scale the time domain between 0 and 5 but still I have MSE in the range of 104 and wrong A value. I don´t understand why it´s not working even though it´s a quite simple equation. this is the code :

import tensorflow as tf import os import numpy as np import pandas as pd def gen_traindata(): DP_train = pd.read_csv( "/content/DATA.csv", delimiter=';') DP_train.columns=['time','DP'] t = (DP_train['time'].values) DP = (DP_train['DP'].values) t = t.astype('int32') DP=DP.astype('float32') t=t.reshape(len(t),1) DP=DP.reshape(len(DP),1) t=t/365

 return t, DP

A = dde.Variable(1.0) E=111*(10**3) T=98 R=8.314

def Emsley_system(t, DP): global A k=A*108(tf.math.exp(-E / (R * (T+273)))) dy_x = dde.grad.jacobian(DP, t, i=0) return [ dy_x + k * (DP2), ] def boundary(_, on_initial): return on_initial

geom = dde.geometry.TimeDomain(0,6)

ic1 = dde.icbc.IC(geom, lambda X: 1000, boundary, component=0)

observe_y0 = dde.icbc.PointSetBC(t_train, y_train, component=0)

data = dde.data.PDE( geom, Emsley_system, [ic1, observe_y0], num_domain=100, num_boundary=2, anchors=t_train, num_test=10000 ) net = dde.maps.FNN([1] + [40] * 3 + [1], "swish", "Glorot normal") model = dde.Model(data, net) model.compile("adam", lr=0.001,loss='MSE') losshistory, train_state = model.train(epochs=10000) dde.saveplot(losshistory, train_state, issave=True, isplot=True) loss

Any help is highly appreciated !

khaoulaoue avatar Apr 12 '22 11:04 khaoulaoue

`activation = "swish"

initializer = "Glorot uniform"

net = dde.nn.ResNet(1,1,32,3, activation, initializer)

model = dde.Model(data, net)

model.compile("L-BFGS-B" ,loss_weights=[0.01, 10, 10])

model.train()

learning_rate = 0.001

model.compile("adam", lr = learning_rate,loss_weights=[0.01,10, 10])`

AHDMarwan avatar Apr 12 '22 20:04 AHDMarwan

thank you @AHDMarwan

But why the use of ResNet and how did you choose the weight' values? also I encountered this issue module 'deepxde.nn.tensorflow' has no attribute 'ResNet' when I tried to build a resnet network

khaoulaoue avatar Apr 13 '22 11:04 khaoulaoue

For FNN is in some cases, the gradient will be vanishingly small, effectively preventing the weight from changing its value, so it's better to use the ResNet. To solve the error of deepxde .... has no attribute ResNet, maybe you need to upgrade you deepXDE package

AHDMarwan avatar Apr 13 '22 20:04 AHDMarwan

thank you @AHDMarwan !

and for the choice of weights , why did you assign a smaller value to the ODE loss weight ?

khaoulaoue avatar Apr 13 '22 20:04 khaoulaoue