Esempio n. 1
0
 def plot_diagnostics(self, figdir=None):
     """
     FUNCTION: plots diagnostics of sequences generated.
             Including MSD, autocorrelation, covering percentage vs time.
     INPUTS: self = propagator with propagated sequences.
             figdir = output figure diretory
     """
     assert self.diagnostics_computed, 'EXPLORER: diagnostics not computed'
     self.fig, self.axes = plt.subplots(1, 3, figsize=(18, 6), sharey=False)
     self.set_target_axis(ax=self.axes[0])
     self.plot_coverage()
     self.set_target_axis(ax=self.axes[1])
     self.plot_exploration_efficiency()
     self.set_target_axis(ax=self.axes[2])
     self.plot_msd()
     plt.tight_layout()
     if figdir is not None:
         save_figure(fig=self.fig,
                     figdir=figdir,
                     fname_base='exploration_analysis',
                     file_ext='.png')
Esempio n. 2
0
 def plot_learning_errors(self, objs=["T_error"], figdir=None):
     """
     FUNCTION: Plots learning objectives as a function of number of sequence samples.
     INPUTS:
     objs = ['Q_error', 'Q_corr', 'T_error', 'T_corr', 'SR_error', 'SR_corr', 'SPL_error', 'KLtraj', 'R_error', 'policy_error'] objectives to learn
     [Superseded by plot_performance_metrics]
     """
     assert self.error_curves_computed, "Learning curves not yet computed."
     self.fig_axis()
     ax = self.ax
     for key in objs:
         loss = self._retrieve_learn_var(n_samp=None, key=key).values
         ax.plot(range(1, self.n_samp + 1), loss, "--o", label=key)
     ax.set_ylabel("Euclidean error")
     ax.set_xlabel("#samples")
     ax.legend(loc="center left")
     if figdir is not None:
         save_figure(
             fig=self.fig,
             figdir=figdir,
             fname_base="learning_analysis",
             file_ext=".png",
         )
Esempio n. 3
0
options.periodic = False
options.norm_cov = False
options.gauss_norm = False
options.box_width = 2.2
options.box_height = 2.2



# run grid pattern formation
Q = diff_gen(options=options, sigma=0.5, surround_scale=1.5)
options.Q = to.as_tensor(Q)

place_cells = PredictivePlaceCells(options=options)

place_cells.compute_covariance(predmap=True)
place_cells.Cmean = gaussian_filter(input=place_cells.Cmean, sigma=4., truncate=6., order=0, mode='wrap', cval=0.0)
place_cells.fft_covariance(predmap=True)

# rescale/smooth in fourier space
place_cells.Ctilde /= place_cells.Ctilde.max()
place_cells.Ctilde *= options.Ng

# run pattern formation
Gmaps = ortho_grid_pattern_formation(place_cells, options, activation='relu')

# plot resulting maps
fig = plot_ratemaps(np.flip(Gmaps), options.Ng)
if save_output:
    save_figure(fig=fig, figdir=figdir, fname_base=fname_base, file_ext='.png')
    save_figure(fig=fig, figdir=figdir, fname_base=fname_base, file_ext='.pdf')
Esempio n. 4
0
            PROP.plot_prop_kernels(n=1,
                                   first_state=int(samps[ix_t]),
                                   wrap_col=1,
                                   autoprop_off=False)
            axes[ix_tau][ix_t].set_title("")
    fig.subplots_adjust(left=0.01,
                        bottom=0.1,
                        right=0.99,
                        top=0.9,
                        wspace=0.5,
                        hspace=0.6)
    fig.set_size_inches(width, height)
    if save_output:
        save_figure(
            fig=fig,
            figdir=figdir,
            fname_base=fname_base + "_TauxT_alpha%.1f" % alpha,
            file_ext=".png",
        )
        save_figure(
            fig=fig,
            figdir=figdir,
            fname_base=fname_base + "_TauxT_alpha%.1f" % alpha,
            file_ext=".pdf",
        )

# %% 3x3 figure
if run_3x3:
    ENV = RoomWorld(start=0, scale=scale_lowres)
    n_step = 30
    start = ENV.n_state // 4 - 1
    width = page_width
