Disentangling the independently controllable factors of variation by interacting with the world
Valentin Thomas, Emmanuel Bengio, William Fedus, Jules Pondard, Philippe Beaudoin, Hugo Larochelle, Joelle Pineau, Doina Precup, Yoshua Bengio
Introduction
When solving Reinforcement Learning problems, what separates great results from random policies is often having the right feature representation. Even with function approximation, learning the right features can lead to faster convergence than blindly attempting to solve given problems (Jaderberg et al., 2016).
The idea that learning good representations is vital for solving most kinds of real-world problems is not new, both in the supervised learning literature (Bengio, 2009; Goodfellow et al., 2016), and in the RL literature (Dayan, 1993; Precup, 2000). An alternate idea is that these representations do not need to be learned explicitly, and that learning can be guided through internal mechanisms of reward, usually called intrinsic motivation (Barto et al., ; Oudeyer and Kaplan, 2009; Salge et al., 2013; Gregor et al., 2017).
We build on a previously studied (Thomas et al., 2017) mechanism for representation learning that has close ties to intrinsic motivation mechanisms and causality. This mechanism explicitly links the agent’s control over its environment to the representation of the environment that is learned by the agent. More specifically, this mechanism’s hypothesis is that most of the underlying factors of variation in the environment can be controlled by the agent independently of one another.
We propose a general and easily computable objective for this mechanism, that can be used in any RL algorithm that uses function approximation to learn a latent space. We show that our mechanism can push a model to learn to disentangle its input in a meaningful way, and learn to represent factors which take multiple actions to change and show that these representations make it possible to perform model-based predictions in the learned latent space, rather than in a low-level input space (e.g. pixels).
Learning disentangled representations
Other authors have proposed mechanisms to disentangle underlying factors of variation. Many deep generative models, including variational autoencoders (Kingma and Welling, 2014) , generative adversarial networks (Goodfellow et al., 2014) or non-linear versions of ICA (Dinh et al., 2014; Hyvarinen and Morioka, 2016) attempt to disentangle the underlying factors of variation by assuming that their joint distribution (marginalizing out the observed ) factorizes, i.e., that they are marginally independent.
Here we explore another direction, trying to exploit the ability of a learning agent to act in the world in order to impose a further constraint on the representation. We hypothesize that interactions can be the key to learning how to disentangle the various causal factors of the stream of observations that an agent is faced with, and that such learning can be done in an unsupervised way.
The selectivity objective
To discover meaningful factors of variation and their associated policies , we consider the following general quantity which we refer to as selectivity and that is used as a reward signal for :
Here is the encoded initial state before executing and is the encoded terminal state. and represent factors of variation a factor. should be understood as a score describing how close is to the variation it caused in . For example in the experiments of section 4.1, we choose to be a gaussian kernel between and , while in the experiments of section 4.2, we choose . The intuition behind these objectives is that in expectation, a factor should be close to the variation it caused when following compared to other factors that could have been sampled and followed thus encouraging independence within the factors.
where is the set of weights shared by the factor generator, the policy network and the encoder.
Thus, our total objective along entire trajectories is a lower bound on the causal (Ziebart, 2010) or directed (Massey, 1990) information which is a measure of the causality the process exercises on the process . See Appendix C for details.
Experiments
We use MazeBase (Sukhbaatar et al., 2015) to assess the performance of our approach. We do not aim to solve the game. In this setting, the agent (a red circle) can move in a small environment ( pixels) and perform the actions down, left, right, up. The agent can go anywhere except on the orange blocks.
After jointly training the reconstruction and selectivity losses, our algorithm disentangles four directed factors of variations as seen in Figure 1: -position and -position of the agent. For visualization purposes we chose the bottleneck of the autoencoder to be of size . To complicate the disentanglement task, we added the redundant action up as well as the action down+left in this experiment.
The disentanglement appears clearly as the latent features corresponding to the and position are orthogonal in the latent space. Moreover, we notice that our algorithm assigns both actions up (white and pink dots in Figure 1.a) to the same feature. It also does not create a significant mode for the feature corresponding to the action down+left (light blue dots in Figure 1.a) as this feature is already explained by features down and left.
2 Multistep embedding of policies
In this experiment, are embeddings of -steps policies . We add a model-based loss defined only in the latent space, and jointly train a decoder alongside with the encoder. Notice that we never train our model-based cost at pixel level. While we currently suffer from mode collapsing of some factors of variations, we show that we are successfully able to do predictions in latent space, reconstruct the latent prediction with the decoder, and that our factor space disentangles several types of variations.
Conclusion, success and limitations
Pushing representations to model independently controllable features currently yields some encouraging success. Visualizing our features clearly shows the different controllable aspects of simple environments, yet, our learning algorithm is unstable. What seems to be the strength of our approach could also be its weakness, as the independence prior forces a very strict separation of concerns in the learned representation, and should maybe be relaxed.
Some sources of instability also seem to slow our progress: learning a conditional distribution on controllable aspects that often collapses to fewer modes than desired, learning stochastic policies that often optimistically converge to a single action, tuning many hyperparameters due to the multiple parts of our model. Nonetheless, we are hopeful in the steps that we are now taking. Disentangling happens, but understanding our optimization process as well as our current objective function will be key to further progress.
References
Appendix A Additional details
Through our research, we experiment with different outputs for our generator . We explored embedding the -vectors into a hypercube, a hypersphere, a simplex and also a simplex multiplied by the output of a operation on a scalar.
A.2 First experiment
In the first experiment, figure 1, we used a gaussian similarity kernel i.e with . In this experiment only, for clarity of the figure, we only allowed permissible actions in the environment (no no-op action).
Appendix B Additional Figures
Here we consider the case where we learn a latent space of size , with factors corresponding to the coordinates of (, and learn separately parameterized policies . We train our model with the selectivity objective, but no autoencoder loss, and find that we correctly recover independently controllable features on a simple environment. Albeit slower than when jointly training an autoencoder, this shows that the objective we propose is strong enough to provide a learning signal for discovering a disentangled latent representation.
We train such a model on a gridworld MNIST environment, where there are two MNIST digits . The two digits can be moved on the grid via 4 directional actions (so there are 8 actions total), the first digit is always odd and the second digit always even, so they are distiguishable. In Figure 4 we plot each latent feature as a curve, as a function of each ground truth. For example we see that the black feature recovers , the horizontal position of the first digit, or that the purple feature recovers , the vertical position of the second digit.
B.2 Planning and policy inference example in 1-step
This disentangled structure could be used to address many challenging issues in reinforcement learning. We give two examples in figure 5:
Model-based predictions: Given an initial state, , and an action sequence , we want to predict the resulting state .
A simplified deterministic policy inference problem: Given an initial state and a terminal state , we aim to find a suitable action sequence such that can be reached from by following it.
Because of the activation on the last layer of , the different factors of variation are placed on the vertices of a hypercube of dimension , and we can think of the the policy inference problem as finding a path in that simpler space, where the starting point is and the goal is . We believe this could prove to be a much easier problem to solve.
B.3 Multistep Example
We demonstrate an instance of ICF operating in a 44 Mazebase enviroment over five time steps in Figure 6. We consistently witness a failure of mode collapse in our generator and therefore the generator only produces a subset of all possible -variations. In Figure 6, we observe the governing the agent’s policy appears to correspond to moving two positions down and then to repeatedly toggle the switch. A random action due to -greedy led to the agent moving up and off the switch at time step-4. This perturbation is corrected by the policy by moving down in order to return to toggling the relevant switch.
Appendix C Variational bound and the selectivity
Let us call the probability distribution over final hidden states starting from and using the policy parametrized by the embedding .
. where is the transition probability of the environment.
For simplicity, let’s refer to as , as and as .
can be proven by using Donsker-Varadhan variational representation of the KL divergence [Donsker and Varadhan, 1975, Ruderman et al., 2012]:
As we sample the factors uniformly, our total objective is then a lower bound on which corresponds here to the directed information [Massey, 1990] Ziebart as is sampled independently from .
Appendix D Additional information on the training
In our experiments, we use the selectivity objective, an autoencoding loss and an entropy regularization loss for each of the policies . Furthermore, in experiment 4.2 we added the model-based cost with a learned two layer fully connected neural network.
The selectivity is used to update the parameters of the encoder, factor generator and policy networks. We use the following equation for computing the gradients
We also use a state dependent baseline as a control variate to reduce the variance of the REINFORCE estimator.
Furthermore, to be able to train the factor generator efficiently, we train all sampled in a mini-batch (of size ) by importance sampling on the probability ratio of the trajectory under each