A basic notebook to generate plots from training logs. See Logger
class in utils.py
.
Python Notebook by Patrick Coady: Learning Artificial Intelligence
In [1]:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
%matplotlib inline
plt.rcParams["figure.figsize"] = (10,5)
plt.style.use('ggplot')
In [2]:
def df_plot(dfs, x, ys, ylim=None, legend_loc='best'):
""" Plot y vs. x curves from pandas dataframe(s)
Args:
dfs: list of pandas dataframes
x: str column label for x variable
y: list of str column labels for y variable(s)
ylim: tuple to override automatic y-axis limits
legend_loc: str to override automatic legend placement:
'upper left', 'lower left', 'lower right' , 'right' ,
'center left', 'center right', 'lower center',
'upper center', and 'center'
"""
if ylim is not None:
plt.ylim(ylim)
for df, name in dfs:
name = name.split('_')[1]
for y in ys:
plt.plot(df[x], df[y], linewidth=2,
label=name + ' ' + y.replace('_', ''))
plt.xlabel(x.replace('_', ''))
plt.legend(loc=legend_loc)
plt.show()
In [3]:
# ENTER LIST OF LOG FILENAMES HERE:
filepaths = ['log-files/Hopper-v1/Jul-18_14:30:37/log.csv',
'log-files/Hopper-v1/Jul-18_14:51:02/log.csv']
dataframes = []
names = []
for filepath in filepaths:
names.append(filepath.split('/')[2])
dataframes.append(pd.read_csv(filepath))
data = list(zip(dataframes, names))
In [4]:
df_plot(data, '_Iteration', ['_MeanReward'])
df_plot(data, '_Iteration', ['KL'])
df_plot(data, '_Iteration', ['ExplainedVarOld'])
df_plot(data, '_Iteration', ['PolicyLoss'], ylim=(-0.05, 0))
In [5]:
df_plot(data, '_Iteration', ['_mean_discrew'])
df_plot(data, '_Iteration', ['_std_discrew'])
df_plot(data, '_Iteration', ['_mean_adv'])
df_plot(data, '_Iteration', ['_std_adv'])
In [6]:
df_plot(data, '_Iteration', ['_mean_obs'])
df_plot(data, '_Iteration', ['_min_obs'])
df_plot(data, '_Iteration', ['_max_obs'])
In [7]:
df_plot(data, '_Iteration', ['_mean_act'])
df_plot(data, '_Iteration', ['_min_act'])
df_plot(data, '_Iteration', ['_max_act'])
df_plot(data, '_Iteration', ['_std_act'])
In [8]:
df_plot(data, '_Iteration', ['PolicyEntropy'])
In [ ]: