In [1]:
import pandas as pd
from pandas.io.json import json_normalize #package for flattening json in pandas df
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import json
import os
%matplotlib inline

In [2]:
os.chdir("./runs/lagaris/1d_trapz_preparation/")
origin_path = os.getcwd() 
runs_id = os.listdir("./")
runs_id = [int(item) for item in runs_id]
runs_id = sorted(runs_id)

In [3]:
df_list = []
for run_id in runs_id:
    os.chdir("./"+str(run_id))
    f_in = open('out.json', 'r')
    run_info = json.load(f_in)
    f_in.close()
    a = json_normalize(run_info)
    #a.set_index(pd.Index([run_id]))
    df_list.append(a)
    #a = pd.concat(a,b)
    os.chdir(origin_path)
res1 = pd.concat(df_list,ignore_index=True)

In [4]:
res_correct = res1[res1['Model info.n_sig'] < 14]
#res_correct

In [5]:
res_n_sig5 = res_correct[res_correct['Model info.n_sig'] == 5]

m_train_all = np.array(res_n_sig5['Model info.m_train'].tolist())

mse_all = np.array(res_n_sig5['Out info.MSE'].tolist())

mse_means = []
std_errs = []
h = 8

for i in range(12):
    ds = res_n_sig5[0+h*i:8+h*i]
    mse_l = np.array(ds['Out info.MSE'].tolist())
    mse_means.append(np.mean(mse_l))
    std_errs.append(np.std(mse_l))

my_set = set(m_train_all)
m_trains = sorted( list(my_set) ) 
print(m_trains)

figure = plt.figure(figsize=(12,8))
axes = figure.add_subplot (1, 1, 1)
plt.grid(True)
plt.title('MSE vs number of train points. 5 sigmoids', fontsize=15)
plt.xlabel('Number of train points', fontsize=15)
plt.ylabel('MSE', fontsize=15)
plt.scatter(m_train_all, mse_all, label = 'MSE for all points', marker = "D",s=40)

plt.plot(m_trains, mse_means, color='black', marker='x', linestyle='dashed', linewidth=3, markersize=16, label = 'Mean MSE')
plt.errorbar(m_trains, mse_means, yerr=std_errs, ecolor='r', lw=2, capsize=15, mew = 3, zorder=3, label = 'Std.error of MSE', linestyle='None')
axes.set_yscale ('log')#, nonposy='clip')

plt.legend(loc=1, prop={'size': 25})
print(std_errs)


[1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56]
[0.011780256085941876, 0.011736751563021893, 1.277780155043645e-12, 7.488822090133562e-14, 4.289031869856569e-12, 3.420371447596467e-14, 2.5082068052931187e-12, 5.099499618561339e-13, 3.829922387972831e-14, 1.9179481553955045e-13, 6.490171044496423e-14, 9.305164742611212e-14]

In [6]:
m_trains


Out[6]:
[1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56]

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [7]:
#%matplotlib notebook
n_sig_all = np.array(res_correct['Model info.n_sig'].tolist())
n_sig_all = n_sig_all.reshape(n_sig_all.size,1)

m_train_all = np.array(res_correct['Model info.m_train'].tolist())
m_train_all = m_train_all.reshape(m_train_all.size,1)

mse_all = np.array(res_correct['Out info.MSE'].tolist())
mse_all = mse_all.reshape(mse_all.size,1)


from mpl_toolkits.mplot3d.axes3d import Axes3D
fig = plt.figure(figsize=(15,10))
ax = fig.add_subplot(1, 2, 1, projection='3d')
ax.scatter(n_sig_all, m_train_all, np.log10(mse_all))


Out[7]:
<mpl_toolkits.mplot3d.art3d.Path3DCollection at 0x2c6d80e6c50>

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [8]:
plt.figure(figsize=(10,7))
plt.grid(True)
plt.title('MSE vs m_trapz', fontsize=15)
plt.xlabel('Number of integration points', fontsize=15)
plt.ylabel('MSE', fontsize=15)
ax = plt.gca()
res_correct.plot(
    x='Model info.n_sig',
    y='Out info.MSE',
    logy=True,
    #logx=True,
    ax = plt.gca(),
    style = 'ro',
)

ax.legend(
   loc='best',
   fontsize=15
)


Out[8]:
<matplotlib.legend.Legend at 0x2c6d8558a20>

In [9]:
res2 = res_correct[res_correct['Model info.m_train'] > 35]
plt.figure(figsize=(10,7))
plt.title('MSE vs m_trapz', fontsize=26)
res2.plot.scatter(
    x='Model info.n_sig',
    y='Out info.MSE',
    logy=True,
    ax = plt.gca(),
)


Out[9]:
<matplotlib.axes._subplots.AxesSubplot at 0x2c6d85b2b70>

