From 554e587ffde3e60d72aa2dd64f8cb2cdccf9cbf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoffer=20M=C3=BCller=20Madsen?= Date: Mon, 12 Mar 2018 00:12:03 +0100 Subject: [PATCH] somewhat working plots --- plot.py | 69 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/plot.py b/plot.py index f40f06e..e5b8228 100644 --- a/plot.py +++ b/plot.py @@ -1,36 +1,57 @@ -import sys +import os import pandas as pd from datetime import datetime import csv +import datetime import matplotlib.pyplot as plt import matplotlib.ticker as mtick import matplotlib.dates as mdates -from matplotlib.backends.backend_pdf import PdfPages -headers = ['Phase', 'Method', 'Start episodes', 'Episodes', 'Sum', 'Mean'] -fig, ax = plt.subplots(1, 1) +train_headers = ['timestamp', 'eps_train', 'eps_trained_session', 'sum', 'mean'] +eval_headers = ['timestamp', 'method', 'eps_train', 'eval_eps_used', 'sum', 'mean'] -plt.ion() -plt.title('Mean over episodes') -plt.xlabel('Episodes') -plt.ylabel('Mean') -plt.grid(True) +model_path = 'models' -#ax.set_xlim(left=0) -ax.set_ylim([-2, 2]) -plt.show() - -while True: - #df = pd.read_csv(sys.stdin, sep=";", names=headers) - df = pd.read_csv('log', sep=";", names=headers) - df['Total episodes'] = df['Start episodes'] + 100 - - print(df) +def dataframes(model_name): + def df_timestamp_to_datetime(df): + df['timestamp'] = df['timestamp'].map(lambda t: datetime.datetime.fromtimestamp(t)) + return df - x = df['Total episodes'] - y = df['Mean'] + 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 + + +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: + df = pd.read_csv('models/c/logs/eval.log', sep=";", names=eval_headers) + df['timestamp'] = df['timestamp'].map(lambda t: datetime.datetime.fromtimestamp(t)) + + print(df) + + x = df['eps_train'] + y = df['mean'] - plt.scatter(x, y, c=[[1,0.5,0]]) - #fig.canvas.draw() - plt.pause(2) + plt.scatter(x, y, c=[[1, 0.5, 0]]) + #fig.canvas.draw() + plt.pause(2)