Deep Learning for simulating ODE(Laplace equation)

$\nabla^2 \phi (x,y) = \frac{\partial^2 \phi}{\partial x^2} + \frac{\partial^2 \phi}{\partial y^2}=0, \forall x \in D. $

With following BCs:

$\phi (x,y)=0,\forall x \in ${$(x,y)\in D|x=0,x=1,$ or $y=0$}

$\phi (x,y)=sin\pi x, \forall x \in ${$(x,y)\in D|y=1$}

Load all the libaray


In [46]:
'''
keras mlp regression
'''
from __future__ import print_function

import numpy as np

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm

from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
%matplotlib inline

Generate data sample from the analitical solution


In [47]:
nx = 20
ny = 20

x_space = np.linspace(0, 1, nx)
y_space = np.linspace(0, 1, ny)


def analytic_solution(x):
    return (1 / (np.exp(np.pi) - np.exp(-np.pi))) * \
           np.sin(np.pi * x[0]) * (np.exp(np.pi * x[1]) - np.exp(-np.pi * x[1]))


x_input = np.zeros((ny,nx,2))

surface = np.zeros((ny, nx))
for i, x in enumerate(x_space):
    for j, y in enumerate(y_space):
        surface[i][j] = analytic_solution([x, y])
        x_input[i][j] = [x, y]


x_input = x_input.reshape(-1, x_input.shape[-1])
y_anal = surface.reshape(-1,1)

print('generate data from analytic solution')
###
fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y = np.meshgrid(x_space, y_space)
surf = ax.plot_surface(X, Y, surface, rstride=1, cstride=1, cmap=cm.viridis,
        linewidth=0, antialiased=False)

ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_zlim(0, 2)

ax.set_xlabel('$x$')
ax.set_ylabel('$y$')
plt.colorbar(surf)


generate data from analytic solution
Out[47]:
<matplotlib.colorbar.Colorbar at 0x2b7934db6f98>

Build a MLP emulator

3 hidden Layes MLP

20 X 400 X 20


In [48]:
batch_size = 32
epochs = 400
vsplit = 0.

print('Building model...')
model = Sequential()
model.add(Dense(20, input_shape=(2,)))
model.add(Activation('relu'))
model.add(Dropout(0.))
model.add(Dense(400))
model.add(Activation('relu'))
model.add(Dropout(0.))
model.add(Dense(20))
model.add(Activation('relu'))
model.add(Dropout(0.2))
model.add(Dense(1))
#model.add(Activation('linear'))



model.compile(loss='mse',
              optimizer='adam',
              metrics=['accuracy'])

history = model.fit(x_input, y_anal,
                    batch_size=batch_size,
                    epochs=epochs,
                    verbose=1,
                    validation_split=vsplit)
# score = model.evaluate(x_test, y_test,
#                        batch_size=batch_size, verbose=1)
# print('Test score:', score[0])
# print('Test accuracy:', score[1])


