Figure 6

The following script was used to generate the graphs of Figure 6 of the article "Behavioral Diversity Generation in Autonomous Exploration Through Reuse of Past Experience" by Fabien C. Y. Benureau and Pierre-Yves Oudeyer.

The full code is available and is distributed under the Open Science License. For any questions, remarks or difficulties running this code, contact fabien.benureau@gmail.com.

In [1]:
import os
import copy
import math

import numpy as np

import environments
from environments import tools

import experiments

import dotdot
import graphs

from fig5_cluster import planar

graphs.output_notebook()

Results

Loading results, and finding the indexes of the worst experiments for the reuse and no reuse cases (for the coverage at t=5000).

In [2]:
expcfgs = planar()
results = experiments.load_results(expcfgs, 'tcov', mask=(True, True, True))
for nor_res, src_res, tgt_res in results:
    min_nor = np.argmin(nor_res['tick_avgs'][-1])
    min_tgt = np.argmin(tgt_res['tick_avgs'][-1])
exp: data loaded in /Users/fabien/research/data/frontiers2016/planar_arms/[kin_reuse][rmb50.rgb.p0.05][kin20_150_p_0.9]/[kin_reuse][rmb50.rgb.p0.05][kin20_150_p_0.9].100.tcov.r.d
exp: data loaded in /Users/fabien/research/data/frontiers2016/planar_arms/[kin_reuse][rmb50.rgb.p0.05][kin20_150]/[kin_reuse][rmb50.rgb.p0.05][kin20_150].100.tcov.r.d
exp: data loaded in /Users/fabien/research/data/frontiers2016/planar_arms/[kin_reuse][rmb50.rgb.p0.05][kin20_150][reuse_50_1.0_20_p0.05][kin20_150_p_0.9]/[kin_reuse][rmb50.rgb.p0.05][kin20_150][reuse_50_1.0_20_p0.05][kin20_150_p_0.9].100.tcov.r.d

No Reuse Case

Distribution of the worst no-reuse experiment + cardinal and intercardinal extremum postures

In [3]:
data_min_nor = experiments.load_explorations(expcfgs, rep=min_nor)
exp: data loaded in /Users/fabien/research/data/frontiers2016/planar_arms/[kin_reuse][rmb50.rgb.p0.05][kin20_150_p_0.9]/[kin_reuse][rmb50.rgb.p0.05][kin20_150_p_0.9].21.d
exp: data loaded in /Users/fabien/research/data/frontiers2016/planar_arms/[kin_reuse][rmb50.rgb.p0.05][kin20_150]/[kin_reuse][rmb50.rgb.p0.05][kin20_150].21.d
exp: data loaded in /Users/fabien/research/data/frontiers2016/planar_arms/[kin_reuse][rmb50.rgb.p0.05][kin20_150][reuse_50_1.0_20_p0.05][kin20_150_p_0.9]/[kin_reuse][rmb50.rgb.p0.05][kin20_150][reuse_50_1.0_20_p0.05][kin20_150_p_0.9].21.d
In [4]:
def spread(d):
    env_cfg = d.job.jobcfg.exploration.env
    env = environments.Environment.create(env_cfg)

    fig = graphs.spread(d['s_channels'], s_vectors=d['s_vectors'], 
                        e_radius=1.0, e_alpha=0.5, title='{}'.format(d.job.jobcfg.key))
    return graphs.posture_extrema(env, d['explorations'], fig=fig, alpha=1.0, radius_factor=0.75, line_factor=1.0)


for nor_data, src_data, tgt_data in data_min_nor:
    # zoom code
    env_cfg = nor_data.job.jobcfg.exploration.env
    env = environments.Environment.create(env_cfg)
    zoom = graphs.posture_extrema(env, nor_data['explorations'], 
                                  x_range=[0, 0.2], y_range=[0.5, 1], 
                                  plot_width=int(80+ 0.4*(450-80)), plot_height=450,
                                  alpha=1.0, radius_factor=0.5, line_factor=1.0)
    graphs.show([[spread(nor_data), zoom]])

Reuse Case

Distribution of the worst reuse experiment + cardinal and intercardinal extremum postures

In [5]:
data_min_tgt = experiments.load_explorations(expcfgs, rep=min_tgt)
exp: data loaded in /Users/fabien/research/data/frontiers2016/planar_arms/[kin_reuse][rmb50.rgb.p0.05][kin20_150_p_0.9]/[kin_reuse][rmb50.rgb.p0.05][kin20_150_p_0.9].95.d
exp: data loaded in /Users/fabien/research/data/frontiers2016/planar_arms/[kin_reuse][rmb50.rgb.p0.05][kin20_150]/[kin_reuse][rmb50.rgb.p0.05][kin20_150].95.d
exp: data loaded in /Users/fabien/research/data/frontiers2016/planar_arms/[kin_reuse][rmb50.rgb.p0.05][kin20_150][reuse_50_1.0_20_p0.05][kin20_150_p_0.9]/[kin_reuse][rmb50.rgb.p0.05][kin20_150][reuse_50_1.0_20_p0.05][kin20_150_p_0.9].95.d
In [6]:
figs = []
for nor_data, src_data, tgt_data in data_min_tgt:
    figs.append(spread(src_data))
    figs.append(spread(tgt_data))
