def plot_session(session_spec, info_space, session_data): '''Plot the session graph, 2 panes: reward, loss & explore_var. Each aeb_df gets its own color''' aeb_count = len(session_data) if aeb_count <= 8: palette = cl.scales[str(max(3, aeb_count))]['qual']['Set2'] else: palette = util.interp(cl.scales['8']['qual']['Set2'], aeb_count) fig = viz.tools.make_subplots(rows=3, cols=1, shared_xaxes=True) for idx, (a, e, b) in enumerate(session_data): aeb_str = f'{a}{e}{b}' aeb_df = session_data[(a, e, b)] fig_1 = viz.plot_line(aeb_df, 'reward', 'epi', legend_name=aeb_str, draw=False, trace_kwargs={'legendgroup': aeb_str, 'line': {'color': palette[idx]}}) fig.append_trace(fig_1.data[0], 1, 1) fig_2 = viz.plot_line(aeb_df, ['loss'], 'epi', y2_col=['explore_var'], trace_kwargs={'legendgroup': aeb_str, 'showlegend': False, 'line': {'color': palette[idx]}}, draw=False) fig.append_trace(fig_2.data[0], 2, 1) fig.append_trace(fig_2.data[1], 3, 1) fig.layout['xaxis1'].update(title='epi', zerolinewidth=1) fig.layout['yaxis1'].update(fig_1.layout['yaxis']) fig.layout['yaxis1'].update(domain=[0.55, 1]) fig.layout['yaxis2'].update(fig_2.layout['yaxis']) fig.layout['yaxis2'].update(showgrid=False, domain=[0, 0.45]) fig.layout['yaxis3'].update(fig_2.layout['yaxis2']) fig.layout['yaxis3'].update(overlaying='y2', anchor='x2') fig.layout.update(ps.pick(fig_1.layout, ['legend'])) fig.layout.update(title=f'session graph: {session_spec["name"]} t{info_space.get("trial")} s{info_space.get("session")}', width=500, height=600) viz.plot(fig) return fig
def plot_session(session_spec, info_space, session_data): '''Plot the session graph, 2 panes: reward, loss & explore_var. Each aeb_df gets its own color''' graph_x = session_spec['meta'].get('graph_x', 'epi') aeb_count = len(session_data) palette = viz.get_palette(aeb_count) fig = viz.tools.make_subplots(rows=3, cols=1, shared_xaxes=True) for idx, (a, e, b) in enumerate(session_data): aeb_str = f'{a}{e}{b}' aeb_df = session_data[(a, e, b)] aeb_df.fillna(0, inplace=True) # for saving plot, cant have nan fig_1 = viz.plot_line(aeb_df, 'reward', graph_x, legend_name=aeb_str, draw=False, trace_kwargs={'legendgroup': aeb_str, 'line': {'color': palette[idx]}}) fig.append_trace(fig_1.data[0], 1, 1) fig_2 = viz.plot_line(aeb_df, ['loss'], graph_x, y2_col=['explore_var'], trace_kwargs={'legendgroup': aeb_str, 'showlegend': False, 'line': {'color': palette[idx]}}, draw=False) fig.append_trace(fig_2.data[0], 2, 1) fig.append_trace(fig_2.data[1], 3, 1) fig.layout['xaxis1'].update(title=graph_x, zerolinewidth=1) fig.layout['yaxis1'].update(fig_1.layout['yaxis']) fig.layout['yaxis1'].update(domain=[0.55, 1]) fig.layout['yaxis2'].update(fig_2.layout['yaxis']) fig.layout['yaxis2'].update(showgrid=False, domain=[0, 0.45]) fig.layout['yaxis3'].update(fig_2.layout['yaxis2']) fig.layout['yaxis3'].update(overlaying='y2', anchor='x2') fig.layout.update(ps.pick(fig_1.layout, ['legend'])) fig.layout.update(title=f'session graph: {session_spec["name"]} t{info_space.get("trial")} s{info_space.get("session")}', width=500, height=600) viz.plot(fig) return fig
def plot_session(session_spec, info_space, session_data): '''Plot the session graph, 2 panes: reward, loss & explore_var. Each aeb_df gets its own color''' aeb_count = len(session_data) palette = get_palette(aeb_count) fig = viz.tools.make_subplots(rows=3, cols=1, shared_xaxes=True) for idx, (a, e, b) in enumerate(session_data): aeb_str = f'{a}{e}{b}' aeb_df = session_data[(a, e, b)] aeb_df.fillna(0, inplace=True) # for saving plot, cant have nan fig_1 = viz.plot_line(aeb_df, 'reward', 'epi', legend_name=aeb_str, draw=False, trace_kwargs={'legendgroup': aeb_str, 'line': {'color': palette[idx]}}) fig.append_trace(fig_1.data[0], 1, 1) fig_2 = viz.plot_line(aeb_df, ['loss'], 'epi', y2_col=['explore_var'], trace_kwargs={'legendgroup': aeb_str, 'showlegend': False, 'line': {'color': palette[idx]}}, draw=False) fig.append_trace(fig_2.data[0], 2, 1) fig.append_trace(fig_2.data[1], 3, 1) fig.layout['xaxis1'].update(title='epi', zerolinewidth=1) fig.layout['yaxis1'].update(fig_1.layout['yaxis']) fig.layout['yaxis1'].update(domain=[0.55, 1]) fig.layout['yaxis2'].update(fig_2.layout['yaxis']) fig.layout['yaxis2'].update(showgrid=False, domain=[0, 0.45]) fig.layout['yaxis3'].update(fig_2.layout['yaxis2']) fig.layout['yaxis3'].update(overlaying='y2', anchor='x2') fig.layout.update(ps.pick(fig_1.layout, ['legend'])) fig.layout.update(title=f'session graph: {session_spec["name"]} t{info_space.get("trial")} s{info_space.get("session")}', width=500, height=600) viz.plot(fig) return fig
def build_aeb_reward_fig(aeb_rewards_df, aeb_str, color): '''Build the aeb_reward envelope figure''' mean_sr = aeb_rewards_df.mean(axis=1) std_sr = aeb_rewards_df.std(axis=1).fillna(0) max_sr = mean_sr + std_sr min_sr = mean_sr - std_sr x = aeb_rewards_df.index.tolist() max_y = max_sr.tolist() min_y = min_sr.tolist() envelope_trace = viz.go.Scatter( x=x + x[::-1], y=max_y + min_y[::-1], fill='tozerox', fillcolor=lower_opacity(color, 0.2), line=dict(color='transparent'), showlegend=False, legendgroup=aeb_str, ) df = pd.DataFrame({'epi': x, 'mean_reward': mean_sr}) fig = viz.plot_line(df, ['mean_reward'], ['epi'], legend_name=aeb_str, draw=False, trace_kwargs={ 'legendgroup': aeb_str, 'line': { 'color': color } }) fig.data.append(envelope_trace) return fig
def build_aeb_reward_fig(aeb_rewards_df, aeb_str, color): '''Build the aeb_reward envelope figure''' # TODO need enable total_t for trial graph, and line up signals at the common total_t mean_sr = aeb_rewards_df.mean(axis=1) std_sr = aeb_rewards_df.std(axis=1).fillna(0) max_sr = mean_sr + std_sr min_sr = mean_sr - std_sr x = aeb_rewards_df.index.tolist() max_y = max_sr.tolist() min_y = min_sr.tolist() envelope_trace = viz.go.Scatter( x=x + x[::-1], y=max_y + min_y[::-1], fill='tozerox', fillcolor=viz.lower_opacity(color, 0.2), line=dict(color='rgba(0, 0, 0, 0)'), showlegend=False, legendgroup=aeb_str, ) df = pd.DataFrame({'epi': x, 'mean_reward': mean_sr}) fig = viz.plot_line(df, ['mean_reward'], ['epi'], legend_name=aeb_str, draw=False, trace_kwargs={ 'legendgroup': aeb_str, 'line': { 'color': color } }) fig.add_traces([envelope_trace]) return fig
def build_aeb_reward_fig(aeb_rewards_df, aeb_str, color): '''Build the aeb_reward envelope figure''' mean_sr = aeb_rewards_df.mean(axis=1) std_sr = aeb_rewards_df.std(axis=1).fillna(0) max_sr = mean_sr + std_sr min_sr = mean_sr - std_sr x = aeb_rewards_df.index.tolist() max_y = max_sr.tolist() min_y = min_sr.tolist() envelope_trace = viz.go.Scatter( x=x + x[::-1], y=max_y + min_y[::-1], fill='tozerox', fillcolor=lower_opacity(color, 0.2), line=dict(color='transparent'), showlegend=False, legendgroup=aeb_str, ) df = pd.DataFrame({'epi': x, 'mean_reward': mean_sr}) fig = viz.plot_line( df, ['mean_reward'], ['epi'], legend_name=aeb_str, draw=False, trace_kwargs={'legendgroup': aeb_str, 'line': {'color': color}} ) fig.data.append(envelope_trace) return fig
''' from IPython.display import Latex from slm_lab.lib import util, viz import pandas as pd import pydash as _ df = pd.DataFrame({ 'a': [0, 1, 2, 3, 4], 'b': [0, 1, 4, 9, 16], }) fig = viz.plot_area(df, ['a', 'b']) fig = viz.plot_area(df, ['a'], y2_col=['b']) fig = viz.plot_area(df, ['a', 'b'], stack=True) fig = viz.plot_bar(df, ['b', 'a']) fig = viz.plot_line(df, ['b', 'a'], save=False) fig = viz.plot_line(df, ['a'], y2_col=['b']) fig = viz.plot_scatter(df, ['b', 'a']) fig = viz.plot_histogram(df, ['b']) # pull plots to make multiple subplots fig1 = viz.plot_area(df, ['a'], y2_col=['b'], draw=False) fig2 = viz.plot_area(df, ['b'], draw=False) fig = viz.tools.make_subplots(rows=3, cols=1, shared_xaxes=True) fig.append_trace(fig1.data[0], 1, 1) fig.append_trace(fig1.data[1], 2, 1) fig.append_trace(fig2.data[0], 3, 1) fig.layout['yaxis1'].update(fig1.layout['yaxis']) fig.layout['yaxis2'].update(fig1.layout['yaxis2']) fig.layout['yaxis1'].update(domain=[0.55, 1]) fig.layout['yaxis3'].update(fig2.layout['yaxis'])