Building model...
Epoch 1/400
400/400 [==============================] - 0s - loss: 0.0356 - acc: 0.0975     
Epoch 2/400
400/400 [==============================] - 0s - loss: 0.0236 - acc: 0.0975     
Epoch 3/400
400/400 [==============================] - 0s - loss: 0.0190 - acc: 0.0975     
Epoch 4/400
400/400 [==============================] - 0s - loss: 0.0143 - acc: 0.0975     
Epoch 5/400
400/400 [==============================] - 0s - loss: 0.0133 - acc: 0.0975     
Epoch 6/400
400/400 [==============================] - 0s - loss: 0.0110 - acc: 0.0975     
Epoch 7/400
400/400 [==============================] - 0s - loss: 0.0093 - acc: 0.0975     
Epoch 8/400
400/400 [==============================] - 0s - loss: 0.0086 - acc: 0.0975     
Epoch 9/400
400/400 [==============================] - 0s - loss: 0.0076 - acc: 0.0975     
Epoch 10/400
400/400 [==============================] - 0s - loss: 0.0072 - acc: 0.0975     
Epoch 11/400
400/400 [==============================] - 0s - loss: 0.0057 - acc: 0.0975     
Epoch 12/400
400/400 [==============================] - 0s - loss: 0.0067 - acc: 0.0975     
Epoch 13/400
400/400 [==============================] - 0s - loss: 0.0054 - acc: 0.0975         
Epoch 14/400
400/400 [==============================] - 0s - loss: 0.0051 - acc: 0.0975     
Epoch 15/400
400/400 [==============================] - 0s - loss: 0.0049 - acc: 0.0975     
Epoch 16/400
400/400 [==============================] - 0s - loss: 0.0049 - acc: 0.0975     
Epoch 17/400
400/400 [==============================] - 0s - loss: 0.0051 - acc: 0.0975     
Epoch 18/400
400/400 [==============================] - 0s - loss: 0.0039 - acc: 0.0975     
Epoch 19/400
400/400 [==============================] - 0s - loss: 0.0046 - acc: 0.0975     
Epoch 20/400
400/400 [==============================] - 0s - loss: 0.0058 - acc: 0.0975     
Epoch 21/400
400/400 [==============================] - 0s - loss: 0.0047 - acc: 0.0975     
Epoch 22/400
400/400 [==============================] - 0s - loss: 0.0044 - acc: 0.0975         
Epoch 23/400
400/400 [==============================] - 0s - loss: 0.0041 - acc: 0.0975     
Epoch 24/400
400/400 [==============================] - 0s - loss: 0.0043 - acc: 0.0975     
Epoch 25/400
400/400 [==============================] - 0s - loss: 0.0038 - acc: 0.0975         
Epoch 26/400
400/400 [==============================] - 0s - loss: 0.0044 - acc: 0.0975     
Epoch 27/400
400/400 [==============================] - 0s - loss: 0.0028 - acc: 0.0975     
Epoch 28/400
400/400 [==============================] - 0s - loss: 0.0037 - acc: 0.0975     
Epoch 29/400
400/400 [==============================] - 0s - loss: 0.0038 - acc: 0.0975     
Epoch 30/400
400/400 [==============================] - 0s - loss: 0.0035 - acc: 0.0975     
Epoch 31/400
400/400 [==============================] - 0s - loss: 0.0027 - acc: 0.0975     
Epoch 32/400
400/400 [==============================] - 0s - loss: 0.0029 - acc: 0.0975     
Epoch 33/400
400/400 [==============================] - 0s - loss: 0.0041 - acc: 0.0975     
Epoch 34/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 35/400
400/400 [==============================] - ETA: 0s - loss: 0.0032 - acc: 0.125 - 0s - loss: 0.0039 - acc: 0.0975     
Epoch 36/400
400/400 [==============================] - 0s - loss: 0.0041 - acc: 0.0975     
Epoch 37/400
400/400 [==============================] - 0s - loss: 0.0035 - acc: 0.0975     
Epoch 38/400
400/400 [==============================] - 0s - loss: 0.0033 - acc: 0.0975     
Epoch 39/400
400/400 [==============================] - 0s - loss: 0.0051 - acc: 0.0975     
Epoch 40/400
400/400 [==============================] - 0s - loss: 0.0038 - acc: 0.0975     
Epoch 41/400
400/400 [==============================] - 0s - loss: 0.0038 - acc: 0.0975     
Epoch 42/400
400/400 [==============================] - 0s - loss: 0.0028 - acc: 0.0975     
Epoch 43/400
400/400 [==============================] - 0s - loss: 0.0028 - acc: 0.0975         
Epoch 44/400
400/400 [==============================] - 0s - loss: 0.0024 - acc: 0.0975     
Epoch 45/400
400/400 [==============================] - 0s - loss: 0.0026 - acc: 0.0975     
Epoch 46/400
400/400 [==============================] - 0s - loss: 0.0034 - acc: 0.0975     
Epoch 47/400
400/400 [==============================] - 0s - loss: 0.0032 - acc: 0.0975     
Epoch 48/400
400/400 [==============================] - 0s - loss: 0.0028 - acc: 0.0975     
Epoch 49/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 50/400
400/400 [==============================] - 0s - loss: 0.0032 - acc: 0.0975     
Epoch 51/400
400/400 [==============================] - 0s - loss: 0.0029 - acc: 0.0975     
Epoch 52/400
400/400 [==============================] - 0s - loss: 0.0026 - acc: 0.0975     
Epoch 53/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 54/400
400/400 [==============================] - 0s - loss: 0.0029 - acc: 0.0975         
Epoch 55/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 56/400
400/400 [==============================] - 0s - loss: 0.0033 - acc: 0.0975     
Epoch 57/400
400/400 [==============================] - 0s - loss: 0.0027 - acc: 0.0975     
Epoch 58/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 59/400
400/400 [==============================] - 0s - loss: 0.0026 - acc: 0.0975         
Epoch 60/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 61/400
400/400 [==============================] - 0s - loss: 0.0029 - acc: 0.0975         
Epoch 62/400
400/400 [==============================] - 0s - loss: 0.0030 - acc: 0.0975     
Epoch 63/400
400/400 [==============================] - 0s - loss: 0.0024 - acc: 0.0975     
Epoch 64/400
400/400 [==============================] - 0s - loss: 0.0026 - acc: 0.0975         
Epoch 65/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 66/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 67/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 68/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 69/400
400/400 [==============================] - 0s - loss: 0.0024 - acc: 0.0975     
Epoch 70/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 71/400
400/400 [==============================] - 0s - loss: 0.0028 - acc: 0.0975     
Epoch 72/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 73/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 74/400
400/400 [==============================] - 0s - loss: 0.0033 - acc: 0.0975         
Epoch 75/400
400/400 [==============================] - 0s - loss: 0.0024 - acc: 0.0975     
Epoch 76/400
400/400 [==============================] - 0s - loss: 0.0026 - acc: 0.0975     
Epoch 77/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 78/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 79/400
400/400 [==============================] - 0s - loss: 0.0029 - acc: 0.0975     
Epoch 80/400
400/400 [==============================] - 0s - loss: 0.0026 - acc: 0.0975         
Epoch 81/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 82/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 83/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 84/400
400/400 [==============================] - 0s - loss: 0.0026 - acc: 0.0975     
Epoch 85/400
400/400 [==============================] - 0s - loss: 0.0026 - acc: 0.0975     
Epoch 86/400
400/400 [==============================] - 0s - loss: 0.0024 - acc: 0.0975     
Epoch 87/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 88/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 89/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 90/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 91/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 92/400
400/400 [==============================] - 0s - loss: 0.0029 - acc: 0.0975     
Epoch 93/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 94/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 95/400
400/400 [==============================] - 0s - loss: 0.0027 - acc: 0.0975         
Epoch 96/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 97/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 98/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975         
Epoch 99/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975         
Epoch 100/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 101/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975         
Epoch 102/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975         
Epoch 103/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 104/400
400/400 [==============================] - 0s - loss: 0.0029 - acc: 0.0975     
Epoch 105/400
400/400 [==============================] - 0s - loss: 0.0026 - acc: 0.0975     
Epoch 106/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 107/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 108/400
400/400 [==============================] - 0s - loss: 0.0029 - acc: 0.0975     
Epoch 109/400
400/400 [==============================] - 0s - loss: 0.0030 - acc: 0.0975     
Epoch 110/400
400/400 [==============================] - 0s - loss: 0.0024 - acc: 0.0975     
Epoch 111/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975     
Epoch 112/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 113/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 114/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975         
Epoch 115/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 116/400
400/400 [==============================] - 0s - loss: 0.0030 - acc: 0.0975     
Epoch 117/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 118/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 119/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 120/400
400/400 [==============================] - 0s - loss: 0.0024 - acc: 0.0975     
Epoch 121/400
400/400 [==============================] - 0s - loss: 0.0040 - acc: 0.0975     
Epoch 122/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975     
Epoch 123/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 124/400
400/400 [==============================] - 0s - loss: 0.0024 - acc: 0.0975         
Epoch 125/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975     
Epoch 126/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 127/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 128/400
400/400 [==============================] - 0s - loss: 0.0024 - acc: 0.0975     
Epoch 129/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 130/400
400/400 [==============================] - 0s - loss: 0.0027 - acc: 0.0975     
Epoch 131/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 132/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 133/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 134/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 135/400
400/400 [==============================] - 0s - loss: 0.0030 - acc: 0.0975     
Epoch 136/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 137/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 138/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975         
Epoch 139/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 140/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975         
Epoch 141/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 142/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 143/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 144/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 145/400
400/400 [==============================] - 0s - loss: 0.0030 - acc: 0.0975         
Epoch 146/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 147/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 148/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 149/400
400/400 [==============================] - 0s - loss: 0.0030 - acc: 0.0975         
Epoch 150/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975         
Epoch 151/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 152/400
400/400 [==============================] - 0s - loss: 0.0016 - acc: 0.0975     
Epoch 153/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 154/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 155/400
400/400 [==============================] - 0s - loss: 0.0027 - acc: 0.0975     
Epoch 156/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 157/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975     
Epoch 158/400
400/400 [==============================] - 0s - loss: 0.0027 - acc: 0.0975     
Epoch 159/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 160/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 161/400
400/400 [==============================] - 0s - loss: 0.0016 - acc: 0.0975     
Epoch 162/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 163/400
400/400 [==============================] - 0s - loss: 0.0024 - acc: 0.0975     
Epoch 164/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 165/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975     
Epoch 166/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 167/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 168/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 169/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 170/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 171/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975     
Epoch 172/400
400/400 [==============================] - 0s - loss: 0.0024 - acc: 0.0975     
Epoch 173/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 174/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 175/400
400/400 [==============================] - 0s - loss: 0.0016 - acc: 0.0975     
Epoch 176/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 177/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975     
Epoch 178/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 179/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 180/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 181/400
400/400 [==============================] - 0s - loss: 0.0026 - acc: 0.0975     
Epoch 182/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 183/400
400/400 [==============================] - 0s - loss: 0.0016 - acc: 0.0975     
Epoch 184/400
400/400 [==============================] - 0s - loss: 0.0014 - acc: 0.0975     
Epoch 185/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 186/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 187/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 188/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 189/400
400/400 [==============================] - 0s - loss: 0.0016 - acc: 0.0975         
Epoch 190/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975         
Epoch 191/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 192/400
400/400 [==============================] - 0s - loss: 0.0026 - acc: 0.0975     
Epoch 193/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 194/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 195/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 196/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 197/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 198/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 199/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 200/400
400/400 [==============================] - 0s - loss: 0.0016 - acc: 0.0975     
Epoch 201/400
400/400 [==============================] - 0s - loss: 0.0024 - acc: 0.0975         
Epoch 202/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 203/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 204/400
400/400 [==============================] - 0s - loss: 0.0016 - acc: 0.0975     
Epoch 205/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975         
Epoch 206/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 207/400
400/400 [==============================] - 0s - loss: 0.0027 - acc: 0.0975     
Epoch 208/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975     
Epoch 209/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 210/400
400/400 [==============================] - 0s - loss: 0.0016 - acc: 0.0975         
Epoch 211/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975         
Epoch 212/400
400/400 [==============================] - 0s - loss: 0.0031 - acc: 0.0975         
Epoch 213/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 214/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 215/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 216/400
400/400 [==============================] - 0s - loss: 0.0027 - acc: 0.0975         
Epoch 217/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 218/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 219/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975         
Epoch 220/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975         
Epoch 221/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 222/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975     
Epoch 223/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 224/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975             
Epoch 225/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 226/400
400/400 [==============================] - 0s - loss: 0.0013 - acc: 0.0975         
Epoch 227/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 228/400
400/400 [==============================] - 0s - loss: 0.0028 - acc: 0.0975     
Epoch 229/400
400/400 [==============================] - 0s - loss: 0.0016 - acc: 0.0975     
Epoch 230/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 231/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975         
Epoch 232/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 233/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 234/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 235/400
400/400 [==============================] - 0s - loss: 0.0024 - acc: 0.0975     
Epoch 236/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975         
Epoch 237/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 238/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 239/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 240/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 241/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 242/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975         
Epoch 243/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 244/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975         
Epoch 245/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 246/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975         
Epoch 247/400
400/400 [==============================] - 0s - loss: 0.0024 - acc: 0.0975     
Epoch 248/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975     
Epoch 249/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975         
Epoch 250/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 251/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975         
Epoch 252/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 253/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 254/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 255/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 256/400
400/400 [==============================] - 0s - loss: 0.0015 - acc: 0.0975     
Epoch 257/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 258/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 259/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 260/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 261/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 262/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975         
Epoch 263/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 264/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 265/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 266/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 267/400
400/400 [==============================] - ETA: 0s - loss: 9.6368e-04 - acc: 0.031 - 0s - loss: 0.0013 - acc: 0.0975         
Epoch 268/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975         
Epoch 269/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 270/400
400/400 [==============================] - 0s - loss: 0.0026 - acc: 0.0975     
Epoch 271/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 272/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 273/400
400/400 [==============================] - 0s - loss: 0.0029 - acc: 0.0975     
Epoch 274/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 275/400
400/400 [==============================] - 0s - loss: 0.0027 - acc: 0.0975     
Epoch 276/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 277/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 278/400
400/400 [==============================] - 0s - loss: 0.0015 - acc: 0.0975         
Epoch 279/400
400/400 [==============================] - 0s - loss: 0.0014 - acc: 0.0975     
Epoch 280/400
400/400 [==============================] - 0s - loss: 0.0015 - acc: 0.0975     
Epoch 281/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 282/400
400/400 [==============================] - 0s - loss: 0.0027 - acc: 0.0975     
Epoch 283/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975         
Epoch 284/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 285/400
400/400 [==============================] - 0s - loss: 0.0026 - acc: 0.0975     
Epoch 286/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975         
Epoch 287/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 288/400
400/400 [==============================] - 0s - loss: 0.0024 - acc: 0.0975     
Epoch 289/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 290/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975     
Epoch 291/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975         
Epoch 292/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 293/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 294/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 295/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 296/400
400/400 [==============================] - 0s - loss: 0.0016 - acc: 0.0975         
Epoch 297/400
400/400 [==============================] - 0s - loss: 0.0016 - acc: 0.0975     
Epoch 298/400
400/400 [==============================] - 0s - loss: 0.0034 - acc: 0.0975     
Epoch 299/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 300/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 301/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 302/400
400/400 [==============================] - 0s - loss: 0.0027 - acc: 0.0975     
Epoch 303/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 304/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975         
Epoch 305/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975         
Epoch 306/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975         
Epoch 307/400
400/400 [==============================] - 0s - loss: 0.0016 - acc: 0.0975         
Epoch 308/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975         
Epoch 309/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 310/400
400/400 [==============================] - 0s - loss: 0.0015 - acc: 0.0975     
Epoch 311/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975         
Epoch 312/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 313/400
400/400 [==============================] - 0s - loss: 0.0024 - acc: 0.0975     
Epoch 314/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 315/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 316/400
400/400 [==============================] - 0s - loss: 0.0027 - acc: 0.0975     
Epoch 317/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 318/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 319/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 320/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 321/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975         
Epoch 322/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 323/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975         
Epoch 324/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 325/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975         
Epoch 326/400
400/400 [==============================] - 0s - loss: 0.0016 - acc: 0.0975         
Epoch 327/400
400/400 [==============================] - 0s - loss: 0.0024 - acc: 0.0975     
Epoch 328/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 329/400
400/400 [==============================] - 0s - loss: 0.0014 - acc: 0.0975     
Epoch 330/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975         
Epoch 331/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 332/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 333/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975     
Epoch 334/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 335/400
400/400 [==============================] - ETA: 0s - loss: 0.0015 - acc: 0.062 - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 336/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 337/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 338/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 339/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 340/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 341/400
400/400 [==============================] - 0s - loss: 0.0016 - acc: 0.0975     
Epoch 342/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 343/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 344/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975         
Epoch 345/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 346/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975     
Epoch 347/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 348/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 349/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 350/400
400/400 [==============================] - 0s - loss: 0.0024 - acc: 0.0975     
Epoch 351/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 352/400
400/400 [==============================] - 0s - loss: 0.0016 - acc: 0.0975     
Epoch 353/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 354/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 355/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 356/400
400/400 [==============================] - 0s - loss: 0.0014 - acc: 0.0975     
Epoch 357/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 358/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 359/400
400/400 [==============================] - 0s - loss: 0.0016 - acc: 0.0975     
Epoch 360/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 361/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 362/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 363/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975         
Epoch 364/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 365/400
400/400 [==============================] - 0s - loss: 0.0026 - acc: 0.0975     
Epoch 366/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 367/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975     
Epoch 368/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 369/400
400/400 [==============================] - 0s - loss: 0.0016 - acc: 0.0975     
Epoch 370/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975     
Epoch 371/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 372/400
400/400 [==============================] - 0s - loss: 0.0017 - acc: 0.0975         
Epoch 373/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 374/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 375/400
400/400 [==============================] - 0s - loss: 0.0013 - acc: 0.0975         
Epoch 376/400
400/400 [==============================] - 0s - loss: 0.0025 - acc: 0.0975     
Epoch 377/400
400/400 [==============================] - 0s - loss: 0.0023 - acc: 0.0975     
Epoch 378/400
400/400 [==============================] - 0s - loss: 0.0015 - acc: 0.0975         
Epoch 379/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975     
Epoch 380/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975         
Epoch 381/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 382/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 383/400
400/400 [==============================] - 0s - loss: 0.0016 - acc: 0.0975         
Epoch 384/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975     
Epoch 385/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 386/400
400/400 [==============================] - 0s - loss: 0.0015 - acc: 0.0975     
Epoch 387/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975     
Epoch 388/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975     
Epoch 389/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975         
Epoch 390/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 391/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975     
Epoch 392/400
400/400 [==============================] - 0s - loss: 0.0024 - acc: 0.0975     
Epoch 393/400
400/400 [==============================] - 0s - loss: 0.0015 - acc: 0.0975         
Epoch 394/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 395/400
400/400 [==============================] - 0s - loss: 0.0021 - acc: 0.0975     
Epoch 396/400
400/400 [==============================] - 0s - loss: 0.0020 - acc: 0.0975         
Epoch 397/400
400/400 [==============================] - 0s - loss: 0.0012 - acc: 0.0975         
Epoch 398/400
400/400 [==============================] - 0s - loss: 0.0022 - acc: 0.0975     
Epoch 399/400
400/400 [==============================] - 0s - loss: 0.0018 - acc: 0.0975         
Epoch 400/400
400/400 [==============================] - 0s - loss: 0.0019 - acc: 0.0975     

