backgammon/plot.py

57 lines
1.4 KiB
Python
Raw Normal View History

2018-03-11 23:12:03 +00:00
import os
2018-03-08 15:36:16 +00:00
import pandas as pd
from datetime import datetime
import csv
2018-03-11 23:12:03 +00:00
import datetime
2018-03-08 15:36:16 +00:00
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
import matplotlib.dates as mdates
2018-03-11 23:12:03 +00:00
train_headers = ['timestamp', 'eps_train', 'eps_trained_session', 'sum', 'mean']
eval_headers = ['timestamp', 'method', 'eps_train', 'eval_eps_used', 'sum', 'mean']
2018-03-08 16:13:25 +00:00
2018-03-11 23:12:03 +00:00
model_path = 'models'
2018-03-08 15:36:16 +00:00
2018-03-08 16:13:25 +00:00
2018-03-11 23:12:03 +00:00
def dataframes(model_name):
def df_timestamp_to_datetime(df):
df['timestamp'] = df['timestamp'].map(lambda t: datetime.datetime.fromtimestamp(t))
return df
log_path = os.path.join(model_path, model_name, 'logs')
raw_dfs = [ pd.read_csv(os.path.join(log_path, 'eval.log'), sep=';', names=eval_headers),
pd.read_csv(os.path.join(log_path, 'train.log'), sep=';', names=train_headers) ]
dfs = [ df_timestamp_to_datetime(df) for df in raw_dfs ]
dataframes = {
'eval': dfs[0],
'train': dfs[1]
}
return dataframes
2018-03-08 15:36:16 +00:00
2018-03-08 16:13:25 +00:00
2018-03-11 23:12:03 +00:00
if __name__ == '__main__':
fig, ax = plt.subplots(1, 1)
plt.ion()
plt.title('Mean over episodes')
plt.xlabel('Episodes trained')
plt.ylabel('Mean')
plt.grid(True)
#ax.set_xlim(left=0)
ax.set_ylim([-2, 2])
plt.show()
while True:
2018-03-22 14:30:47 +00:00
df = dataframes('a')['eval']
2018-03-11 23:12:03 +00:00
print(df)
x = df['eps_train']
y = df['mean']
2018-03-08 16:13:25 +00:00
2018-03-11 23:12:03 +00:00
plt.scatter(x, y, c=[[1, 0.5, 0]])
#fig.canvas.draw()
plt.pause(2)