In [1]:
import research as r
import scipy
import pandas
def fitness_plots(path, treatment):
D = r.load_files(r.find_files(path, treatment+"_.*/fitness.dat"))
D['rmse'] = 100.0 / D['max_fitness'] - 1.0
figure()
for i,g in D.groupby('trial'):
plot(g['update'], g['rmse'])
ylabel('Sum RMSE, t=1:8')
xlabel('Update')
figure()
r.quick_ciplot('update','rmse', D)
ylabel('Sum RMSE, t=1:8')
xlabel('Update')
final = D[D['update']==D['update'].max()]
print "\nDominant fitness:"
print final.ix[final['rmse'].idxmin()]
return D
def rmse_boxplots(path, treatment):
figure()
D = r.load_files(r.find_files(path, treatment+"_.*/sunspot_test_rmse.dat"))
B = D.boxplot(column=['tplus1'])
ylabel("RMSE per horizon")
print "\nMinimum testing RMSE:"
print D.ix[D['total_rmse'].idxmin()]
return D
def predictions(path,R):
T = R.ix[R['total_rmse'].idxmin()]
path += "/" + T["treatment"] + "_" + T["trial"]
D = r.load_files(r.find_files(path, "sunspot_test_detail.dat"))
left, width = 0.1, 0.8
rect1 = [left, 0.25, width, 0.8]
rect2 = [left, 0.1, width, 0.1]
for i in range(1,2):
fig=figure()
ax1 = fig.add_axes(rect1)
ax2 = fig.add_axes(rect2, sharex=ax1)
for label in ax1.get_xticklabels():
label.set_visible(False)
p1 = ax1.plot(D['observed'], color='blue', label='observed')
p2 = ax1.plot(D['tplus'+str(i)], color='red', label='t+'+str(i))
ax1.legend()
ax1.set_ylabel('SSN')
p3 = ax2.vlines(range(0,len(D)), 0, abs(D['observed']-D['tplus'+str(i)]))
pyplot.locator_params(axis='y', nbins=2)
ax2.set_ylabel('Error')
ax2.set_xlabel('Day')
return D
In [19]:
def rmse(D):
obs = D['observed']
pre = D['tplus1']
error = obs[1:] - pre[:-1]
return sqrt(mean(error**2))
In [24]:
R = rmse_boxplots('/Users/dk/research/var/sunspot/006-daily','ta0') # 2009-2010
R = rmse_boxplots('/Users/dk/research/var/sunspot/006-daily','tb0') # 2009-2010
R = rmse_boxplots('/Users/dk/research/var/sunspot/006-daily','tc0') # 2009-2010
R = rmse_boxplots('/Users/dk/research/var/sunspot/006-daily','td0') # 2009-2010
#P = predictions('/Users/dk/research/var/sunspot/006-daily', R)
#print rmse(D)
#savefig("tplus1_predictions_td0_18.pdf",pad_inches=0, bbox_inches='tight')
In [4]:
D = fitness_plots('/Users/dk/research/var/sunspot/006-daily','ta0') # 1997-1998
In [5]:
D = fitness_plots('/Users/dk/research/var/sunspot/006-daily','tb0') # 2000-2001
In [6]:
D = fitness_plots('/Users/dk/research/var/sunspot/006-daily','tc0') # 2003-2004
In [8]:
D = fitness_plots('/Users/dk/research/var/sunspot/006-daily','td0') # 2009-2010