In [2]:
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
import argparse
import os

import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np


def errorfill(x, y, yerr, color=None, alpha_fill=0.1, ax=None, label=None):
    """Plot with confidence intervals rendered as shaded regions."""
    ax = ax if ax is not None else plt.gca()
    if color is None:
        color = next(ax._get_lines.prop_cycler)['color']
    if np.isscalar(yerr) or len(yerr) == len(y):
        ymin = y - yerr
        ymax = y + yerr
    elif len(yerr) == 2:
        ymin, ymax = yerr
    ax.plot(x, y, color=color, label=label)
    ax.fill_between(x, ymax, ymin, color=color, alpha=alpha_fill)

    
def plot_scores(file_label_pairs, title):
    for fpath, label in file_label_pairs:
        if os.path.isdir(fpath):
            fpath = os.path.join(fpath, 'scores.txt')
        assert os.path.exists(fpath)
        scores = pd.read_csv(fpath, delimiter='\t')
#         plt.plot(scores['steps'], scores['mean'], label=label)
        # plt.plot(scores['steps'], scores['mean'], label=label)
        # plt.fill_between(scores['steps'], -scores['stdev'], scores['stdev'], alpha=0.2, edgecolor='#1B2ACC', facecolor='#089FFF', linewidth=4, linestyle='dashdot', antialiased=True)
        errorfill(scores['steps'], scores['mean'], scores['stdev'], label=label)

    plt.xlabel('steps')
    plt.ylabel('score')
    plt.legend(loc='best')
    if title:
        plt.title(title)

    fig_fname = title + '.png'
    plt.show()
    plt.savefig(fig_fname)
    print('Saved a figure as {}'.format(fig_fname))
In [6]:
plot_scores([('beamrider/20170728T220737.724648/scores.txt', 'dqn'),
             ('beamrider-doubledqn/20170731T140650.787772/scores.txt', 'doubledqn'),
             ('beamrider-pal/20170731T140914.361425/scores.txt', 'pal'),
             ('beamrider-prioritized/20170802T170532.266097/scores.txt', 'prioritized'),
             ('beamrider-pal-dueling/20170802T153051.888857/scores.txt', 'pal-dueling'),
            ],
            title='beamrider')
plot_scores([('breakout/20170726T212134.210326/scores.txt', 'dqn'),
             ('breakout-doubledqn/20170731T140720.421836/scores.txt', 'doubledqn'),
             ('breakout-pal/20170731T141003.023559/scores.txt', 'pal'),
             ('breakout-prioritized/20170802T170613.041840/scores.txt', 'prioritized'),
             ('breakout-pal-dueling/20170802T153059.027101/scores.txt', 'pal-dueling'),
            ],
            title='breakout')
plot_scores([('pong/20170729T002505.180328/scores.txt', 'dqn'),
             ('pong-doubledqn/20170731T140750.795522/scores.txt', 'doubledqn'),
             ('pong-pal/20170731T141024.998128/scores.txt', 'pal'),
             ('pong-prioritized/20170802T170635.057412/scores.txt', 'prioritized'),
             ('pong-pal-dueling/20170802T153102.533890/scores.txt', 'pal-dueling'),
            ],
            title='pong')
plot_scores([('seaquest/20170729T002437.594523/scores.txt', 'dqn'),
             ('seaquest-doubledqn/20170731T204458.148897/scores.txt', 'doubledqn'),
             ('seaquest-pal/20170731T141034.356256/scores.txt', 'pal'),
             ('seaquest-prioritized/20170802T170653.760037/scores.txt', 'prioritized'),
             ('seaquest-pal-dueling/20170802T153105.377498/scores.txt', 'pal-dueling'),
            ],
            title='seaquest')
plot_scores([('spaceinvaders/20170728T221316.351960/scores.txt', 'dqn'),
             ('spaceinvaders-doubledqn/20170731T140739.363588/scores.txt', 'doubledqn'),
             ('spaceinvaders-pal/20170731T141052.732935/scores.txt', 'pal'),
             ('spaceinvaders-prioritized/20170802T170723.628997/scores.txt', 'prioritized'),
             ('spaceinvaders-pal-dueling/20170802T153110.109558/scores.txt', 'pal-dueling'),
            ],
            title='spaceinvaders')
Saved a figure as beamrider.png
Saved a figure as breakout.png
Saved a figure as pong.png
Saved a figure as seaquest.png
Saved a figure as spaceinvaders.png
In [ ]: