{'fraction_non_alphanumeric': 0.03149908358552491, 'fraction_numerical': 0.009462512254379609, 'mean_word_length': 4.836318407960199, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
S-RL Toolbox: Environments, Datasets and Evaluation Metrics for State Representation Learning

State representation learning aims at learning compact representations from raw observations in robotics and control applications. Approaches used for this objective are auto-encoders, learning forward models, inverse dynamics or learning using generic priors on the state characteristics. However, the diversity in applications and methods makes the field lack standard evaluation datasets, metrics and tasks. This paper provides a set of environments, data generators, robotic control tasks, metrics and tools to facilitate iterative state representation learning and evaluation in reinforcement learning settings.


Introduction
Robotics control relies on compact and expressive representations of sensor data, as the task objectives are often expressed in much smaller dimensions than the sensor space dimension (e.g., the position of an object versus the size of an image). These representations are usually hand crafted by human experts, but deep-learning now makes it possible to avoid this feature engineering by using end-to-end learning (e.g., learning a policy from raw pixels). However, such approach is mostly possible in simulation because it requires a huge amount of training data -usually millions of samples-that makes it impractical in the real world. To overcome this issue, State Representation Learning (SRL) methods (Jonschkowski, 2018) can be used to create an intermediate representation that should contain only useful information to control a robot and thus simplify the policy learning task.
Many different SRL approaches have been proposed (see (Lesort et al., 2018) for a review), but comparing their performances is challenging. A common approach to evaluate learned representations is to compare performance in a Reinforcement Learning (RL) setting. However, because of the instability of RL algorithms and their cost, this should not be the only method used to assess learned states. Moreover, this approach gives no mean to interpret a state representation, making it difficult to understand which information is encoded in this representation.
While Reinforcement Learning has well established benchmarks, SRL has no metrics nor universal criterion to compare the different approaches. With that in mind, we propose a set of environments with an increasing difficulty, designed for comparing State Representation Learning (SRL) methods for robotic control. We also introduce qualitative and quantitative metrics along with visualization tools to facilitate the development and the comparison of SRL algorithms. The proposed framework allows fast iteration and eases research of new SRL methods by making it easy to produce statistically relevant results: the simulated environments run at 250 FPS on a 8-core machine that allows to train a RL agent on 1 Million steps in only 1h (or to generate 20k samples in less than 2 min) 1 .
In this paper, we first present quickly the reinforcement learning framework and the main state representation learning approaches that are implemented, before presenting the SRL Toolbox environments and datasets, the qualitative and quantitative evaluation methods, and a set of experiments illustrating the performances of the implemented approaches.

Reinforcement Learning and State Representation Learning
In this section, we introduce Reinforcement Learning (RL), as well as the State Representation Learning (SRL) approaches we integrated in our framework.

Reinforcement Learning
In RL, an agent must learn to select the best action to maximize a reward it will receive. More formally, in a given state s t (t denotes the current time-step), an agent performs an action a t and receives a reward r t . The learned behaviour, that should maximize the long-term discounted reward by mapping states to actions, is called a policy: a t = π(s t ).
In the most common settings, the state s t is either a low dimension representation given by an expert human, or corresponds to the raw observation (end-to-end learning). In order to differentiate these cases, we introduce the observation o t that correspond to the raw sensor data, and use the term state only to refer to low dimensional representations that can be provided by humans, or can be learned using SRL.
In this paper, we work in the context of Markov Decision Processes (MDP), where the next state of the system only depends on the previous state and the taken action. As described above, the term observations refers to raw sensor data (mostly images), but do not imply partial observability as assumed in Partially Observable Markov Decision Processes (POMDP).

State Representation Learning
SRL (Lesort et al., 2018) aims at learning compact representations from raw observations (e.g., learn a position (x, y) directly from raw pixels) without explicit supervision. Most of the time, the goal is to use that representation to solve a task with RL. The idea is that a low-dimensional representation should only keep the useful information and reduce the search space, thus contributing to address two main challenges of RL: sample inefficiency and instability. Moreover, a state representation learned for a particular task may be transferred to related tasks and therefore speed up learning in multiple task settings.
Using RL notations, SRL corresponds to learning a transformation 2 ϕ from the observation space O to the state space S. Then, a policy π, that takes a state s t ∈ S as input and outputs action a t , is learned to solve the task: In the next sections, we present approaches of SRL that are implemented in our toolbox. Each method is not mutually exclusive and can be combined to create new models.

Auto-encoders (AE, VAE)
A first approach to learn a state representation is to compress the observation into a low dimensional state that is sufficient to reconstruct the observation. This approach does not take advantage of the robotic context because it ignores the possible actions, therefore it is often associated with different objectives (e.g. forward model), and provides a performance baseline.

Robotic Priors
To build a relevant representation of states, one can use prior knowledge about the dynamics or physics of the world. This knowledge can account for temporal continuity or causality principles that reflect the interactions of an agent with its environment (Jonschkowski and Brock, 2015;Jonschkowski et al., 2017). Robotic Priors are defined as objective functions that constrain the state representation.

Forward and Inverse Models
The dynamics of the world can be integrated by learning a forward model that predicts state s t+1 given state s t and action a t . Constraints on the state representation can be added by constraining the forward model, for instance, by enforcing the system to follow linear dynamics (Watter et al., 2015).
Another approach is to learn an inverse model (Shelhamer et al., 2017;Pathak et al., 2017), which predicts the taken action a t given two successive states s t and s t+1 . This enforces the states to encode information about the dynamics, in order to recover the action needed for such transition.

Combining Approaches
Auto-encoders tend to reconstruct everything (that is salient enough in the observation), including static objects and irrelevant features for the task (distractors), whereas forward and inverse models focus on the dynamics, usually encoding the position of the controlled robot in the representation, but not a goal that is not controlled by the actions.
However, these approaches are not mutually exclusive and can be combined to create improved state representations. For instance, (Pathak et al., 2017) combine both inverse and forward models and (Zhang et al., 2018) additionally integrate an auto-encoder. In the same vein, Ha and Schmidhuber (2018) use a VAE with a recurrent forward model to learn a state representation.

Datasets and Environments
In this section, we describe a set of environments with incremental difficulty, designed to assess SRL algorithms for robotic control. They all follow the interface defined by OpenAI Gym (Brockman et al., 2016), which makes integration with RL algorithms easy.

Environments Details
The settings we propose ( Fig. 1) are variations of two environments: a 2D environment with a mobile robot and a 3D environment with a robotic arm. In all settings, there is a controlled robot and one or more targets (that can be static, randomly initialized or

Mobile Navigation
Robotic Arm Real Robot Figure 1: Environments and datasets for state representation learning. moving). Each environment can either have a continuous or discrete action space, and the reward can be sparse or shaped, allowing us to cover many different situations.
Static & random target mobile navigation: This setting simulates a navigation task using a small car resembling the task of (Jonschkowski and Brock, 2014), with either a cylinder or a horizontal band on the ground as a goal, which can be fixed or moving from episode to episode. The car can move in four directions (forward, backward, left, right) and will get a +1 reward when reaching the target, -1 when hitting walls, and 0 otherwise.
Static & random target robotic arm: This setting simulates a robotic arm (Kuka), fixed on a table, with the task of pushing a button that may move or not in between episodes. The arm can be controlled either in the x, y and z position using inverse kinematics, or directly controlling the joints. The robot will get +1 reward when the arm pushes the button, -1 when it hits the table (this will end the episode), and 0 otherwise. A variant adds distractors, i.e., moving objects on the table irrelevant for solving the task.
Simulated & real robotic arm: We used a real Baxter robot arm (Gazebo in simulation) to perform the same button pushing task as the previous task, with the same actions and the same rewards. The goal is to test the different methods in a real world setup.
A ground truth state is defined in each scenario: the absolute robot position in static scenarios and the relative position (w.r.t. the target) in moving goal scenarios. Note that apart from providing all described environments, we also provide the corresponding datasets used in our evaluations: images are 224x224 pixels, navigation datasets use 4 discrete actions (right, left, forward, backward ); robot arms use one more (down) action.
In section A.2, we provide baselines results (Ground Truth, Auto-Encoder, Raw Pixels) for each environment.

Motivation of the Goal-Based Robotics Tasks
The environments proposed have several characteristics that make them suitable for research and benchmarking.
Designed for Robotics: The proposed environments cover basic goal-based robotics tasks: navigation for a mobile robot and reaching a desired position for a robotic arm.
Designed for State Representation Learning: The simplicity of the environments makes the extracted features easier to interpret (correlation can be computed between learned states and position of relevant objects). It is also clear what a good state representation should encode because of the small number of important elements: there is only the controllable robot and the target.
Designed for Research: The environments have incremental difficulty, the minimal number of variables for describing each environment (minimal state dimension for solving the task with RL) is increasing from 2 (mobile robot with static target) to 6 (robotic arm with random target). Having simple environments of gradual difficulty is really important when developing new methods. The proposed environments are also easily customizable so that they cover all possibilities: reward can be sparse/dense, actions can be continuous/discrete. Finally, our benchmark is completely free and fast (it runs at 250 FPS on a 8-core machine with one GPU).

Evaluation of Learned State Representations
The most practical evaluation of SRL is assessing if the learned states can be used for solving the task in RL. However, algorithm development can benefit from other metrics and visually assessing the validity of the representation being learned, for faster iteration and interpretation of the state embedding space. We provide tools and metrics for this.

Real-time SRL
Interactive scatter Latent visualization Qualitative evaluation in our case is the perceived utility of the state representation using visualization tools. The perceived utility depends on the task at hand. For example, the state representation of the robotic arm dataset is expected to have a continuous and correlated change with respect to the arm tip position. Three tools are proposed (Fig. 2): Real-time SRL: This tool is used in conjunction with a graphical interface of the simulated environment. It shows the correspondence between observation and state by plotting current position of the observation in the state representation.
Interactive scatter : A clickable plot of the state representation, with the reward defining the colour for each point. Here, we expect to visualize structure in the state representation.
Latent visualization: It allows to navigate in the latent space by projecting the state to the observation space. This is achieved either by reconstructing the output (for AE and VAE), or by using a nearest neighbour approach for the models lacking a reconstruction.
To deal with state dimensions larger than three, PCA is used to visually assess the learned representations in a qualitative manner.
These tools allow to have better insights of the learned representation over different settings of state representation learning. This is especially useful in situations where the state dimension is greater than 3. This way, we are able to validate different configurations before running more exhaustive and time consuming methods.

KNN-MSE
We use an assessment of the representation's quality based on a Nearest-Neighbours approach (as in (Sermanet et al., 2017)). While the nearest neighbour coherence can be assessed visually, KNN-MSE (Lesort et al., 2017) derives a quantitative metric from this information.
For a given observation o, we find the nearest neighbours of its associated state s in the learned state space, and project them in the ground truth state space. Then we compute the average distance to its neighbours in the latter space: where KNN(s, k) returns the k nearest neighbours of s (chosen with the Euclidean distance) in the learned state space S,s is the ground truth state associated to s, ands is the one associated to s . A low KNN-MSE means that a neighbour in the ground truth is still a neighbour in the learned representation, and thus, local coherence is preserved.

Correlation
A Pearson ρ correlation coefficient's matrix is computed for each dimension pair (s,s), wheres is the ground truth (GT) state, s the learned state, and µ s and σ s are the mean and standard deviation, respectively, of state s: We can visualize the correlation matrix to quantitatively assess the ability of a model to encode relevant information in the states learned. For instance, the correlation matrix in Figure 3 shows degrees of correlation between the mobile robot position and the learned states. The plot illustrates that for each dimension i of the predicted states s, there is a correlation close to 1 (in absolute value) with at least one dimension j of the agent's real positions j . Therefore, this gives measurable evidences that the model was able to encode the position of the mobile robot.  This visualization tool is quite useful for low-dimensional spaces. However, for state spaces with a high number of dimensions, looking at the correlation matrix becomes impractical. Therefore, we introduce the following measure, named GTC for Ground Truth Correlation, that allows to compare the models ability to encode relevant information: with i ∈ 0, |s| , j ∈ 0, |s| ,s = [s 1 ; ...;s n ], ands k being the k th dimension of the ground truth state vector.
For instance, in the Mobile Robot environment with random target, the ground truth state is composed of the 2D robot position and 2D target position. That is to say, the ground truth states have a dimension of 4: |s| = 4.
The vector GTC gives for each component i of the ground truth statess, the maximum absolute correlation value betweens i and any component of the predicted states s. Therefore, GTC measures the similarity per component, between the learned states s and the ground truth statess.
We also introduce a metric, which is the mean of GTC , that allows to compare learned states using one scalar value:

Experiments
We perform experiments on the proposed datasets using states learned with the approaches described in Section 2.2 along with ground truth (GT). Here, we report results obtained with PPO.
Ground Truth States Learned States RL Performance   Table 2: KNN-MSE results for each SRL method. Ground Truth (robot absolute or relative position with respect to target object), auto-encoders, forward (fwd), inverse (inv) models and combinations.
The table 3 gives the GT C mean metrics for several approaches and the associated RL performance using PPO. It shows that GT C mean is a good indicator for the performance than can be obtained in RL: a good disentanglement with a good correlation with the ground truth state (i.e. a high GT C mean ) lead to a higher mean reward in RL.
During the development of S-RL Toolbox, we learned some useful insights on SRL. We observed that auto-encoders do not reconstruct objects if they are too small. This is an issue if the object is relevant for the task. An inverse model is usually sufficient to learn a coherent state representation (in our case, the position of the controllable object). Continuity in the state space is important to perform well in RL. Using real-time SRL tools, we note discontinuities in the state space learned by AE, even if reconstruction error is low, and that hinders RL.  Table 3: GTC and GT C mean , and mean reward performance in RL (using PPO) per episode after 2 millions steps, with standard error for each SRL method in mobile robot with random target environment.

Related Work
In the RL literature, several classic benchmarks are used to compare algorithms. For discrete actions, Atari Games from OpenAI Gym suite (Brockman et al., 2016) are often adopted, whereas for continuous actions, MuJoCo locomotion tasks (Todorov et al., 2012) is favoured. OpenAI recently open-sourced robotics goal-based tasks . These environments are close to what we propose; however, they use a non-free physics engine, observations are not images and customization is not easy. Also, our tools were designed with SRL in mind and offer a gradual difficulty.
Regarding the SRL literature, very diverse environments are used, without common metrics or visualizations. The SRL methods are usually only compared with learning from raw observations. Jonschkowski and Brock (2015) assess the quality of learned representations in a slot car scenario (similar to Lange et al. (2012)) and a mobile navigation task (following Sprague (2009); Boots et al. (2011)). More recently, Ha and Schmidhuber (2018) present their results on Vizdoom and RaceCar environments. They show interesting insights of what was learned by navigating in the latent space and projecting states back to the pixel space (similar to Fig. 2). Zhang et al. (2018) use a subset of MuJoCo tasks, with joints as input, and a binary maze environment. They perform an insightful ablation study of their SRL model.
Our contribution is two-fold: we provide a framework integrated with RL algorithms, environments and tools for SRL, along with implementations of the main SRL methods.

Discussion and Conclusions
This paper presents a set of environments on which to perform SRL benchmarks of incremental difficulty to solve tasks in RL, specifically, in robotics control. Our proposed toolbox facilitates fast iterations, interpretability and reproducibility, with a set of qualitative and quantitative metrics and interactive visualization tools. We believe such a framework is needed to have fair comparisons, focused on robotics control, among SRL methods.

A.1 Datasets Details
In this section, we provide the parameters used to generate datasets, for the results presented in Table 2. The simulated datasets were created with a random policy, using PyBullet (Coumans et al., 2018) (generating up to 30k samples per minute on a 8-core machine 4 ). The real Baxter dataset was recorded using ROS.
We used 10k samples of each dataset to learn a state representation. Reward is sparse (see Section 3 for details) and actions are discrete (encoded as integers) for all datasets 5 .
Each target object can be fixed or randomly positioned between episodes; what we call "absolute" or "relative" dataset, refers to the fact of learning a relative or absolute position of the robot with respect to the target object. The images dimension in every dataset is 224x224 pixels.

A.2 Baselines Results
In this section, we provide baselines results for each environment.

A.3.1 Reinforcement Learning
We use the implementations from Stable-Baselines (Hill et al., 2018) for the RL experiments (except for CMA-ES, ARS and SAC which we implemented ourselves). Where we used the default hyperparameters set by OpenAI Baselines. With 10 random seeds in order to have quantitative results.
As for the network of the policies, the same architecture is used in all different methods. For the SRL and ground truth approaches, it is a 2-layers MLP, whereas for learning from raw pixels, it is the CNN from (Mnih et al., 2015) implemented in OpenAI baselines.
All CNN policies normalize the input image by dividing it by 255. Observations are not stacked. When learning from SRL, the states are normalized using a running mean/std average. Reinforcement learning metrics reported are the average returned rewards over 5 policies, independently trained using the same RL algorithm with a different seed.

A.3.2 State Learning Representation
For the SRL methods, we used an altered form of ResNet (Table 9), which is more compact for our needs. However, for forward and inverse models, we used a linear model in addition to the CNN for learning a state representation. We are using the Adam (Kingma and Ba, 2014) optimizer in all our models, with learning rates that vary from 10 −2 to 10 −3 . The batch size of forward and inverse is 128, 256 for robotic priors, and 32 for the other models. Table 9: CNN architecture for SRL methods. The first layers are inspired by ResNet architecture (He et al., 2015).

A.3.3 Results
Fig . 4 shows the average reward during learning of the PPO algorithm. We observed during the development of the S-RL Toolbox, that PPO was one of the best RL algorithm for SRL benchmarking. It allows us to obtain good performance and was consistent without needing to change any hyperparameters. Figure 5 illustrates this, in addition to the variability of the RL algorithms.

Appendix B. Supplementary material
The visualization and interactive state space exploration tools are demonstrated in the following videos: • S-RL Toolbox Showcase: https://youtu.be/qNsHMkIsqJc • S-RL Toolbox Environments: https://tinyurl.com/y973vhfy  • Kuka robot arm environment: State Representation Learning Benchmark running PPO on ground truth states: https://tinyurl.com/yd549l7o