In [10]:
#1 6 11 16 21 26 31 36 41 46 51 56

In [11]:
res_correct


Out[11]:
Model info.a Model info.b Model info.m_train Model info.m_trapz Model info.n_sig Out info.MSE Out info.Std
0 -5 5 1 150 1 9.171818e-03 9.581753e-02
1 -5 5 1 150 1 1.920493e-02 1.386512e-01
2 -5 5 1 150 1 7.728864e-03 8.795795e-02
3 -5 5 1 150 1 1.717892e-02 1.311339e-01
4 -5 5 1 150 1 1.315710e-02 1.147618e-01
5 -5 5 1 150 1 5.025866e-03 7.092881e-02
6 -5 5 1 150 1 6.931093e-03 8.329484e-02
7 -5 5 1 150 1 2.586761e-03 5.088566e-02
8 -5 5 6 150 1 1.879685e-14 1.371702e-07
9 -5 5 6 150 1 1.978691e-14 1.407363e-07
10 -5 5 6 150 1 9.352529e-15 9.675687e-08
11 -5 5 6 150 1 2.907727e-14 1.706059e-07
12 -5 5 6 150 1 2.471366e-14 1.572844e-07
13 -5 5 6 150 1 6.527128e-15 8.083107e-08
14 -5 5 6 150 1 1.589623e-14 1.261433e-07
15 -5 5 6 150 1 1.791141e-14 1.339005e-07
16 -5 5 11 150 1 8.637847e-15 9.298652e-08
17 -5 5 11 150 1 6.686226e-15 8.181026e-08
18 -5 5 11 150 1 1.373421e-14 1.172517e-07
19 -5 5 11 150 1 1.251171e-14 1.119117e-07
20 -5 5 11 150 1 1.690202e-14 1.300728e-07
21 -5 5 11 150 1 8.332502e-15 9.132821e-08
22 -5 5 11 150 1 1.503682e-14 1.226861e-07
23 -5 5 11 150 1 1.748505e-14 1.322972e-07
24 -5 5 16 150 1 9.911629e-15 9.960698e-08
25 -5 5 16 150 1 1.120490e-14 1.059062e-07
26 -5 5 16 150 1 1.581202e-14 1.258088e-07
27 -5 5 16 150 1 2.134972e-14 1.461885e-07
28 -5 5 16 150 1 6.126785e-15 7.831295e-08
29 -5 5 16 150 1 9.613702e-15 9.809855e-08
... ... ... ... ... ... ... ...
1218 -5 5 41 150 13 7.984492e-12 2.827098e-06
1219 -5 5 41 150 13 2.268066e-12 1.506764e-06
1220 -5 5 41 150 13 1.864015e-12 1.365972e-06
1221 -5 5 41 150 13 1.768474e-13 4.207427e-07
1222 -5 5 41 150 13 3.750102e-13 6.126872e-07
1223 -5 5 41 150 13 8.059370e-13 8.981892e-07
1224 -5 5 46 150 13 8.397497e-13 9.168371e-07
1225 -5 5 46 150 13 3.298917e-12 1.817201e-06
1226 -5 5 46 150 13 9.814563e-12 3.134388e-06
1227 -5 5 46 150 13 3.678945e-11 6.068466e-06
1228 -5 5 46 150 13 2.501470e-12 1.582395e-06
1229 -5 5 46 150 13 4.791286e-12 2.189996e-06
1230 -5 5 46 150 13 1.824327e-12 1.351352e-06
1231 -5 5 46 150 13 3.132218e-11 5.599422e-06
1232 -5 5 51 150 13 1.660446e-12 1.289228e-06
1233 -5 5 51 150 13 1.064679e-12 1.032349e-06
1234 -5 5 51 150 13 3.299135e-12 1.817261e-06
1235 -5 5 51 150 13 4.037451e-02 2.010346e-01
1236 -5 5 51 150 13 1.280692e-12 1.132243e-06
1237 -5 5 51 150 13 1.538897e-11 3.924840e-06
1238 -5 5 51 150 13 3.362255e-12 1.834563e-06
1239 -5 5 51 150 13 4.222644e-11 6.501439e-06
1240 -5 5 56 150 13 1.393860e-13 3.735311e-07
1241 -5 5 56 150 13 5.967793e-13 7.729015e-07
1242 -5 5 56 150 13 1.199917e-14 1.095956e-07
1243 -5 5 56 150 13 3.319197e-11 5.764130e-06
1244 -5 5 56 150 13 1.705098e-12 1.306448e-06
1245 -5 5 56 150 13 1.755027e-13 4.191401e-07
1246 -5 5 56 150 13 4.038075e-02 2.010502e-01
1247 -5 5 56 150 13 3.399462e-11 5.833408e-06

1248 rows × 7 columns


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: