def reuse_coverage(data, milestones=(200, 1000), testname='tcov', e_radius=3.0, nor=True, src=True, tgt=True, show=True, **kwargs): figs = [] titles = ['no reuse', 'source', 'target'] for i, (d, flag) in enumerate(zip(data, (nor, src, tgt))): if flag and d is not None: figs.append([]) try: K_boot = d['jobcfg'].exploration.explorer.eras[0] except KeyError: K_boot = 200 s_vectors = d['s_vectors'] radius = d.expcfg.tests[testname].buffer_size for t in milestones: fig = graphs.coverage(d['s_channels'], radius, s_vectors=s_vectors[:t], swap_xy=False, plot_width=400, plot_height=400, title='{} {}'.format(titles[i], t), **kwargs) graphs.spread(d['s_channels'], s_vectors=s_vectors[:K_boot], fig=fig, swap_xy=False, e_alpha=1.0, e_color=RED, radius_units='data', e_radius=radius/4.0) graphs.spread(d['s_channels'], s_vectors=s_vectors[K_boot:t], fig=fig, swap_xy=False, e_alpha=1.0, radius_units='data', e_radius=radius/4.0) figs[-1].append(fig) if show: graphs.show(figs) else: return figs
def reuse_coverage( data, milestones=(200, 1000), testname="tcov", e_radius=3.0, nor=True, src=True, tgt=True, show=True, **kwargs ): figs = [] titles = ["no reuse", "source", "target"] for i, (d, flag) in enumerate(zip(data, (nor, src, tgt))): if flag and d is not None: figs.append([]) try: K_boot = d["jobcfg"].exploration.explorer.eras[0] except KeyError: K_boot = 200 s_vectors = d["s_vectors"] radius = d.expcfg.tests[testname].buffer_size for t in milestones: fig = graphs.coverage( d["s_channels"], radius, s_vectors=s_vectors[:t], swap_xy=False, plot_width=400, plot_height=400, title="{} {}".format(titles[i], t), **kwargs ) graphs.spread( d["s_channels"], s_vectors=s_vectors[:K_boot], fig=fig, swap_xy=False, e_alpha=1.0, e_color=RED, radius_units="data", e_radius=radius / 4.0, ) graphs.spread( d["s_channels"], s_vectors=s_vectors[K_boot:t], fig=fig, swap_xy=False, e_alpha=1.0, radius_units="data", e_radius=radius / 4.0, ) figs[-1].append(fig) if show: graphs.show(figs) else: return figs
def coverage_graphs(expcfgs_levels, dest='tmp.html', n_graphs=3): cwd = os.getcwd() graphs.output_file(dest) red = '#DF6464' for level in expcfgs_levels: for i, exp_cfg in enumerate(level): n = 0 batch = jobfactory.make_jobgroup([exp_cfg]) os.chdir(os.path.expanduser(exp_cfg.meta.rootpath)) data_hub = hub.DataHub(batch, sensory_only=True) datas = data_hub.data() for j, data in enumerate(datas): if n_graphs is None or n < n_graphs: for N in [200, 1000]: print(exp_cfg.exploration.explorer) n_reuse = exp_cfg.exploration.explorer.eras[0] s_vectors = [ tools.to_vector(s_signal, data.s_channels) for s_signal in data.s_signals ][:N] graphs.coverage(data.s_channels, exp_cfg.testscov.buffer_size, s_vectors=s_vectors, swap_xy=False, title_text_font_size='6pt', title='{} {}'.format( exp_cfg.exp.key, j)) graphs.hold(True) graphs.spread(data.s_channels, s_vectors=s_vectors[n_reuse:], swap_xy=False, e_radius=2.0) graphs.hold(True) graphs.spread(data.s_channels, s_vectors=s_vectors[:n_reuse], swap_xy=False, e_radius=2.0, e_color=red) n += 1 os.chdir(cwd)
def adapt_graphs(ex_cfg, explorations, s_vectors, weight_history, mesh=None, title='no title'): s_channels = ex_cfg.s_channels tally_dict = {} for exploration, feedback in explorations: tally_dict.setdefault(exploration['from'], 0) tally_dict[exploration['from']] += 1 print(tally_dict) if ex_cfg.div_algorithm == 'hyperball': graphs.coverage(s_channels, ex_cfg.threshold, s_vectors=s_vectors, title=title) else: assert ex_cfg.div_algorithm == 'grid' if mesh is not None: graphs.mesh(mesh, title=title) graphs.hold(True) graphs.spread(s_channels, s_vectors=s_vectors, e_radius=1.25, e_alpha=0.75) # interest measure colors = [graphs.BLUE, graphs.PINK] weight_lists = zip(*weight_history['data']) for i, weights in enumerate(weight_lists): graphs.perf_std(range(len(weights)), weights, [0.0 for _ in weights], legend=weight_history['ex_names'][i], color=colors[i], alpha=0.5, plot_width=1000, plot_height=300, title='diversity: {}'.format(title)) graphs.hold(True) graphs.hold(False) # # usage with sliding window window = 100.0 uuid_history = tuple(e[0]['uuid'] for e in explorations) for i, weights in enumerate(weight_lists): ex_uuid = weight_history['ex_uuids'][i] ex_name = weight_history['ex_names'][i] usage = [t_usage(window, t, ex_uuid, uuid_history) for t in range(len(uuid_history))] graphs.perf_std(range(len(usage)), usage, [0.0 for _ in usage], color=colors[i], alpha=0.5, plot_width=1000, plot_height=300, title='usage: {}'.format(title), y_range=(0.0, 1.0)) graphs.hold(True) graphs.hold(False) # print('{} {:.3f}'.format(env_name, np.average(errors))) return tally_dict
radius, alpha = 1.0, 0.35 if ex_name == 'distrib_corner': radius, alpha = 0.75, 0.15 plotting.circle([0.0], [0.0], radius=1.0, x_range=(-xy_range, xy_range), y_range=(-xy_range, xy_range), fill_color='#000000', fill_alpha=0.075, line_color=None, title='goal distribution for {}'.format(ex_name)) graphs.hold(True) graphs.spread(ex.s_channels, s_vectors=(), s_goals=s_goals, g_radius=radius, g_alpha=alpha, grid=None, title='{} goals'.format(ex_name)) graphs.spread(ex.s_channels, s_vectors=s_vectors, s_goals=(), e_radius=1.0, e_alpha=0.35, grid=None, title=ex_name) graphs.show()
N = 10000 graphs.output_file('c0_fig2_mb_vs_gb.html') for env_name in ['kin2_150', 'kin7_150', 'kin20_150', 'kin100_150']: for ex_name in ['random.motor', 'random.goal']: random.seed(0) # instanciating the environment env_cfg = envs.catalog[env_name]._deepcopy() env = environments.Environment.create(env_cfg) # instanciating the explorer ex_cfg = exs.catalog[ex_name]._deepcopy() ex_cfg.m_channels = env.m_channels ex_cfg.s_channels = env.s_channels ex = explorers.Explorer.create(ex_cfg) # running the exploration explorations, s_vectors, s_goals = factored.run_exploration(env, ex, N) # making graphs graphs.spread(env.s_channels, s_vectors=s_vectors, e_radius=1.3, e_alpha=0.5, grid=False, title='{}::{}'.format(ex_name, env_name)) graphs.show()
tools.to_vector(exploration['s_goal'], env.s_channels)) explorations.append((exploration, feedback)) if t + 1 in milestones: idx = milestones.index(t + 1) last_milestone = milestones[idx - 1] alpha = 0.75 if t + 1 != N else 0.20 radius = 1.5 if t + 1 != N else 1.5 # making graphs print('{: 6.0f}: {} ({})'.format( t + 1, ex.m_channels[0].bounds, lrn_name)) graphs.spread(ex.s_channels, s_vectors=s_vectors[:last_milestone], e_alpha=0.50, title=']{}, {}] period : {} ({})'.format( last_milestone, t + 1, ex.m_channels[0].bounds, lrn_name)) graphs.hold(True) graphs.spread(ex.s_channels, s_vectors=s_vectors[last_milestone:], e_alpha=alpha, e_radius=radius) # display postures graphs.hold(True) graphs.posture_random(env, explorations[last_milestone:], n=5, radius_factor=0.50) graphs.hold(False)
kin_cfg = envs.catalog['kin20_150'] kin = environments.Environment.create(kin_cfg) dataset = {'s_channels': kin.s_channels, 's_signals': []} s_vectors = [] RES = 70 for i in range(RES): for j in range(RES): s_vector = [(k + 0.5) / RES * (c.bounds[1] - c.bounds[0]) + c.bounds[0] for k, c in zip([i, j], kin.s_channels)] if s_vector[0]**2 + s_vector[1]**2 <= 1.0: s_signal = environments.tools.to_signal(s_vector, kin.s_channels) dataset['s_signals'].append(s_signal) s_vectors.append(s_vector) datafile.save_file(dataset, '../../testsets/testset_kinone') if __name__ == '__main__': import graphs graphs.output_file('c3_fig3_1_kin_testset.html') graphs.spread(kin.s_channels, s_vectors=s_vectors, e_radius=1.5, e_alpha=0.75, title='{} tests'.format(len(s_vectors))) graphs.grid().grid_line_color = 'white' graphs.show()
env = environments.Environment.create(env_cfg) ex_cfg = exs.catalog[ex_name]._deepcopy() ex_cfg.m_channels = env.m_channels ex_cfg.s_channels = env.s_channels ex = explorers.Explorer.create(ex_cfg) mesh = explorers.ExplorerMeshGrid({'res': RES}, env.s_channels, env.m_channels) # running the exploration prefix = '{} {}'.format(env_name, ex_name) explorations, s_vectors, s_goals = factored.run_exploration( env, ex, N, mesh=mesh, prefix=prefix) # making graphs graphs.spread(ex.s_channels, s_vectors=s_vectors, e_radius=1.3, e_alpha=0.35, title='{} {}'.format(env_name, ex_name)) graphs.hold(True) graphs.posture_idxs(env, explorations, alpha=1.0, idxs=[0, 1000, 2500, 5000, 7500], radius_factor=0.75) # graphs.posture_extrema(env, explorations, alpha=1.0, radius_factor=0.75) graphs.show()
random.seed(0) # instanciating the environment env_cfg = envs.catalog[env_name]._deepcopy() env = environments.Environment.create(env_cfg) ex_cfg = exs.catalog[ex_name]._deepcopy() ex_cfg.m_channels = env.m_channels ex_cfg.s_channels = env.s_channels ex = explorers.Explorer.create(ex_cfg) # running the exploration explorations, s_vectors, s_goals = factored.run_exploration(env, ex, N) # making graphs cov = factored.run_coverage(TAU, s_vectors) graphs.coverage(env.s_channels, TAU, s_vectors=s_vectors, c_alpha=1.0, title='cov={:.2f} {}::{}'.format( cov, ex_name, env_name)) graphs.hold(True) graphs.spread(env.s_channels, s_vectors=s_vectors, e_radius=2.0, e_alpha=1.0, title='{}:{}'.format(env_name, ex_name)) graphs.show()
# Splitting the trials s_vectors_pos, s_vectors_neg = [], [] for explo, s_vector in zip(explorations, s_vectors): if explo[0]['m_signal']['j0'] > 0: s_vectors_pos.append(s_vector) else: s_vectors_neg.append(s_vector) graphs.output_file('c0_fig4_kin2_decomp.html') # Positive Graph graphs.spread(env.s_channels, s_vectors=s_vectors_pos, e_radius=1.0, e_alpha=0.5, title='{}::{} [positive]'.format(env_name, ex_name)) graphs.hold(True) graphs.posture_signals(env, [{'j0': i, 'j1':-150+2*i} for i in range(150, -1, -10)], color='#333333', alpha=0.5, swap_xy=True) graphs.hold(False) # Negative Graph graphs.spread(env.s_channels, s_vectors=s_vectors_neg, e_radius=1.0, e_alpha=0.5, title='{}::{} [negative]'.format(env_name, ex_name)) graphs.hold(True) graphs.posture_signals(env, [{'j0': -i, 'j1':-150+2*i} for i in range(0, 151, 10)], color='#333333', alpha=0.5, swap_xy=True) graphs.hold(False)
} ex = explorers.Explorer.create(ex_cfg, datasets=[dataset]) # running the exploration explorations, s_vectors, s_goals = factored.run_exploration( env, ex, N, verbose=True) # making graphs milestones = [0, 100, 200, 500, 1000, 2000, 5000, N] for t in milestones[1:]: alpha = 0.5 if t == 100 else 0.25 graphs.spread(ex.s_channels, s_vectors=s_vectors[:t], s_goals=(), e_radius=2.0, e_alpha=alpha, x_range=(-1.05, 1.05), y_range=(-1.05, 1.05), title='demo:{}, t={}'.format(env_name, t)) graphs.hold(True) graphs.posture_signals(env, dataset['m_signals'], radius_factor=0.35, alpha=0.75) graphs.hold(True) graphs.spread(ex.s_channels, s_vectors=s_vectors[:1], s_goals=(), e_radius=2.0, e_alpha=.0, e_color='#DF6464')
random.seed(0) print(disturb, env_name) # instanciating the environment env_cfg = envs.catalog[env_name] env = environments.Environment.create(env_cfg) # instanciating the explorer ex_cfg = exs.catalog['random.goal']._deepcopy() ex_cfg.ex_1.learner.m_disturb = disturb ex_cfg.m_channels = env.m_channels ex_cfg.s_channels = env.s_channels ex = explorers.Explorer.create(ex_cfg) # running the exploration explorations, s_vectors, s_goals = factored.run_exploration( env, ex, N, verbose=True) # making graphs radius = {0.001: 1.0, 0.005: 1.0}.get(disturb, 1.25) graphs.spread(env.s_channels, s_vectors=s_vectors, s_goals=s_goals, e_radius=radius, e_alpha=0.25, g_color=None, title='{}::{}'.format(env_name, disturb)) graphs.show()
ex = explorers.Explorer.create(ex_cfg, datasets=[dataset]) explorations, s_vectors, s_goals = factored.run_exploration(env, ex, N) graphs.output_file('c5_fig5_2.3.4_reuse.html') # Graph of reused effects in first env s_vectors0 = [] for explo in explorations[:MB]: feedback = env0.execute(explo[0]['m_signal']) s_vectors0.append( explorers.tools.to_vector(feedback['s_signal'], env0.s_channels)) graphs.spread(env.s_channels, s_vectors=s_vectors0[:MB], e_radius=3.0, e_alpha=1.0, e_color='#DF6464', title='first arm - reused effects') for e in explorations[:MB]: graphs.hold(True) graphs.posture_signals(env0, [e[0]['m_signal']], alpha=ARM_ALPHA, radius_factor=0.75) graphs.hold(True) graphs.spread(env.s_channels, s_vectors=s_vectors0[:MB], grid=False, e_radius=3.0, e_alpha=1.0, e_color='#DF6464') graphs.hold(False)
# running the exploration explorations, s_vectors, s_goals = factored.run_exploration(env, ex, N) # making graphs for t in milestones: idxs = [] for x_ in range(10): idxs.append( find_rightmost(s_vectors[:t], -x_ / 10.0, -(x_ - 1) / 10.0)) idxs.append(find_rightmost(s_vectors[:t], -0.960, -0.940)) idxs.append(find_rightmost(s_vectors[:t], -0.940, -0.920)) idxs.append(find_rightmost(s_vectors[:t], -0.920, -0.900)) idxs.append(find_rightmost(s_vectors[:t], -0.900, -0.850)) graphs.spread(env.s_channels, s_vectors=s_vectors[:t], e_radius=1.4, e_alpha=0.5, title='{}::{}::{}'.format(ex_name, env_name, t)) for idx in idxs: graphs.hold(True) graphs.posture_signals(env, [explorations[idx][0]['m_signal']], color='#666666', alpha=0.50, radius_factor=0.6) graphs.show()
mesh = explorers.ExplorerMeshGrid({'res': RES}, env.s_channels, env.m_channels) # running the exploration explorations, s_vectors, s_goals = factored.run_exploration(env, ex, N, mesh=mesh) mesh_picks = pick(mesh) # Spread Graph for t in [MB, 200, 400, N]: alpha = 1.0 if t != N else 0.5 graphs.spread(mesh.s_channels, s_vectors=s_vectors[:t], grid=False, e_radius=1.5, e_alpha=alpha, title='first arm - {} steps'.format(t)) # graphs.hold(True) # if t == N: # graphs.bokeh_spread(mesh.s_channels, s_vectors=[tools.to_vector(s, mesh.s_channels) for m, s in mesh_picks], # e_color='#DF6464', e_radius=2.0, e_alpha=1.0) # Mesh Graph graphs.mesh(mesh, s_vectors=s_vectors, mesh_colors=mesh_colors, mesh_timescale=timescale, e_radius=1.5, e_alpha=0.5, tile_ratio=1.0,
# instanciating the environment env_name, env_cfg = envs.kin(dim=DIM, limit=LIMIT) env = environments.Environment.create(env_cfg) # instanciating the explorer ex_cfg = exs.catalog[ex_name]._deepcopy() ex_cfg.m_channels = env.m_channels ex_cfg.s_channels = env.s_channels ex = explorers.Explorer.create(ex_cfg) # running exploration explorations, s_vectors, s_goals = factored.run_exploration(env, ex, N, verbose=True) # finding leftmost posture min_y, min_idx = 0, -1 for i, (x, y) in enumerate(s_vectors): if y < min_y: min_y = y min_idx = i # making graphs graphs.spread(env.s_channels, s_vectors=s_vectors, e_radius=1.5, e_alpha=0.25, plot_height=250, plot_width=800, y_range=[-1, 0.05], x_range=[-1.05/8, 1.05/8], title='{}::{}'.format(ex_name, env_name)) graphs.hold(True) graphs.posture_signals(env, [explorations[min_idx][0]['m_signal']], color='#666666', alpha=0.75, radius_factor=0.35) graphs.show()