ehsanhaghighat / sciann

Deep learning for Engineers - Physics Informed Deep Learning
htttp://sciann.com
Other
325 stars 116 forks source link

How to add training and data points #66

Closed Mixpap closed 2 years ago

Mixpap commented 2 years ago

Hi! Maybe a silly question, but how can I add both observed data AND training data during the training.

Looking on the examples there is two ways of using scinn, one by sampling randomly data points for the physics part of the los function to train, using the snippet from the burgers equation example:

#...
L1 = diff(u, t) + u*diff(u,x) - (0.01/pi)*diff(u, x, order=2)
TOL = 0.001
C1 = (1-sign(t - TOL)) * (u + sin(pi*x))
C2 = (1-sign(x - (-1+TOL))) * (u)
C3 = (1+sign(x - ( 1-TOL))) * (u)
m = sn.SciModel([x, t], [L1, C1, C2, C3])
x_data, t_data = np.meshgrid(
    np.linspace(-1, 1, 100), 
    np.linspace(0, 1, 100)
)
h = m.train([x_data, t_data], 4*['zero'], learning_rate=0.002, epochs=5000, verbose=0)
#...

and the other by using data using the Data function, which looks like

#...
m = sn.SciModel([x, t], [L1, Data(u)])
#now we use observed data (u_data at x_data,t_data)
h = m.train([x_data, t_data], ['zero', u_data], learning_rate=0.002, epochs=5000, verbose=0)
#...

How someone can give both Data(u) but also use a (bigger) sampling space for the physics los function to optimise?

I have tried using something like

#...
x_sampling, t_sampling = np.meshgrid(
    np.linspace(-1, 1, 100), 
    np.linspace(0, 1, 100)
)
#now we use observed data (u_data at x_data,t_data)
C = (1-sign(t - t_data)) *  (1-sign(x - x_data)) * (u - u_data)
m = sn.SciModel([x, t], [L1, C])
h = m.train([x_sampling, t_sampling], ['zero', 'zero'], learning_rate=0.002, epochs=5000, verbose=0)
#...

but the results are terrible, so I thought that maybe this is not a correct way to follow, am I missing something? Thanks!

Mixpap commented 2 years ago

Ok I saw my mistake, and corrected

#...
x_sampling, t_sampling = np.meshgrid(
    np.linspace(-1, 1, 100), 
    np.linspace(0, 1, 100)
)
#now we use observed data (u_data at x_data,t_data)
C = (t == t_data) *  (x == x_data) * abs(u - u_data)
m = sn.SciModel([x, t], [L1, C])
x_train=np.append(x_sampling,x_data)
t_train=np.append(t_sampling,t_data)
h = m.train([x_train, t_train], ['zero', 'zero'], learning_rate=0.002, epochs=5000, verbose=0)
#...