Esempio n. 5
0
 def plot_performance_metrics(
         self,
         metrics=["Q_error", "SR_error", "SPL_error", "policy_error"],
         figdir=None):
     """
     FUNCTION: Plots learning objectives on different panels as a function of number of sequences.
     INPUTS: metrics = list of what metrics to plot from self.metrics_dict.keys()
     """
     self.metrics_dict = {
         "Q_error": "generator error",
         "Q_corr": "generator correlation",
         "T_error": "transition error",
         "T_corr": "transition correlation",
         "SR_error": "successor representation error",
         "SR_corr": "successor representation correlation",
         "R_error": "reward function error",
         "SPL_error": "shortest path length error",
         "policy_error": "expected cumulative reward loss",
         "KLtraj": "trajectory KL-divergence",
     }
     metrics_df = pd.melt(
         self.output_learn.reset_index(),
         id_vars=["n_samp", "alpha", "tau", "lr"],
         value_vars=self.metrics_dict.keys(),
         var_name="metric",
         value_name="value",
     )
     metrics_df.rename(columns={"n_samp": "#samples"}, inplace=True)
     for metric_key in self.metrics_dict.keys():
         if metric_key in metrics:
             metrics_df.loc[metrics_df.metric == metric_key,
                            "metric"] = self.metrics_dict[metric_key]
         else:
             metrics_df = metrics_df[metrics_df.metric != metric_key]
     self.metrics_learn = metrics_df
     g = sb.FacetGrid(
         self.metrics_learn,
         row="lr",
         col="metric",
         hue="alpha",
         margin_titles=True,
         sharex=True,
         sharey=False,
     )
     g.map(
         sb.regplot,
         "#samples",
         "value",
         ci=None,
         fit_reg=False,
         logx=False,
         order=1,
         truncate=False,
     )
     [plt.setp(ax.texts, text="") for ax in g.axes.flat]
     g.set_titles(row_template="{row_name}", col_template="{col_name}")
     if figdir is not None:
         save_figure(fig=g,
                     figdir=figdir,
                     fname_base="learning_performance",
                     file_ext=".png")
Esempio n. 6
0
label_panel(axes[2][1], label="J", x=x, y=y)
label_panel(axes[2][2], label="K", x=x, y=y)
label_panel(axes[2][3], label="L", x=x, y=y)

fig.subplots_adjust(left=0.01, bottom=0.1, right=0.99, top=0.9, wspace=0.6, hspace=0.8)
fig.set_size_inches(width, height)

if save_output:
    fname_base = "FIGURE_7_SamplingOptim_tau%.1f_%.1f_alpha%.1f_%.1f_lr%.1f" % (
        tau_diff,
        tau_supdiff,
        alpha_diff,
        alpha_supdiff,
        lr,
    )
    save_figure(fig=fig, figdir=figdir, fname_base=fname_base, file_ext=".png")
    save_figure(fig=fig, figdir=figdir, fname_base=fname_base, file_ext=".pdf")


# %% SUPPLEMENTARY PLOT
width = page_width * 1.3
height = row_height * 1.6 * 2.5
nrows = 5
ncols = 3
fig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=(width, height))
state_msize = 5
jitter_state = False
traj_width = 0.5
n_step = 10
rho_start = rho_init_exp
title_fontsize = 24
Esempio n. 7
0
    n_state = env.n_state
    states = np.arange(n_state)

    # sequence generation
    exp_diff_g1.sample_sequences(n_samp=1, n_step=n_step)

    # sequence plots
    figsize = (12, 12)
    exp_diff_g1.plot_trajectory(samp=0,
                                plot_env=True,
                                state_func_env=False,
                                figsize=figsize)
    if save_output:
        fname_base = 'FIGURE_4_sample_diff_g1'
        save_figure(fig=exp_diff_g1.fig,
                    figdir=figdir,
                    fname_base=fname_base,
                    file_ext='.png')
        save_figure(fig=exp_diff_g1.fig,
                    figdir=figdir,
                    fname_base=fname_base,
                    file_ext='.pdf')
    exp_sdiff_g1.plot_trajectory(samp=0,
                                 plot_env=True,
                                 state_func_env=False,
                                 figsize=figsize)
    if save_output:
        fname_base = 'FIGURE_4_sample_sdiff_g1'
        save_figure(fig=exp_sdiff_g1.fig,
                    figdir=figdir,
                    fname_base=fname_base,
                    file_ext='.png')