Esempio n. 1
0
def main():
    parser = argparse.ArgumentParser(
        description='Plots an experiment in terminal')
    parser.add_argument('glob', help='directory of experiment to plot')
    parser.add_argument('--window',
                        help='smoothing window',
                        type=int,
                        default=100)
    parser.add_argument('--width', help='smoothing window', type=int)
    parser.add_argument('--height', help='smoothing window', type=int)
    parser.add_argument('-x', help='x axis', default='frames')
    parser.add_argument('-y', help='y axis', default='mean_win_rate')
    args = parser.parse_args()

    exps_and_logs = Experiment.discover_logs(args.glob, JSONLogger())
    print('loaded {} experiments'.format(len(exps_and_logs)))

    fig = plotille.Figure()
    kwargs = {}
    for exp, log in exps_and_logs:
        if log:
            df = pd.DataFrame(log)
            fig.plot(X=df[args.x],
                     Y=df[args.y].rolling(args.window, min_periods=1).mean(),
                     label=exp.name,
                     **kwargs)
    fig.x_label = args.x
    fig.y_label = args.y
    if args.height:
        fig.height = args.height
    if args.width:
        fig.width = args.width

    print(fig.show(legend=True))
Esempio n. 2
0
            exp = Experiment(
                config=dict(seed=seed,
                            type=t,
                            name=name,
                            logdir=os.path.join(args.logdir, 'seeded')),
                loggers=loggers).start(delete_existing=args.delete_existing)
            for i in range(100):
                if t == 'linear':
                    score = i + random.uniform(-noise, noise)
                elif t == 'quadratic':
                    score = (i / 10)**2 + random.uniform(-noise * 2, noise * 2)
                exp.log(dict(score=score))
            exp.finish()

    exps_and_logs = Experiment.discover_logs(glob_path=os.path.join(
        args.logdir, 'seeded', '*'),
                                             logger=JSONLogger())

    if args.wandb:
        WandbLogger.upload_logs(exps_and_logs, project='seeded_upload')

    plotter = LinePlotter()
    fig, ax = plt.subplots(figsize=(5, 5))
    plotter.plot(exps_and_logs,
                 x='step',
                 y='score',
                 group='type',
                 xpid='name',
                 read_every=2,
                 smooth_window=10,
                 ax=ax)