-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis.py
211 lines (159 loc) · 7.3 KB
/
analysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import os
import sys
import glob
# Pandas for managing datasets
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from seaborn.relational import _LinePlotter
variant_names = ["random_exploration/",
"vanilla_me/",
"direct_model_archcond/",
#"dyn_model_det_archcond/",
#"dyn_model_probens_archcond/",
"dyn_model_probens_archcond_2/",
]
def get_files(variant, filename=""):
#if(len(arg)!=0):
# base = arg[0]
#else:
# base = "."
base = "./hpc_results/hexapod_exp_015/"
#base = "./hpc_results/pushing_ee_025/"
if filename != "":
filename ="/"+filename
#return glob.glob(base+'/results_' + variant+"_"+exp+'/202*/' + filename)
return glob.glob(base+"/"+variant+"/*")
def collect_data(filename = "log_file.dat",):
model_fields = ["gen","num_evals","num_model_evals","archive_size",
"best_fit", "qd_score", "mean_fit", "median_fit",
"per_5", "per_95",
"true_pos", "false_pos", "false_neg", "true_neg"]
baseline_fields = ["gen","num_evals","archive_size",
"best_fit", "qd_score", "mean_fit", "median_fit",
"per_5", "per_95",
"true_pos", "false_pos", "false_neg", "true_neg"]
data = pd.DataFrame()
interpolated_data = pd.DataFrame()
for variant in variant_names:
files = get_files(variant,filename)
print(files)
if(len(files)==0):
print("NO file called " + filename + " for "+exp+" "+variant)
continue
# use a data tmp to store all the data for one variant for one experiment
# append the data tmp to the full dataframe file later on
data_tmp = pd.DataFrame()
data_tmp_2 = pd.DataFrame() # for interpolation data
for run, f in enumerate(files):
if ("random_exploration" in f) or ("vanilla_me" in f):
fields = baseline_fields
print("Baseline field: ", f)
else:
fields = model_fields
#fields = model_fields
tmp = pd.read_csv(f,delim_whitespace=True,names=fields)
#sns_plot = sns.lineplot(x="num_evals", y="archive_size",data=tmp)
tmp['run']=run # replication of the same variant
if "dyn_model_probens_archcond_2" in f:
data_int = interpolate_data(tmp, end_point=80000) #interpolated data we want
else:
data_int = interpolate_data(tmp) #interpolated data we want
#sns_plot = sns.lineplot(x="num_evals", y="archive_size", data=data_int, marker="x", markersize=3, 'k')
data_tmp=pd.concat([data_tmp, tmp], ignore_index=True)
data_tmp_2=pd.concat([data_tmp_2, data_int], ignore_index=True)
plt.show()
# add variant and experinment name as fieds as well
data_tmp['variant'] = variant
data_tmp_2['variant'] = variant
#data_tmp['exp'] = exp
# all variants added into same big overall dataframe and variant used as hue in plot
data = data.append(data_tmp)
interpolated_data = interpolated_data.append(data_tmp_2)
return data, interpolated_data
def interpolate_data(data, end_point=1000001):
data_points = pd.DataFrame()
#end_point = data["num_evals"].iloc[-1]
#end_point = 1000000
#print(end_point)
interested_points = np.arange(0,end_point,200)
data_points["num_evals"] = interested_points
#print(data_points.shape)
data = data.append(data_points)
data = data.sort_values(by="num_evals")
#print(data)
data['archive_size'] = data['archive_size'].interpolate(method='linear')
data['qd_score'] = data['qd_score'].interpolate(method='linear')
#print(data)
interested_data = data.loc[data['num_evals'].isin(interested_points)]
interested_data = interested_data[pd.isnull(interested_data["mean_fit"])]
#interested_data = interested_data.round(2)
#print(interested_data)
#s = interested_data.to_csv("interpolated_data.csv")
#print(s)
return interested_data
def plot():
data, interpolated_data = collect_data()
# qd score is the sum of fitness
# to normalise it - sum each value of fitness by pi and divide by pi
data["qd_score_norm"] = data["qd_score"] + data["archive_size"]*np.pi
interpolated_data["qd_score_norm"] = (interpolated_data["qd_score"] + interpolated_data["archive_size"]*np.pi)/np.pi
'''
# stats
data["precision"] = data["true_pos"]/(data["true_pos"]+data["false_pos"])
data["recall"] = data["true_pos"]/(data["true_pos"]+data["false_neg"])
data["num_pos"] = data["true_pos"] + data["false_pos"]
data["num_neg"] = data["true_neg"] + data["false_neg"]
# normalize data
data["true_pos_norm"] = data["true_pos"]/200
data["false_pos_norm"] = data["false_pos"]/200
data["false_neg_norm"] = data["false_neg"]/200
data["true_neg_norm"] = data["true_neg"]/200
'''
sns.set(style="whitegrid")
#sns.palplot(sns.color_palette("colorblind"))
# Plot the responses for different events and regions
def first_second_third_quartile(self, vals, grouper, units=None):
# Group and get the aggregation estimate
grouped = vals.groupby(grouper, sort=self.sort)
est = grouped.agg('median')
min_val = grouped.quantile(0.25)
max_val = grouped.quantile(0.75)
cis = pd.DataFrame(np.c_[min_val, max_val],
index=est.index,
columns=["low", "high"]).stack()
# Unpack the CIs into "wide" format for plotting
if cis.notnull().any():
cis = cis.unstack().reindex(est.index)
else:
cis = None
return est.index, est, cis
for item in ["archive_size"]:
#for item in ["qd_score_norm"]:
#for item in ["archive_size","best_fit", "mean_fit"]:
#for item in ["archive_size","num_pos","num_neg","precision", "recall", "true_pos_norm","false_pos_norm", "false_neg_norm","true_neg_norm"]:
#for item in ["num_pos", "num_neg"]:
#for item in ["true_pos_norm","false_pos_norm", "false_neg_norm","true_neg_norm"]:
#for item in ["true_pos","false_pos", "false_neg","true_neg"]:
#for item in ["false_neg","true_neg"]:
#for item in ["true_neg"]:
plt.figure()
my_lineplot=sns.lineplot
_LinePlotter.aggregate = first_second_third_quartile
#sns_plot = sns.lineplot(x="num_evals", y=item,
# hue="variant",
# data=data)
#sns_plot = sns.lineplot(x="gen", y=item,
# hue="variant",
# data=data )
sns_plot = sns.lineplot(x="num_evals", y=item,
hue="variant",
data=interpolated_data)
print("HERE")
#plt.title(exp+"_"+item)
#plt.savefig("./stats_plots/direct_nn/progress_me_baseline"+item+".svg")
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left')
plt.vlines(50000, ymin=0, ymax=1000, linestyles="dashed")
plt.show()
plot()