def plot_session_from_file(session_df_filepath): ''' Method to plot session from its session_df file @example from slm_lab.experiment import analysis filepath = 'data/reinforce_cartpole_2018_01_22_211751/reinforce_cartpole_t0_s0_session_df.csv' analysis.plot_session_from_file(filepath) ''' from slm_lab.experiment.monitor import InfoSpace spec_name = util.prepath_to_spec_name(session_df_filepath) session_spec = {'name': spec_name} session_df = util.read(session_df_filepath, header=[0, 1, 2, 3], index_col=0, dtype=np.float32) session_data = util.session_df_to_data(session_df) tn, sn = session_df_filepath.replace('_session_df.csv', '').split('_')[-2:] info_space = InfoSpace() info_space.set('experiment', 0) info_space.set('trial', int(tn[1:])) info_space.set('session', int(sn[1:])) session_fig = plot_session(session_spec, info_space, session_data) viz.save_image( session_fig, session_df_filepath.replace('_session_df.csv', '_session_graph.png'))
def mock_info_space_spec(predir, trial_index=None, session_index=None): '''Helper for retro analysis to build mock info_space and spec''' from slm_lab.experiment.monitor import InfoSpace spec_name = util.prepath_to_spec_name(predir) experiment_ts = util.prepath_to_experiment_ts(predir) info_space = InfoSpace() info_space.experiment_ts = experiment_ts info_space.set('experiment', 0) if trial_index is None: filepath = f'{predir}/{spec_name}_spec.json' else: info_space.set('trial', trial_index) filepath = f'{predir}/{spec_name}_t{trial_index}_spec.json' if session_index is not None: info_space.set('session', session_index) spec = util.read(filepath) return spec, info_space
def plot_session_from_file(session_df_filepath): ''' Method to plot session from its session_df file @example from slm_lab.experiment import analysis filepath = 'data/reinforce_cartpole_2018_01_22_211751/reinforce_cartpole_t0_s0_session_df.csv' analysis.plot_session_from_file(filepath) ''' from slm_lab.experiment.monitor import InfoSpace spec_name = util.prepath_to_spec_name(session_df_filepath) session_spec = {'name': spec_name} session_df = util.read(session_df_filepath, header=[0, 1, 2, 3], index_col=0, dtype=np.float32) session_data = util.session_df_to_data(session_df) tn, sn = session_df_filepath.replace('_session_df.csv', '').split('_')[-2:] info_space = InfoSpace() info_space.set('experiment', 0) info_space.set('trial', int(tn[1:])) info_space.set('session', int(sn[1:])) session_fig = plot_session(session_spec, info_space, session_data) viz.save_image(session_fig, session_df_filepath.replace('_session_df.csv', '_session_graph.png'))