Learning Curves


In [49]:
if(bool(vsplit)):
    # summarize history for accuracy
    fig = plt.figure()
    plt.plot(history.history['acc'])
    plt.plot(history.history['val_acc'])
    plt.title('model accuracy')
    plt.ylabel('accuracy')
    plt.xlabel('epoch')
    plt.legend(['train', 'test'], loc='upper left')
    plt.show()

    # summarize history for loss
    fig = plt.figure()
    plt.plot(history.history['loss'])
    plt.plot(history.history['val_loss'])
    plt.title('model loss')
    plt.ylabel('loss')
    plt.xlabel('epoch')
    plt.legend(['train', 'test'], loc='upper left')
    plt.show()

ML inferencing


In [50]:
x_test = x_input+0.0
x_test_space=x_test.reshape(ny,nx,2)[0,:,1]
y_test_space=x_test.reshape(ny,nx,2)[:,0,0]
surface_predict = model.predict(x_test).reshape(ny, nx)

compare to analitical solution


In [51]:
###
fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y = np.meshgrid(x_test_space, y_test_space)
surf_pdt = ax.plot_surface(X, Y, surface_predict, rstride=1, cstride=1, cmap=cm.viridis,
        linewidth=0, antialiased=False)

ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_zlim(0, 2)

ax.set_xlabel('$x$')
ax.set_ylabel('$y$')
plt.colorbar(surf_pdt)

fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y = np.meshgrid(x_space, y_space)
surf = ax.plot_surface(X, Y, surface, rstride=1, cstride=1, cmap=cm.viridis,
        linewidth=0, antialiased=False)

ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_zlim(0, 2)

ax.set_xlabel('$x$')
ax.set_ylabel('$y$')
plt.colorbar(surf)


Out[51]:
<matplotlib.colorbar.Colorbar at 0x2b79351ad7f0>

top is the ML estimation; bottom is analitical solution


In [ ]: