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/approx/main2/")
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)
    df_list.append(a)
    os.chdir(origin_path)
res1 = pd.concat(df_list,ignore_index=True)

In [7]:
res_correct = res1
res_correct_2d = res_correct[res_correct['Model info.dim'] == 2]
res_correct_3d = res_correct[res_correct['Model info.dim'] == 3]

In [28]:
res_correct_2d[res_correct_2d['Out info.MSE'] < 0.428e-2]


Out[28]:
Model info.a Model info.b Model info.dim Model info.eps Model info.iters Model info.k Model info.m Model info.max_t Model info.n_sig Out info.J_fin Out info.MSE Out info.Std Out info.Time
80 0 6.283185 2 1.000000e-09 100000 1 10 400 21 0.003628 0.003628 0.060538 125.347851
89 0 6.283185 2 1.000000e-09 100000 1 10 400 23 0.003296 0.003296 0.057704 163.990935
191 0 6.283185 2 1.000000e-09 100000 1 10 400 48 0.003279 0.003279 0.057552 169.927181

In [30]:
res_correct_3d[res_correct_3d['Out info.MSE'] < 0.4e-1]


Out[30]:
Model info.a Model info.b Model info.dim Model info.eps Model info.iters Model info.k Model info.m Model info.max_t Model info.n_sig Out info.J_fin Out info.MSE Out info.Std Out info.Time
213 0 6.283185 3 1.000000e-09 100000 1 10 660 14 0.039151 0.039151 0.197965 219.195033
226 0 6.283185 3 1.000000e-09 100000 1 10 660 27 0.037022 0.037022 0.192507 296.150805
231 0 6.283185 3 1.000000e-09 100000 1 10 660 32 0.037736 0.037736 0.194354 295.160253
234 0 6.283185 3 1.000000e-09 100000 1 10 660 35 0.039959 0.039959 0.199996 306.855275
237 0 6.283185 3 1.000000e-09 100000 1 10 660 38 0.039623 0.039623 0.199155 318.608563

In [9]:
matplotlib.rcParams['text.usetex'] = True
matplotlib.rcParams['text.latex.unicode'] = True
matplotlib.rcParams['text.latex.preamble'] = [r'\usepackage{amsmath}']

In [11]:
res_correct = res_correct_2d
m_sig_all = np.array(res_correct['Model info.n_sig'].tolist())
mse_all = np.array(res_correct['Out info.MSE'].tolist())
mse_means = []
std_errs = []
h = 4
for i in range(50):
    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_sig_all)
m_sig = sorted( list(my_set) ) 

figure = plt.figure(figsize=(12,8))
axes = figure.add_subplot (1, 1, 1)
plt.grid(True)
plt.title(r'$\sigma_{\text{sol}}^2$ vs number of neurons. 2D task', fontsize=25)
plt.xlabel('Number of neurons', fontsize=25)
plt.ylabel(r'$\sigma_{\text{sol}}^2$', fontsize=25)
plt.scatter(m_sig_all, mse_all, label = r'$\sigma_{\text{sol}}^2$ for all points', marker = "D",s=40)
plt.plot(m_sig, mse_means, color='black', marker='x', linestyle='dashed', linewidth=3, markersize=16, label = r'Mean $\sigma_{\text{sol}}^2$')
plt.errorbar(m_sig, mse_means, yerr=std_errs, ecolor='r', lw=2, capsize=15, mew = 3, zorder=3, label = r'Std.error of $\sigma_{\text{sol}}^2$', linestyle='None')

axes.set_yscale ('log')
plt.legend(loc=1, prop={'size': 20})


Out[11]:
<matplotlib.legend.Legend at 0x7faa1454dc18>

In [14]:
res_correct = res_correct_3d
m_sig_all = np.array(res_correct['Model info.n_sig'].tolist())
mse_all = np.array(res_correct['Out info.MSE'].tolist())
mse_means = mse_all
m_sig = m_sig_all


#mse_means = []
#std_errs = []
#h = 4
#for i in range(50):
#    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_sig_all)
#m_sig = sorted( list(my_set) ) 