fig = graphs.show([figs])

Reused Commands

Showing motor commands reused by the worst reuse experiment.

In [7]:
def arm_width(env, m_signal):
    """How much lateral space a posture occupies (for screen placement)"""
    s_signal = env.execute(m_signal)
    xs, ys = zip(*env.posture)
    ys, xs = xs, ys
    return min(xs), max(xs)
In [8]:
import bokeh.models

def arm_examples(env, examples):
    """Display rotated example of arm postures"""
    fig = None
    x_offset = 0.025
    y_offset = 0.0
    examples = copy.deepcopy(examples)
    
    for i, e in enumerate(examples):
        x = env.execute(e[0]['m_signal'])['s_signal']['x']
        y = env.execute(e[0]['m_signal'])['s_signal']['y']
        e[0]['m_signal']['j19'] -= math.degrees(math.atan2(y, x))
        e[0]['m_signal']['j19'] = ((e[0]['m_signal']['j19']+180)%(360))-180

        x_min, x_max = arm_width(env, e[0]['m_signal'])
        x_offset += max(0, -x_min) + 0.05

        fig = graphs.posture_explorations(env, [e], fig=fig, x_T=x_offset, y_T=y_offset,
                                          plot_width=3800/4, plot_height=3200/4, grid=False,
                                          x_range=[0.0, 3.8], y_range=[-2.2, 1.0],
                                          alpha=0.50, radius_factor=1.0)
        
        fig.outline_line_color = None
        fig.axis.major_tick_out = 4
        fig.axis.minor_tick_out = 0
        
        fig.xgrid.grid_line_color = None
        fig.xaxis.axis_line_color = None
        fig.xaxis.major_tick_line_color = None
        fig.xaxis.major_label_text_color = None
        
        fig.yaxis.major_label_text_font_size="14pt"
        fig.yaxis[0].ticker=bokeh.models.FixedTicker(ticks=[1, 0, -1, -2, -3])

        x_offset += max(0, x_max)
        if x_offset > 3.5:            
            y_offset -= 1.0
            x_offset  = 0.025

    graphs.show(fig)
In [9]:
def _reused_commands(explorations):
    expls = []
    for expl in explorations:
        if 'ReuseExplorer' == expl[0]['from']:
            expls.append(expl)
    return expls

for nor_data, src_data, tgt_data in data_min_tgt:
    env_cfg = tgt_data.job.jobcfg.exploration.env
    env_cfg.classname = 'environments.envs.KinArmEuclidean'
    env = environments.Environment.create(env_cfg)

    reused_commands = _reused_commands(tgt_data['explorations'])#[:50]
    arm_examples(env, reused_commands)

Provenance Data

The cluster provenance code examines all the exploration data files of this experiment to check and compare their embedded provenance data.

In [10]:
import provenance 
prov_data = provenance.cluster(planar()) # this may take a minute or two.
print(prov_data.message())
All the code involved in the cluster computation was commited during job execution.
Every job was run with the same code version.

The cluster jobs were launched with commit: 3ae43f48a7ceabcbccd754c1714f89be0c5dd35c.

Installed research packages during cluster jobs execution:
    fastlearners [870e9d472f50c0920b66b8f10df1823dbcd9d659]
    clusterjobs  [7505201203af95d3b1074d751c0afac76f3cc619]
    environments [f1937e2ab3a381b29c6a096c9e676d502ed84ce7]
    scicfg       [63c4c5c794114ed1606124806b55aa6a56ecb689]
    experiments  [b9a12430484626db1140e1ae33bd11921f388112]
    learners     [c43380e0e0cd7e6f914dbd9cd2e62e1d87003abc]
    explorers    [1d284f3b1479b935f94b99b8e12c1e9432963421]

Installed third-party python packages during cluster jobs execution:
    scipy 0.17.0
    numpy 1.10.4
    shapely 1.5.13
    sklearn 0.17

Installed third-party non-python packages during cluster jobs execution:
    geos 3.5.0

Cluster jobs were executed with:
    CPython 2.7.11 ('default', 'Jan 31 2016 09:15:49')
    [GCC 4.8.2]

This notebook was executed with code commit: efe8d71f8242d148d3d1825f0157a48b458eb1d9.

In [11]: