Figure 7

The following script was used to generate the graphs of Figure 7 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 random

import scipy.stats
from bokeh import plotting
import pyprind # progress bars

import explorers
import environments

import dotdot
import exs
import envs
import factored
import graphs


random.seed(0)
graphs.output_notebook()
In [2]:
DIM = 20    # number of joints
N   = 20000 # size of the total population
M   = 1000  # maximum size of subsets whose diversity is compared

env1 = environments.Environment.create(envs.catalog['kin{}_150'.format(DIM)])
env2 = environments.Environment.create(envs.catalog['kin{}_150_0.9'.format(DIM)])

m_signals = [environments.tools.random_signal(env1.m_channels) for _ in range(N)]

# creating comparative s_vectors
s_vectors1, s_vectors2 = [], []
for m_signal in m_signals:
    s_vectors1.append(environments.tools.to_vector(env1.execute(m_signal)['s_signal'], env1.s_channels))
    s_vectors2.append(environments.tools.to_vector(env2.execute(m_signal)['s_signal'], env2.s_channels))
In [3]:
# this will take a few minutes.
def compute_diversities(s_vectors1, s_vectors2):
    """Compute the diversity of random subsets of the sensory vectors"""
    divs = []
    progress_bar = pyprind.ProgBar(M-1)

    assert len(s_vectors1) == len(s_vectors2)

    
    for k in range(1, M, 1):
        for _ in range(1):
            pop_idx = random.sample(range(len(s_vectors1)), k)
            pop1 = [s_vectors1[i] for i in pop_idx]
            pop2 = [s_vectors2[i] for i in pop_idx]

            div1 = factored.run_coverage(0.05, pop1)
            div2 = factored.run_coverage(0.05, pop2)
            divs.append((div1, div2))
        progress_bar.update()
            
    return divs

divs = compute_diversities(s_vectors1, s_vectors2)
0%                          100%
[##############################] | ETA[sec]: 0.000 
Total time elapsed: 1092.569 sec
In [4]:
# Peason correlation
print(scipy.stats.pearsonr([d[0] for d in divs], [d[1] for d in divs]))
(0.9937255392078197, 0.0)
In [5]:
fig = plotting.figure(title='diversity correlation_{}'.format(DIM), x_range=[0, 1.4], y_range=[0, 1.4])
fig.scatter([d[0] for d in divs], [d[1] for d in divs],
            radius=1.2, radius_units='screen', line_color=None, fill_alpha=0.5)
graphs.show(fig)

Provenance Data

In [6]:
import provenance
prov_data = provenance.planar_arms()
print(prov_data.message())
All the code involved in the execution of this notebook is commited (no git repository in dirty state).
This notebook was executed with commit efe8d71f8242d148d3d1825f0157a48b458eb1d9.

Installed research packages (available in the submodules/ directory):
    clusterjobs  [7505201203af95d3b1074d751c0afac76f3cc619]
    environments [f1937e2ab3a381b29c6a096c9e676d502ed84ce7]
    experiments  [14acbd38d66f996f19e35f3b0a749fc9585fb03f]
    explorers    [1d284f3b1479b935f94b99b8e12c1e9432963421]
    fastlearners [870e9d472f50c0920b66b8f10df1823dbcd9d659]
    learners     [c43380e0e0cd7e6f914dbd9cd2e62e1d87003abc]
    scicfg       [63c4c5c794114ed1606124806b55aa6a56ecb689]

Installed third-party python packages:
    numpy 1.10.4
    scipy 0.17.0
    shapely 1.5.13
    sklearn 0.17

Installed third-party non-python packages:
    geos 3.5.0

Executed with:
    CPython 2.7.11 ('default', 'Feb  2 2016 04:42:29')
    [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]
    on Darwin Kernel Version 15.3.0: Thu Dec 10 18:40:58 PST 2015; root:xnu-3248.30.4~1/RELEASE_X86_64