figure = plt.figure(figsize=(12,8))
axes = figure.add_subplot (1, 1, 1)
plt.grid(True)
plt.title(r'$\sigma_{\text{sol}}^2$ vs number of neurons. 3D task', fontsize=25)
plt.xlabel('Number of neurons', fontsize=25)
plt.ylabel(r'$\sigma_{\text{sol}}^2$', fontsize=25)
#plt.scatter(m_sig_all, mse_all, label = r'$\sigma_{\text{sol}}^2$ for all points', marker = "D",s=40)
plt.plot(m_sig, mse_means, color='black', marker='x', linestyle='dashed', linewidth=3, markersize=16, label = r'$\sigma_{\text{sol}}^2$')
#plt.errorbar(m_sig, mse_means, yerr=std_errs, ecolor='r', lw=2, capsize=15, mew = 3, zorder=3, label = r'Std.error of $\sigma_{\text{sol}}^2$', linestyle='None')

axes.set_yscale ('log')
plt.legend(loc=1, prop={'size': 20})


Out[14]:
<matplotlib.legend.Legend at 0x7faa140a0eb8>

In [ ]:


In [ ]:


In [18]:
m_sig_all = np.array(res_correct['Model info.n_sig'].tolist())
mse_all = np.array(res_correct['Out info.MSE'].tolist())
mse_means = []
std_errs = []
h = 4
for i in range(50):
    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_sig_all)
m_sig = sorted( list(my_set) ) 

figure = plt.figure(figsize=(12,8))
axes = figure.add_subplot (1, 1, 1)
plt.grid(True)
plt.title(r'$\sigma_{\text{sol}}^2$ vs number of neurons. One-dimensional task', fontsize=25)
plt.xlabel('Number of neurons', fontsize=25)
plt.ylabel(r'$\sigma_{\text{sol}}^2$', fontsize=25)
plt.scatter(m_sig_all, mse_all, label = r'$\sigma_{\text{sol}}^2$ for all points', marker = "D",s=40)
plt.plot(m_sig, mse_means, color='black', marker='x', linestyle='dashed', linewidth=3, markersize=16, label = r'Mean $\sigma_{\text{sol}}^2$')
plt.errorbar(m_sig, mse_means, yerr=std_errs, ecolor='r', lw=2, capsize=15, mew = 3, zorder=3, label = r'Std.error of $\sigma_{\text{sol}}^2$', linestyle='None')

axes.set_yscale ('log')
plt.legend(loc=1, prop={'size': 20})


Out[18]:
<matplotlib.legend.Legend at 0x7ff61e9a90b8>

In [ ]:


In [ ]:


In [ ]:
m_sig_all = np.array(res_correct['Model info.n_sig'].tolist())
J_all = np.array(res_correct['Out info.J_fin'].tolist())
J_means = []
std_errs = []
h = 4
for i in range(15):
    ds = res_correct[0+h*i:h+h*i]
    J_l = np.array(ds['Out info.J_fin'].tolist())
    J_means.append(np.mean(J_l))
    std_errs.append(np.std(mse_l))

my_set = set(m_sig_all)
m_sig = sorted( list(my_set) ) 



figure = plt.figure(figsize=(12,8))
axes = figure.add_subplot (1, 1, 1)
plt.grid(True)
plt.title('J_fin vs number of neurons', fontsize=15)
plt.xlabel('Number of neurons', fontsize=15)
plt.ylabel('J_fin', fontsize=15)
plt.scatter(m_sig_all, mse_all, label = 'J_fin 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 J_fin')
plt.errorbar(m_sig, mse_means, yerr=std_errs, ecolor='r', lw=2, capsize=15, mew = 3, zorder=3, label = 'Std.error of J_fin', linestyle='None')

axes.set_yscale ('log')
plt.legend(loc=1, prop={'size': 14})

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:
res_n_sig5 = res_correct[res_correct['Model info.m_train'] == 16]

#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=2, prop={'size': 19})
#print(std_errs)

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: