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_preparation3/")
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
In [8]:
os.chdir("../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)
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)
res_correct1 = res1[res1['Model info.n_sig'] < 14]
res_correct1 = res_correct1[res_correct1['Model info.m_train'] >= 21]
res_n_sig5_1 = res_correct1[res_correct1['Model info.n_sig'] == 5]
m_train_all_1 = np.array(res_n_sig5_1['Model info.m_train'].tolist())
mse_all_1 = np.array(res_n_sig5_1['Out info.MSE'].tolist())
mse_means_1 = []
std_errs_1 = []
h = 8
for i in range(8):
ds = res_n_sig5_1[0+h*i:8+h*i]
mse_l = np.array(ds['Out info.MSE'].tolist())
mse_means_1.append(np.mean(mse_l))
std_errs_1.append(np.std(mse_l))
mse_means_1 = np.array(mse_means_1)
my_set_1 = set(m_train_all_1)
m_trains_1 = np.array(sorted( list(my_set_1) ) )
print(m_trains_1.shape)
print(mse_means_1.shape)
In [11]:
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 = 20
for i in range(20):
ds = res_n_sig5[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))
mse_means = np.array(mse_means)
my_set = set(m_train_all)
m_trains = np.array( sorted( list(my_set) ) )
print(m_trains.shape)
print(mse_means.shape)
In [13]:
m_trains = np.concatenate((m_trains, m_trains_1))
mse_means = np.concatenate((mse_means, mse_means_1))
m_train_all = np.concatenate((m_train_all, m_train_all_1))
mse_all = np.concatenate((mse_all, mse_all_1))
std_errs = np.concatenate((std_errs, std_errs_1))
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 = 'Errorbar', linestyle='None')
axes.set_yscale ('log', nonposy='clip')
plt.legend(loc=1, prop={'size': 15})
#print(std_errs)
Out[13]:
In [ ]:
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 = 'Errorbar', linestyle='None')
axes.set_yscale ('log', nonposy='clip')
plt.legend(loc=1, prop={'size': 15})
print(std_errs)
In [ ]:
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 [ ]:
#res_correct
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: