Example #1
0
 def return_avg_median(fig, df, args):
     if not _keys_in_columns(df,
                             'avg_return',
                             'std_return',
                             'median_return',
                             verbose=args.verbose):
         return False
     data = DataFrame(dict(mean=df.avg_return, std=df.std_return))
     draw_curve_from_data('mean_std',
                          fig.gca(),
                          data,
                          np.arange(len(df.avg_return)),
                          ax_calc=1,
                          curve_label='average',
                          x_label='iteration',
                          y_label='return',
                          legend_kwargs=dict(loc='upper left'))
     plt.plot(np.arange(len(df.median_return)),
              df.median_return,
              label='median')
     if _keys_in_columns(df, 'curr_policy_return', verbose=args.verbose):
         # If the algorithm is a subclass of ParameterExploring
         plt.plot(np.arange(len(df.curr_policy_return)),
                  df.curr_policy_return,
                  label='current')
Example #2
0
 def return_min_max_avg(fig, df, args):
     if not _keys_in_columns(df, "avg_return", "min_return", "max_return", verbose=args.verbose):
         return False
     data = DataFrame(dict(mean=df.avg_return, min=df.min_return, max=df.max_return))
     draw_curve_from_data(
         "min_mean_max",
         fig.gca(),
         data,
         np.arange(len(df.avg_return)),
         ax_calc=1,
         curve_label="average",
         x_label="iteration",
         y_label="return",
         legend_kwargs=dict(loc="upper left"),
     )
Example #3
0
 def return_min_max_avg(fig, df, args):
     if not _keys_in_columns(
             df, 'avg_return', 'min_return', 'max_return',
             verbose=args.verbose):
         return False
     data = DataFrame(
         dict(mean=df.avg_return, min=df.min_return, max=df.max_return))
     draw_curve_from_data('min_mean_max',
                          fig.gca(),
                          data,
                          np.arange(len(df.avg_return)),
                          ax_calc=1,
                          curve_label='average',
                          x_label='iteration',
                          y_label='return',
                          legend_kwargs=dict(loc='upper left'))
Example #4
0
 def return_avg_median(fig, df, args):
     if not _keys_in_columns(df, "avg_return", "std_return", "median_return", verbose=args.verbose):
         return False
     data = DataFrame(dict(mean=df.avg_return, std=df.std_return))
     draw_curve_from_data(
         "mean_std",
         fig.gca(),
         data,
         np.arange(len(df.avg_return)),
         ax_calc=1,
         curve_label="average",
         x_label="iteration",
         y_label="return",
         legend_kwargs=dict(loc="upper left"),
     )
     plt.plot(np.arange(len(df.median_return)), df.median_return, label="median")
     if _keys_in_columns(df, "curr_policy_return", verbose=args.verbose):
         # If the algorithm is a subclass of ParameterExploring
         plt.plot(np.arange(len(df.curr_policy_return)), df.curr_policy_return, label="current")
Example #5
0
def test_render_curve(data, x_grid):
    fix, axs = plt.subplots(nrows=2, ncols=2)
    draw_curve_from_data(
        'mean_std', axs[0, 0], data, x_grid, ax_calc=1,
        x_label='A', y_label='y', vline_level=None, title=None, show_legend=True, area_label='a',
        plot_kwargs=dict(alpha=0.1, color='r', ls='--')
    )
    draw_curve_from_data(
        'min_mean_max', axs[0, 1], data, x_grid, ax_calc=1,
        x_label=None, y_label=None, vline_level=None, title=None, show_legend=True, curve_label='c',
    )
    draw_curve_from_data(
        'mean_std', axs[1, 0], data, x_grid, ax_calc=1,
        x_label='d', y_label=r'$y$', vline_level=None, title='Title', show_legend=True, curve_label='c',
        plot_kwargs=dict(alpha=0.1)
    )
    draw_curve_from_data(
        'min_mean_max', axs[1, 1], data, x_grid, ax_calc=1,
        x_label=r'$\mu$', y_label='', vline_level=None, title='Title', show_legend=True, area_label='a',
        plot_kwargs=dict(alpha=0.1, color='r')
    )
Example #6
0
def test_render_curve(data, x_grid):
    fix, axs = plt.subplots(nrows=3, ncols=2)
    draw_curve_from_data(
        "mean_std",
        axs[0, 0],
        data,
        x_grid,
        ax_calc=1,
        x_label="A",
        y_label="y",
        vline_level=None,
        title=None,
        show_legend=True,
        area_label="a",
        plot_kwargs=dict(alpha=0.1, color="r", ls="--"),
    )
    draw_curve_from_data(
        "min_mean_max",
        axs[0, 1],
        data,
        x_grid,
        ax_calc=1,
        x_label=None,
        y_label=None,
        vline_level=None,
        title=None,
        show_legend=True,
        curve_label="c",
    )
    draw_curve_from_data(
        "mean_std",
        axs[1, 0],
        data,
        x_grid,
        ax_calc=1,
        x_label="d",
        y_label=r"$y$",
        vline_level=None,
        title="Title",
        show_legend=True,
        curve_label="c",
        plot_kwargs=dict(alpha=0.1),
    )
    draw_curve_from_data(
        "min_mean_max",
        axs[1, 1],
        data,
        x_grid,
        ax_calc=1,
        x_label=r"$\mu$",
        y_label="",
        vline_level=None,
        title="Title",
        show_legend=True,
        area_label="a",
        plot_kwargs=dict(alpha=0.1, color="r"),
    )
    draw_curve_from_data(
        "ci_on_mean",
        axs[2, 0],
        data,
        x_grid,
        ax_calc=1,
        title=None,
        show_legend=True,
        curve_label="100 reps",
        area_label="ci",
        cmp_kwargs=dict(num_reps=100, confidence_level=0.5),
        plot_kwargs=dict(color="c"),
    )
    draw_curve_from_data(
        "ci_on_mean",
        axs[2, 1],
        data,
        x_grid,
        ax_calc=1,
        title=None,
        show_legend=True,
        curve_label="10000 reps",
        area_label="ci",
        cmp_kwargs=dict(num_reps=10000),
        plot_kwargs=dict(alpha=0.4, color="c"),
    )
            if args.verbose:
                print(f"b_Jhat_{n}:\t\t{b_Jhat_n}\n")

    print(f"At the last iteration (n={num_iter})")
    print(f"mean G_n: {np.mean(G_n_hist, axis=0)[-1]}")
    print(f"mean G_true: {np.mean(G_true_hist, axis=0)[-1]}")
    print(f"mean b_Jhat_n: {np.mean(b_Jhat_n_hist, axis=0)[-1]}\n")

    # Plot
    os.makedirs(ex_dir, exist_ok=True)
    fig_n, ax = plt.subplots(1, figsize=fig_size, constrained_layout=True)
    draw_curve_from_data(
        "ci_on_mean",
        ax,
        n_M_hist,
        np.arange(1, num_iter + 1),
        ax_calc=0,
        x_label="number of domains $n$",
        y_label="samples per domain",
        curve_label="$n_M$",
    )
    draw_curve_from_data(
        "ci_on_mean",
        ax,
        n_V_hist,
        np.arange(1, num_iter + 1),
        ax_calc=0,
        x_label="number of domains $n$",
        y_label="samples per domain",
        curve_label="$n_V$",
    )
    ax.plot(np.arange(1, num_iter + 1),