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_main_serv/")
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['Out info.MSE'] < 0.01 ) | (res1['Model info.m_trapz'] < 10) ]
#res_correct = res1
In [5]:
#res_correct
In [6]:
#res_n_sig5 = res_correct[res_correct['Model info.n_sig'] == 5]
m_trapz_all = np.array(res_correct['Model info.m_trapz'].tolist())
mse_all = np.array(res_correct['Out info.MSE'].tolist())
mse_means = []
std_errs = []
h = 16
for i in range(119):
ds = res_correct[0+h*i:h+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_trapz_all)
m_trapz = sorted( list(my_set) )
#print(m_trapz)
figure = plt.figure(figsize=(12,8))
axes = figure.add_subplot (1, 1, 1)
plt.grid(True)
plt.title('MSE vs number of integration points. 5 sigmoids, 20 train points ', fontsize=15)
plt.xlabel('Number of integration points', fontsize=15)
plt.ylabel('MSE', fontsize=15)
#plt.scatter(m_trapz_all, mse_all, label = 'MSE for all points', marker = "D",s=40)
plt.plot(m_trapz, mse_means, color='black', marker='x', linestyle='dashed', linewidth=3, markersize=16, label = 'Mean MSE')
#plt.errorbar(m_trapz, mse_means, yerr=std_errs, ecolor='r', lw=2, capsize=15, mew = 3, zorder=3, label = 'Errorbar', linestyle='None')
axes.set_yscale ('log')#, nonposy='clip')
axes.set_xscale ('log')#, nonposy='clip')
plt.legend(loc=1, prop={'size': 25})
#print(std_errs)
Out[6]:
In [7]:
figure = plt.figure(figsize=(12,8))
axes = figure.add_subplot (1, 1, 1)
plt.grid(True)
plt.title('MSE vs number of integration points. 5 sigmoids, 20 train points ', fontsize=15)
plt.xlabel('Number of integration points', fontsize=15)
plt.ylabel('MSE', fontsize=15)
#plt.scatter(m_trapz_all, mse_all, label = 'MSE for all points', marker = "D",s=40)
plt.plot(m_trapz[:30], mse_means[:30], color='black', marker='x', linestyle='dashed', linewidth=3, markersize=16, label = 'Mean MSE')
plt.errorbar(m_trapz[:30], mse_means[:30], yerr=std_errs[:30], ecolor='r', lw=2, capsize=15, mew = 3, zorder=3, label = 'Std.error of MSE', linestyle='None')
axes.set_yscale ('log')#, nonposy='clip')
axes.set_xscale ('log')#, nonposy='clip')
plt.legend(loc=1, prop={'size': 25})
#print(std_errs)
Out[7]:
In [8]:
figure = plt.figure(figsize=(12,8))
axes = figure.add_subplot (1, 1, 1)
plt.grid(True)
plt.title('MSE vs number of integration points. 5 sigmoids, 20 train points ', fontsize=15)
plt.xlabel('Number of integration points', fontsize=15)
plt.ylabel('MSE', fontsize=15)
plt.scatter(m_trapz_all[:29*16], mse_all[:29*16], label = 'MSE for all points', marker = "D",s=40)
plt.plot(m_trapz[:30], mse_means[:30], color='black', marker='x', linestyle='dashed', linewidth=3, markersize=16, label = 'Mean MSE')
plt.errorbar(m_trapz[:30], mse_means[:30], yerr=std_errs[:30], ecolor='r', lw=2, capsize=15, mew = 3, zorder=3, label = 'Std.error of MSE', linestyle='None')
axes.set_yscale ('log')#, nonposy='clip')
#axes.set_xscale ('log')#, nonposy='clip')
plt.legend(loc=1, prop={'size': 25})
#print(std_errs)
Out[8]:
In [9]:
m_trapz[:30]
Out[9]:
In [10]:
figure = plt.figure(figsize=(12,8))
axes = figure.add_subplot (1, 1, 1)
plt.grid(True)
plt.title('MSE vs number of integration points. 5 sigmoids, 20 train points ', fontsize=15)
plt.xlabel('Number of integration points', fontsize=15)
plt.ylabel('MSE', fontsize=15)
plt.scatter(m_trapz_all[30*16:-32], mse_all[30*16:-32], label = 'MSE for all points', marker = "D",s=40)
plt.plot(m_trapz[30:], mse_means[30:], color='black', marker='x', linestyle='dashed', linewidth=3, markersize=16, label = 'Mean MSE')
plt.errorbar(m_trapz[30:], mse_means[30:], yerr=std_errs[30:], ecolor='r', lw=2, capsize=15, mew = 3, zorder=3, label = 'Std.error of MSE', linestyle='None')
axes.set_yscale ('log')#, nonposy='clip')
#axes.set_xscale ('log')#, nonposy='clip')
plt.legend(loc=1, prop={'size': 25})
#print(std_errs)
Out[10]:
In [ ]:
In [ ]:
In [ ]:
In [11]:
figure = plt.figure(figsize=(12,8))
axes = figure.add_subplot (1, 1, 1)
plt.grid(True)
plt.title('MSE vs number of integration points. 5 sigmoids, 20 train points ', fontsize=15)
plt.xlabel('Number of integration points', fontsize=15)
plt.ylabel('MSE', fontsize=15)
#plt.scatter(m_trapz_all, mse_all, label = 'MSE for all points', marker = "D",s=40)
plt.plot(m_trapz[:15], mse_means[:15], color='black', marker='x', linestyle='dashed', linewidth=3, markersize=16, label = 'Mean MSE')
plt.errorbar(m_trapz[:15], mse_means[:15], yerr=std_errs[:15], ecolor='r', lw=2, capsize=15, mew = 3, zorder=3, label = 'Std.error of MSE', linestyle='None')
axes.set_yscale ('log')#, nonposy='clip')
axes.set_xscale ('log')#, nonposy='clip')
plt.legend(loc=1, prop={'size': 25})
#print(std_errs)
Out[11]:
In [12]:
hui = 10
x = np.log10(m_trapz[:15])
y = np.log10(mse_means[:15])
der = []
for i in range(x.size-hui):
der.append((y[i+1]-y[i])/(x[i+1]-x[i]))
rrr = np.zeros(shape = (np.array(der).size)) + 10
figure = plt.figure(figsize=(12,8))
axes = figure.add_subplot (1, 1, 1)
plt.grid(True)
plt.title('MSE vs number of integration points. 5 sigmoids, 20 train points ', fontsize=15)
plt.xlabel('Number of integration points', fontsize=15)
plt.ylabel('MSE', fontsize=15)
#plt.scatter(m_trapz_all, mse_all, label = 'MSE for all points', marker = "D",s=40)
plt.plot(m_trapz[:-hui], np.power(rrr,der), color='blue', marker='+', linestyle='dashed', linewidth=3, markersize=16, label = 'der MSE')
plt.plot(m_trapz[:15-hui], mse_means[:15-hui], color='black', marker='x', linestyle='dashed', linewidth=3, markersize=16, label = 'Mean MSE')
plt.errorbar(m_trapz[:15-hui], mse_means[:15-hui], yerr=std_errs[:15-hui], ecolor='r', lw=2, capsize=15, mew = 3, zorder=3, label = 'Std.error of MSE', linestyle='None')
axes.set_yscale ('log')#, nonposy='clip')
axes.set_xscale ('log')#, nonposy='clip')
plt.legend(loc=1, prop={'size': 25})
#print(std_errs)
In [ ]:
x = np.log10(m_trapz[:15])
y = np.log10(mse_means[:15])
In [ ]:
np.power(rrr,der)
In [ ]:
der
In [ ]:
x = np.log10(m_trapz[:15])
y = np.log10(mse_means[:15])
der = []
hui = 10
for i in range(x.size-hui):
der.append((y[i+1]-y[i])/(x[i+1]-x[i]))
plt.plot(x[:-hui], der)
In [ ]:
rrr = np.zeros(shape = (np.array(der).size)) + 10
In [27]:
hui = 4
x = np.log10(m_trapz[:15])
y = np.log10(mse_means[:15])
der = []
for i in range(x.size - hui):
der.append((y[i+1]-y[i])/(x[i+1]-x[i]))
rrr = np.zeros(shape = (np.array(der).size)) + 10
figure = plt.figure(figsize=(12,8))
axes = figure.add_subplot (1, 1, 1)
plt.grid(True)
plt.title('Numerical derivative of MSE', fontsize=15)
plt.xlabel('Number of integration points', fontsize=15)
#plt.ylabel(, fontsize=15)
#plt.scatter(m_trapz_all, mse_all, label = 'MSE for all points', marker = "D",s=40)
#plt.scatter(m_trapz[4:15-hui], np.power(rrr,der), label = 'der', marker = "D", s=40)
plt.plot(m_trapz[:15-hui], np.power(rrr,der), color='blue', marker='x', linestyle='dashed', linewidth=0, markersize=16, label = 'der MSE')
#plt.plot(m_trapz[:15-hui], mse_means[:15-hui], color='black', marker='x', linestyle='dashed', linewidth=3, markersize=16, label = 'Mean MSE')
#plt.errorbar(m_trapz[:15-hui], mse_means[:15-hui], yerr=std_errs[:15-hui], ecolor='r', lw=2, capsize=15, mew = 3, zorder=3, label = 'Std.error of MSE', linestyle='None')
axes.set_yscale ('log')#, nonposy='clip')
axes.set_xscale ('log')#, nonposy='clip')
#plt.legend(loc=1, prop={'size': 25})
#print(std_errs)
In [15]:
figure = plt.figure(figsize=(12,8))
axes = figure.add_subplot (1, 1, 1)
plt.grid(True)
plt.title('MSE vs number of integration points. 5 sigmoids, 20 train points ', fontsize=15)
plt.xlabel('Number of integration points', fontsize=15)
plt.ylabel('MSE', fontsize=15)
#plt.scatter(m_trapz_all, mse_all, label = 'MSE for all points', marker = "D",s=40)
plt.plot(m_trapz[:15], mse_means[:15], color='black', marker='x', linestyle='dashed', linewidth=3, markersize=16, label = 'Mean MSE')
plt.errorbar(m_trapz[:15], mse_means[:15], yerr=std_errs[:15], ecolor='r', lw=2, capsize=15, mew = 3, zorder=3, label = 'Std.error of MSE', linestyle='None')
#axes.set_yscale ('log')#, nonposy='clip')
#axes.set_xscale ('log')#, nonposy='clip')
plt.legend(loc=1, prop={'size': 25})
#print(std_errs)
Out[15]:
In [16]:
x = m_trapz[:15]
y = mse_means[:15]
p = np.polyfit(m_trapz[:15], mse_means[:15], 3)
f = np.poly1d(p)
figure = plt.figure(figsize=(12,8))
axes = figure.add_subplot (1, 1, 1)
plt.grid(True)
plt.plot(x, y)
plt.plot(x, f(x))
#axes.set_yscale ('log')#, nonposy='clip')
#axes.set_xscale ('log')#, nonposy='clip')
Out[16]:
In [ ]:
In [ ]: