In [1]:
%matplotlib inline
import os
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
from collections import defaultdict
sns.set(style="darkgrid")
In [3]:
#from exp_utils import collect_experiment_data, summarize_experiment_data
import exp_utils
#source1 = '/home/ruben/playground/HFO/experiments/testResultFiles/2016_09_12-10.42.14_SARSA_1_10'
#source2 = '/home/ruben/playground/HFO/experiments/testResultFiles/SARSA'
#source3 = '/home/ruben/playground/HFO/experiments/testResultFiles/AdHocVisit'
source1 = '/home/ruben/playground/HFO/experiments/testResultFiles/2016_09_xx-xx.xx.20_SARSATile_1_20'
source1 = '/home/leno/HFO/experiments/testResultFiles/2016_09_xx-xx.xx.20_SARSATile_1_20'
#source2 = '/home/ruben/playground/HFO/experiments/testResultFiles/sortedSARSATile'
source2 = '/home/ruben/playground/HFO/experiments/testResultFiles/2016_09_14-02.07.41_Torrey_1_20'
source2 = '/home/leno/HFO/experiments/testResultFiles/2016_09_14-02.07.41_Torrey_1_20'
#source3 = '/home/ruben/playground/HFO/experiments/testResultFiles/2016_09_13-15.13.06_AdHocTD_1_10'
source3 = '/home/ruben/playground/HFO/experiments/testResultFiles/sortedAdHocVisit1'
source3 = '/home/leno/HFO/experiments/testResultFiles/sortedAdHocVisit1'
#source4 = '/home/ruben/playground/HFO/experiments/testResultFiles/sortedAdHocVisit'
#source4 = '/home/ruben/playground/HFO/experiments/testResultFiles/2016_09_14-12.01.47_AdHocVisit_1_20'
source4 = '/home/ruben/playground/HFO/experiments/testResultFiles/2016_09_14-20.54.40_AdHocTD_1_15'
source4 = '/home/leno/HFO/experiments/testResultFiles/2016_09_14-20.54.40_AdHocTD_1_15'
#exp_utils.collect_experiment_data(source4, runs = 7)
#exp_utils.summarize_experiment_data(source4)
exp_utils.draw_graph(source1=source1, source2=source2, source3=source3, #source4=source4,
name1="NoAdvice", name2="Teacher-Student", #name4="AdHocTD",
name3="AdHocVisit",ci=False)
exp_utils.draw_graph(source1=source1, source2=source2, source3=source3, #source4=source4,
name1="SARSATile", name2="Torrey", #name4="AdHocTD",
name3="AdHocVisit", ci=False, what="__SUMMARY_goaltimes")
exp_utils.draw_graph(source1=source1, source2=source2, source3=source3, #source4=source4,
name1="SARSATile", name2="Torrey",
#name4="AdHocTD",
name3="AdHocVisit", ci=False, what="__SUMMARY_budgets")
In [ ]:
In [ ]:
for run in range(1,21):
for agent in range(1,4):
with open('/home/ruben/playground/HFO/experiments/testResultFiles/2016_09_12-21.15.35_Torrey_1_20/_0_'+str(run)+'_AGENT_'+str(agent)+'_RESULTS_eval') as f:
lines = f.readlines()
if len(lines) != 52:
print ('Not enough lines in: _0_%d_AGENT_%d_RESULTS_eval' % (run, agent))
for line in lines:
if len(line.split(',')) != 4:
print('Not enough values in file: _0_%d_AGENT_%d_RESULTS_eval' % (run, agent))
#with open('/home/ruben/playground/HFO/experiments/testResultFiles/AdHocVisit/__EVAL_goaltimes') as f:
#with open('/home/ruben/playground/HFO/experiments/testResultFiles/2016_09_12-21.15.35_Torrey_1_20/__EVAL_goaltimes') as f:
# lines = f.readlines()
#for line in lines:
# print(len(line.split(',')))
In [ ]:
'''
from collections import defaultdict
data = defaultdict(list)
#data[(10,0)] = []
data[(10,0)].append(1)
data[(10,0)].append(2)
print data[(10,0)]
'''
a = np.array([1,2])
b = np.array([])
print sum(a.shape)
for i in range(sum(a.shape)):
#print i
print a[i]
import csv
with open('eggs.csv', 'wb') as csvfile:
spamwriter = csv.writer(csvfile)
spamwriter.writerow("bla,bla,bla")
spamwriter.writerow(("bla,bla,bla"))
spamwriter.writerow(("bla","bla","bla"))
blub = ["bla","bla","bla"]
spamwriter.writerow((blub))
spamwriter.writerow(("bla", blub))
In [ ]:
runs = 16
agentNames = []
countAgents = 0
for run in range(1,runs+1):
#experimentDir = '/home/ruben/playground/HFO/experiments/EVAL/2016_09_14-12.01.47_AdHocVisit_1_20/'
#experimentDir = '/home/ruben/playground/HFO/experiments/EVAL/2016_09_14-20.54.40_AdHocTD_1_20'
#experimentDir = '/home/ruben/playground/HFO/experiments/testResultFiles/2016_09_xx-xx.xx.20_SARSATile_1_20'
experimentDir = '/home/ruben/playground/HFO/experiments/testResultFiles/2016_09_14-12.01.47_AdHocVisit_1_20'
agentName = '_0_'+str(run)+'_AGENT_1_RESULTS_eval'
agentPath = os.path.join(experimentDir, agentName)
if os.path.isfile(agentPath):
#print(agentName)
agentNames.append(agentPath)
countAgents += 1
print('Found %d agents' % len(agentNames))
t = []
gp = []
tg = []
b = []
for agentName in agentNames:
#print(agentName)
_t, _gp, _tg, _b = np.loadtxt(open(agentName, "rb"), skiprows=1, delimiter=",", unpack=True)
#print("trials:\n%s" % str(trials))
#print("goalPercentage:\n%s" % str(goalPercentage))
#print("timeToGoal:\n%s" % str(timeToGoal))
#print("budget:\n%s" % str(budget))
t.append(_t)
gp.append(_gp)
tg.append(_tg)
b.append(_b)
t = np.asarray(t)
gp = np.asarray(gp)
#gp2 = gp1+10
#gp3 = gp1-10
tg = np.asarray(tg)
b = np.asarray(b)
In [ ]:
X = t[0]
plt.figure(figsize=(10,6), dpi=80)
plt.xlim(0, X.max()*1.05)
plt.ylim(0, 100)
for i in range(1, runs+1):
if i not in [2,3,5,6,7,13,14,15,16]:
#print(i, X.shape, gp[i-1].shape)
plt.plot(X,gp[i-1],label=str(i))
plt.title('Goal Percentage per Trial')
plt.legend(loc='upper left')
plt.xlabel('Trials')
plt.ylabel('Goal %')
plt.show()
plt.figure(figsize=(10,6), dpi=80)
plt.xlim(0, X.max()*1.05)
plt.ylim(0, 100)
for i in range(1, runs+1):
if i not in [1,6,2,4,3,5,8,9,10,11,12,7,14,15]:
#print(i, X.shape, gp[i-1].shape)
plt.plot(X,gp[i-1],label=str(i))
plt.title('Goal Percentage per Trial')
plt.legend(loc='upper left')
plt.xlabel('Trials')
plt.ylabel('Goal %')
plt.show()
In [ ]:
X = t[0]
Y1, Y2, Y3 = tg[0], tg[1], tg[2]
plt.figure(figsize=(10,6), dpi=80)
plt.xlim(0, X.max()*1.05)
plt.plot(X,Y1,label='tg1', color='blue')
plt.plot(X,Y2,label='tg2', color='green')
plt.plot(X,Y3,label='tg3', color='red')
plt.title('Time to Goal per Trial')
plt.legend(loc='upper left')
plt.xlabel('Trials')
plt.ylabel('Time to Goal')
plt.show()
In [ ]:
In [ ]:
filename = '/home/ruben/playground/HFO/experiments/LOGS/2016_09_09-17.18.41_SARSA/SARSA_1_7_eval'
trials, goalPercentage, timeToGoal, budget = numpy.loadtxt(open(filename, "rb"), skiprows=1, delimiter=",", unpack=True)
print("trials:\n%s" % str(trials))
print("goalPercentage:\n%s" % str(goalPercentage))
print("timeToGoal:\n%s" % str(timeToGoal))
print("budget:\n%s" % str(budget))
In [ ]:
import seaborn as sns
import pandas as pd
sns.set(style="darkgrid")
gammas = sns.load_dataset("gammas")
print type(gammas)
print type(trials)
goalPercentage2 = goalPercentage + 10
goalPercentage3 = goalPercentage - 10
myDict = {'date': trials, 'gp1': goalPercentage, 'gp2': goalPercentage2, 'gp3': goalPercentage3}
myDF = pd.DataFrame(myDict)
print myDF
myDFM = pd.melt(myDF, id_vars=['date','sub'], value_vars=['gp1', 'gp2', 'gp3'])
#myDF.set_index('date').plot()
#data = [goalPercentage,goalPercentage2,goalPercentage3]
sns.tsplot(data=myDF, ci=[0,100], time='date', value='gp3')
In [ ]:
import numpy as np
N=100
num_runs = 3
out = []
for k in range(num_runs):
data = np.random.rand(N,3) + np.sin(np.arange(N)/5)[:,np.newaxis]
data = np.hstack([np.arange(N)[:,np.newaxis],data])
data = np.hstack([np.zeros(N)[:,np.newaxis]+k,data])
out.append(data)
print type(out), len(out), type(out[0]), out[0].shape
data = np.vstack(out)
print type(data), data.shape
df = pd.DataFrame(data, columns=['sub','t', 'x', 'y', 'z'])
df
dfm = pd.melt(df, id_vars=['t','sub'], value_vars=['x', 'y', 'z'])
dfm
sns.tsplot(time='t',
value='value',
condition='variable',
data=dfm,
err_style="boot_traces",
unit='sub',
n_boot=50)
In [ ]:
In [ ]: