Commit 23811425 authored by Daniel Lukats's avatar Daniel Lukats

final colorscheme and x axis adjustments

parent a77493a6
......@@ -14,8 +14,12 @@ from matplotlib.lines import Line2D
@dataclass
class Run:
steps: List[int]
values: Union[List[float], np.ndarray]
steps: np.ndarray
values: np.ndarray
def get_dict(self,
):
return {'steps': self.steps.tolist(), 'values': self.steps.tolist()}
@dataclass
......@@ -25,6 +29,10 @@ class Experiment:
runs: List[Run] = field(default_factory=lambda: list())
baseline: Run = None
def get_dict(self,
):
return self.__dict__
def save(self,
):
"""
......@@ -41,7 +49,7 @@ class Experiment:
Converts self to json
:return:
"""
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True)
return json.dumps(self, default=lambda o: o.get_dict(), sort_keys=True)
def score(self):
path = os.path.join(self.path, 'final_score')
......@@ -94,20 +102,17 @@ def create_plot(experiment: Experiment,
:param plot:
:return:
"""
colors = ['#009988', '#33BBEE', '#0077BB', '#EE7733']
# colors = ['#307B3B', '#CAA023', '#254796', '#D01B88']
colors = ['#307B3B', '#CAA023', '#254796', '#F1009A']
setup()
data_x = []
data_y = []
for i, run in enumerate(experiment.runs):
plt.scatter(run.steps, run.values, label=f'Run {i+1}', color=colors[i], s=18)
data_x += run.steps
data_y += run.values
plt.plot(comparison[0], comparison[1], color='black', label='Trendline')
plt.title(f'{experiment.game}')
plt.xlabel('Time step')
plt.ylabel('Score')
make_legend(colors, trend=False)
plt.tight_layout(pad=1.04)
plt.tight_layout(pad=1.02)
if plot:
plt.show()
......@@ -135,11 +140,11 @@ def make_legend(colors: List,
def create_trendline(data: Experiment,
window: int,
):
data_x = []
data_y = []
data_x = np.empty(0)
data_y = np.empty(0)
for run in data.runs:
data_x += run.steps
data_y += run.values
data_x = np.concatenate((data_x, run.steps))
data_y = np.concatenate((data_y, run.values))
values = deque(maxlen=window)
data_x, data_y = zip(*sorted(zip(data_x, data_y), key=operator.itemgetter(0)))
trend_y = []
......@@ -149,17 +154,25 @@ def create_trendline(data: Experiment,
return data_x[:-window//2], trend_y[window//2:]
def parse(directory: str):
def parse(directory: str,
experiment: str = None,
):
"""
:param directory:
:return:
"""
if experiment is not None and '16_envs' in experiment:
step_scale = 16
elif experiment is not None and '4_envs' in experiment:
step_scale = 4
else:
step_scale = 8
acc = EventAccumulator(directory)
acc.Reload()
_, steps, values = zip(*acc.Scalars('Episode/avg_reward'))
config = str(acc.Tensors('Config/text_summary')[0][2].string_val)[5:-2].replace('\\n', '\n')
return steps, values, config
return np.array(steps) * step_scale, np.array(values), config
def create_default_config_trends(data_dir: str):
......@@ -205,9 +218,9 @@ def main(root_dir: str,
'Pong': Experiment(path, 'Pong'),
'Seaquest': Experiment(path, 'Seaquest'),
'SpaceInvaders': Experiment(path, 'SpaceInvaders')}
runs = sorted(os.listdir(os.path.join(root_dir, experiment)))
runs = sorted(os.listdir(path))
for run in runs:
steps, values, config = parse(os.path.join(path, run))
steps, values, config = parse(os.path.join(path, run), experiment)
game = str(run.split('-')[0])
data[game].runs.append(Run(steps, values))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment