mirror of
https://github.com/wassname/DeepRL.git
synced 2026-09-09 11:13:47 +08:00
Update plotter and scheduler
This commit is contained in:
@@ -3,6 +3,7 @@ from .normalizer import *
|
||||
from .misc import *
|
||||
from .tf_logger import Logger
|
||||
from .plot import Plotter
|
||||
from .schedule import *
|
||||
import logging
|
||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s: %(message)s')
|
||||
logger = logging.getLogger('MAIN')
|
||||
|
||||
+4
-3
@@ -46,16 +46,17 @@ class Plotter:
|
||||
ts = ts[ts.l.cumsum() <= max_timesteps]
|
||||
tslist.append(ts)
|
||||
xy_list = [self.ts2xy(ts, x_axis) for ts in tslist]
|
||||
xy_list = [[x, y, self.window_func(x, y, episode_window, np.mean)] for x, y in xy_list]
|
||||
if episode_window:
|
||||
xy_list = [self.window_func(x, y, episode_window, np.mean) for x, y in xy_list]
|
||||
return xy_list
|
||||
|
||||
def plot_results(self, dirs, max_timesteps=1e8, x_axis=X_TIMESTEPS, episode_window=100, title=None):
|
||||
import matplotlib.pyplot as plt
|
||||
plt.ticklabel_format(axis='x', style='sci', scilimits=(1, 1))
|
||||
xy_list = self.load_results(dirs, max_timesteps, x_axis, episode_window)
|
||||
for (i, (x, y, smoothed)) in enumerate(xy_list):
|
||||
for (i, (x, y)) in enumerate(xy_list):
|
||||
color = Plotter.COLORS[i]
|
||||
plt.plot(smoothed[0], smoothed[1], color=color)
|
||||
plt.plot(x, y, color=color)
|
||||
plt.xlabel(x_axis)
|
||||
plt.ylabel("Episode Rewards")
|
||||
if title is not None:
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#######################################################################
|
||||
# Copyright (C) 2017 Shangtong Zhang(zhangshangtong.cpp@gmail.com) #
|
||||
# Permission given to modify the code as long as you keep this #
|
||||
# declaration at the top #
|
||||
#######################################################################
|
||||
|
||||
class ConstantSchedule:
|
||||
def __init__(self, val):
|
||||
self.val = val
|
||||
|
||||
def __call__(self):
|
||||
return self.val
|
||||
|
||||
class LinearSchedule:
|
||||
def __init__(self, start, end, steps):
|
||||
self.inc = (end - start) / float(steps)
|
||||
self.current = start
|
||||
self.end = end
|
||||
if end > start:
|
||||
self.bound = min
|
||||
else:
|
||||
self.bound = max
|
||||
|
||||
def __call__(self):
|
||||
val = self.current
|
||||
self.current = self.bound(self.current + self.inc, self.end)
|
||||
return val
|
||||
Reference in New Issue
Block a user