Exemplo n.º 1
0
def test_figure_row():
    doc @ """
    ## Test Figure Row
    """
    with doc:
        import gym
        env = gym.make('FetchReach-v1')

    img = env.render('rgb_array')

    with doc, doc.table() as table:
        with table.figure_row() as row:
            row.figure(img,
                       src=f"figures/reach.png?ts={doc.now()}",
                       title="Before Init",
                       caption="this is the details")
            row.figure(img,
                       src=f"figures/reach.png?ts={doc.now()}",
                       title="Before Init",
                       caption="this is the details")
            row.figure(img,
                       src=f"figures/reach.png?ts={doc.now()}",
                       title="Before Init",
                       caption="this is the details")
            row.figure(img,
                       src=f"figures/reach.png?ts={doc.now()}",
                       title="Before Init",
                       caption="this is the details")
Exemplo n.º 2
0
def test_table():
    table = doc.table()

    with table.figure_row() as row:
        row.figure(src="some_file.png",
                   title="some title",
                   caption="some text")
        row.figure(src="some_file.png",
                   title="some title",
                   caption="some text")
        row.figure(src="some_file.png",
                   title="some title",
                   caption="some text")
        row.figure(src="some_file.png",
                   title="some title",
                   caption="some text")

    with table.figure_row() as row:
        row.figure(src="some_file.png",
                   title="some title",
                   caption="some text")
        row.figure(src="some_file.png",
                   title="some title",
                   caption="some text")
        row.figure(src="some_file.png",
                   title="some title",
                   caption="some text")
        row.figure(src="some_file.png",
                   title="some title",
                   caption="some text")

    target = """
| **some title** | **some title** | **some title** | **some title** |
|:--------------:|:--------------:|:--------------:|:--------------:|
| ![some_file.png](some_file.png) | ![some_file.png](some_file.png) | ![some_file.png](some_file.png) | ![some_file.png](some_file.png) |
| some text | some text | some text | some text |
| **some title** | **some title** | **some title** | **some title** |
| ![some_file.png](some_file.png) | ![some_file.png](some_file.png) | ![some_file.png](some_file.png) | ![some_file.png](some_file.png) |
| some text | some text | some text | some text |
"""[1:]

    print(doc._md)

    assert doc._md == target
    doc.children.clear()
Exemplo n.º 3
0
    loader = ML_Logger(root=os.getcwd(), prefix="data/walker-walk/curl")

with doc @ """Check all the files""":
    files = loader.glob(query="**/metrics.pkl", wd=".", recursive=True)
    doc.print(files)

with doc @ """Step 1: load the data""":
    avg, top, bottom, step = loader.read_metrics(
        "train/episode_reward/mean@mean",
        "train/episode_reward/mean@84%",
        "train/episode_reward/mean@16%",
        x_key="step@mean",
        path="**/metrics.pkl",
        bin_size=40)

with doc @ "Step 2: Plot", doc.table().figure_row() as r:
    import matplotlib.pyplot as plt
    from matplotlib import ticker

    title = "CURL on Walker-walk"

    plt.figure()

    plt.plot(step, avg.to_list(), color="#23aaff")
    plt.fill_between(step, bottom, top, color="#23aaff", alpha=0.15)

    plt.gca().xaxis.set_major_formatter(
        ticker.FuncFormatter(lambda x, _: f"{int(x / 1000)}k" if x else "0"))
    plt.title(title)
    plt.xlabel("Steps")
    plt.ylabel("Return")
Exemplo n.º 4
0
                x_key="frames@min",
                path=path)

            plt.plot(step.to_list(),
                     mean.to_list(),
                     color=color,
                     label=f'{label} (pred)',
                     linestyle='--')
            plt.fill_between(step, low, high, alpha=0.1, color=color)

    doc @ """Drqv2 (state) -RFF vs Drqv2"""
    with doc:
        for (b_val, env_name) in tqdm(zip(b_vals, envs), desc="(b_val, env)"):

            if loader.every(4, 'figure', start_on=1):
                r = doc.table().figure_row()

            if env_name == 'dmc:Finger-turn_hard-v1':
                menv = 'dmc:Finger-turn_hard2-v1'
            else:
                menv = env_name

            plt.title(f"DDPG {env_name.split(':')[-1][:-3]}", fontsize=18)
            plot_line(path=f"mlp/{menv.split(':')[-1][:-3]}/**/metrics.pkl",
                      color='black',
                      label='DDPG')

            if env_name == 'dmc:Humanoid-run-v1':
                tenv = 'dmc:Humanoid-run2-v1'
            else:
                tenv = env_name
Exemplo n.º 5
0
        plt.plot(step, avg, color=color, label=label)
        plt.fill_between(step, bottom, top, alpha=0.15, color=color)


with doc @ "Step 2: Plot":
    title = "CURL"
    colors = ['#49b8ff', '#444444', '#ff7575', '#66c56c', '#f4b247']

    for domain in [
            'walker-walk', 'cartpole-swingup', 'ball_in_cup-catch',
            'finger-spin'
    ]:
        name, task = domain.split("-")

        doc(name.replace('_', ' ').title(), f"[{task}]")
        with loader.Prefix(domain), doc.table().figure_row() as r:
            for method in ['curl', 'rad', 'pad']:
                with loader.Prefix(method):
                    group(yKey="episode_reward/mean",
                          bins=None,
                          dropna=True,
                          color=colors[0],
                          label="Eval")
                    group(yKey="train/episode_reward/mean",
                          color=colors[1],
                          label="Train")

                plt.legend(frameon=False)
                plt.ylim(0, 1000)
                plt.gca().xaxis.set_major_formatter(
                    ticker.FuncFormatter(lambda x, _: f"{int(x / 1000)}k"