In [1]:
# /!\ We're using Python 3

import plotly
import numpy as np
import plotly.plotly as py
import plotly.graph_objs as go

import matplotlib.pyplot as plt
from scipy.spatial import distance

from sklearn import preprocessing

from __future__ import division

from mpl_toolkits.mplot3d import Axes3D

%matplotlib inline

plotly.offline.init_notebook_mode(connected=True)
from IPython.core.display import display, HTML, Markdown
# The polling here is to ensure that plotly.js has already been loaded before
# setting display alignment in order to avoid a race condition.
display(HTML(
    '<script>'
        'var waitForPlotly = setInterval( function() {'
            'if( typeof(window.Plotly) !== "undefined" ){'
                'MathJax.Hub.Config({ SVG: { font: "STIX-Web" }, displayAlign: "center" });'
                'MathJax.Hub.Queue(["setRenderer", MathJax.Hub, "SVG"]);'
                'clearInterval(waitForPlotly);'
            '}}, 250 );'
    '</script>'
))

# Colorscales
def colorscale_list(cmap, number_colors, return_rgb_only=False):
    cm = plt.get_cmap(cmap)
    colors = [np.array(cm(i/number_colors)) for i in range(1, number_colors+1)]
    rgb_colors_plotly = []
    rgb_colors_only = []
    for i, c in enumerate(colors):
        col = 'rgb{}'.format(tuple(255*c[:-1]))
        rgb_colors_only.append(col)
        rgb_colors_plotly.append([i/number_colors, col])
        rgb_colors_plotly.append([(i+1)/number_colors, col])
    return rgb_colors_only if return_rgb_only else rgb_colors_plotly

from scipy.io import loadmat, whosmat
from numpy.random import randint

def formatted(f): 
    return format(f, '.2f').rstrip('0').rstrip('.')
In [2]:
!pip install --force-reinstall git+https://github.com/youqad/Neurorobotics_Project.git#egg=sensorimotor_dependencies
Collecting sensorimotor_dependencies from git+https://github.com/youqad/Neurorobotics_Project.git#egg=sensorimotor_dependencies
  Cloning https://github.com/youqad/Neurorobotics_Project.git to /private/var/folders/6z/mr5_h8cs5knf_vymb7jct8040000gn/T/pip-install-xfm94q7w/sensorimotor-dependencies
Building wheels for collected packages: sensorimotor-dependencies
  Running setup.py bdist_wheel for sensorimotor-dependencies ... done
  Stored in directory: /private/var/folders/6z/mr5_h8cs5knf_vymb7jct8040000gn/T/pip-ephem-wheel-cache-afdf5zz9/wheels/55/44/c5/17ebe4a63673ffe2fd1d70e35a212ad7bf3302b4795b7348e5
Successfully built sensorimotor-dependencies
tensorflow-tensorboard 0.4.0rc3 has requirement bleach==1.5.0, but you'll have bleach 2.1.3 which is incompatible.
tensorflow-tensorboard 0.4.0rc3 has requirement html5lib==0.9999999, but you'll have html5lib 1.0.1 which is incompatible.
Installing collected packages: sensorimotor-dependencies
  Found existing installation: sensorimotor-dependencies 0.0.1
    Uninstalling sensorimotor-dependencies-0.0.1:
      Successfully uninstalled sensorimotor-dependencies-0.0.1
Successfully installed sensorimotor-dependencies-0.0.1
In [3]:
from sensorimotor_dependencies import organisms
#organisms.Organism1(proprio=1, nb_joints=2, extero=1, nb_eyes=2).get_proprioception()
In [4]:
# Plot Figure 3a

## add "from mpl_toolkits.mplot3d import Axes3D" in the beginning

## dim 1: trial index
## dim 2: sensor number (ext + pro)
## dim 3: normalized sensory input

def plot_envchange(xs,ys,zs):
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    ax.plot_surface(xs,ys,zs)
    plt.show()

O = organisms.Organism1()
z = O.get_proprioception(return_trials=True)
#x = np.array(range(0,z.shape[0]+1))
#y = np.array(range(0,z.shape[1]+1) )
z = preprocessing.scale(z, axis=0, with_mean=True, with_std=True, copy=True)


plotly.offline.iplot([go.Surface(z=z)])
/Users/younessekaddar/.pyenv/versions/anaconda3-5.0.0/lib/python3.6/site-packages/sklearn/preprocessing/data.py:181: UserWarning:

Numerical issues were encountered when scaling the data and might not be solved. The standard deviation of the data is probably very close to 0. 

In [19]:
O = organisms.Organism1()
get_dim = O.get_dimensions(return_eigenvalues=True)
eig, ratios = get_dim[4], get_dim[5]

traces_eig, traces_rat = [], []
names = ['Body', 'Environment', 'Body and Environment']

for e, name in zip(eig, names):
    traces_eig.append(go.Scatter(
    y=e[-10::-1],
    name='Moving {}'.format(name)
    ))

for e, name in zip(ratios, names):
    traces_rat.append(go.Scatter(
    y=e,
    name='Moving {}'.format(name)
    ))
    
def layout(title):
    return go.Layout(
            title = title,
            yaxis=dict(
                type='log',
                autorange=True
                )
            )

plotly.offline.iplot(
    go.Figure(
        data=traces_eig, 
        layout=layout('Ten largest eigenvalues'))
)

plotly.offline.iplot(
    go.Figure(
    data=traces_rat,
    layout=layout('Eigenvalues ratios'))
)