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.m_train'] == 15]

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

#res_n_sig5 = res_correct
m_sig_all = np.array(res_n_sig5['Model info.n_sig'].tolist())


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

mse_means = []
std_errs = []
h = 8

for i in range(13):
    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_sig_all)
m_sig = sorted( list(my_set) ) 
#print(m_sig)

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

plt.plot(m_sig, mse_means, color='black', marker='x', linestyle='dashed', linewidth=3, markersize=16, label = 'Mean MSE')
plt.errorbar(m_sig, 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)


/home/rodion/anaconda3/lib/python3.6/site-packages/numpy/core/fromnumeric.py:3118: RuntimeWarning: Mean of empty slice.
  out=out, **kwargs)
/home/rodion/anaconda3/lib/python3.6/site-packages/numpy/core/_methods.py:85: RuntimeWarning: invalid value encountered in double_scalars
  ret = ret.dtype.type(ret / rcount)
/home/rodion/anaconda3/lib/python3.6/site-packages/numpy/core/_methods.py:140: RuntimeWarning: Degrees of freedom <= 0 for slice
  keepdims=keepdims)
/home/rodion/anaconda3/lib/python3.6/site-packages/numpy/core/_methods.py:110: RuntimeWarning: invalid value encountered in true_divide
  arrmean, rcount, out=arrmean, casting='unsafe', subok=False)
/home/rodion/anaconda3/lib/python3.6/site-packages/numpy/core/_methods.py:132: RuntimeWarning: invalid value encountered in double_scalars
  ret = ret.dtype.type(ret / rcount)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-b29dc8db3113> in <module>()
     31 plt.scatter(m_sig_all, mse_all, label = 'MSE for all points', marker = "D",s=40)
     32 
---> 33 plt.plot(m_sig, mse_means, color='black', marker='x', linestyle='dashed', linewidth=3, markersize=16, label = 'Mean MSE')
     34 plt.errorbar(m_sig, mse_means, yerr=std_errs, ecolor='r', lw=2, capsize=15, mew = 3, zorder=3, label = 'Std.error of MSE', linestyle='None')
     35 axes.set_yscale ('log')#, nonposy='clip')

/home/rodion/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py in plot(*args, **kwargs)
   3356                       mplDeprecation)
   3357     try:
-> 3358         ret = ax.plot(*args, **kwargs)
   3359     finally:
   3360         ax._hold = washold

/home/rodion/anaconda3/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
   1853                         "the Matplotlib list!)" % (label_namer, func.__name__),
   1854                         RuntimeWarning, stacklevel=2)
-> 1855             return func(ax, *args, **kwargs)
   1856 
   1857         inner.__doc__ = _add_data_doc(inner.__doc__,

/home/rodion/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_axes.py in plot(self, *args, **kwargs)
   1525         kwargs = cbook.normalize_kwargs(kwargs, _alias_map)
   1526 
-> 1527         for line in self._get_lines(*args, **kwargs):
   1528             self.add_line(line)
   1529             lines.append(line)

/home/rodion/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py in _grab_next_args(self, *args, **kwargs)
    404                 this += args[0],
    405                 args = args[1:]
--> 406             for seg in self._plot_args(this, kwargs):
    407                 yield seg
    408 

/home/rodion/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py in _plot_args(self, tup, kwargs)
    381             x, y = index_of(tup[-1])
    382 
--> 383         x, y = self._xy_from_xy(x, y)
    384 
    385         if self.command == 'plot':

/home/rodion/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py in _xy_from_xy(self, x, y)
    240         if x.shape[0] != y.shape[0]:
    241             raise ValueError("x and y must have same first dimension, but "
--> 242                              "have shapes {} and {}".format(x.shape, y.shape))
    243         if x.ndim > 2 or y.ndim > 2:
    244             raise ValueError("x and y can be no greater than 2-D, but have "

ValueError: x and y must have same first dimension, but have shapes (0,) and (13,)

In [ ]:
m_trains

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:
#%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))

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:
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
)

In [ ]:
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(),
)

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

In [ ]:
res_correct

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: