HomeBlogProjectsResearch
← Blog

Improving PILCO with a Neural Network Gaussian Process

Rishi Edupalli,•Machine LearningResearch

Introduction and Overview

PILCO  is a model-based reinforcement learning algorithm that uses Gaussian Process inference to build a simulated model of a robotics control problem and learn how to solve it. The algorithm can solve non-trivial reinforcement learning problems from scratch with limited data and time. Unfortunately, Gaussian Processes do not scale well to more complex, non-smooth dynamics models.

To fix this issue, a new variant of PILCO called DeepPILCO was created. DeepPILCO  replaced the Gaussian Process in PILCO with a Bayesian Neural Network, which allowed the algorithm to model more complex systems. Unfortunately, a neural network requires more data to train than a Gaussian Process, which takes away from the efficiency of the algorithm.

Fortunately, Neal showed in 1996 that a neural network with one hidden layer converges to a Gaussian Process as its width goes to infinity, and a 2017 paper by Lee et al.  extended this to deep networks, giving the Neural Network Gaussian Process (NNGP). The related Neural Tangent Kernel  describes how infinitely wide networks evolve under gradient descent. My research asked whether replacing PILCO’s Gaussian Process with a Neural Network Gaussian Process would provide any performance gains.

A Quick Overview of the PILCO Algorithm

Consider a dynamical system of the form

xt+1=f(xt,ut)+ϵx_{t+1} = f(x_t,u_t) + \epsilon

where xtx_t is a vector describing the state of the system at time tt, utu_t is the control signal applied at time tt, ff is an unknown function governing the transitional dynamics of the physical system, and ϵ\epsilon is random Gaussian noise.

The goal of PILCO is to find the controller π(x,θ)=ut\pi(x,\theta) = u_t, a deterministic policy which is a function of the current state and parameters θ\theta that minimizes the expected cost c(xt)c(x_t) summed over time TT

Jπ(θ)=∑t=0TE[c(xt)].J^{\pi}(\theta) = \sum_{t=0}^T \mathbb{E}[c(x_t)].

To learn the function ff, PILCO uses Gaussian Process regression. A Gaussian Process is defined by its mean and covariance functions. PILCO utilizes a mean of zero and the Squared Exponential covariance function (kernel) which is defined as

k(x~,x~′)=α2e−12(x~−x~′)TΛ−1(x~−x~′).k(\tilde{x},\tilde{x}') = \alpha^2 e^{-\frac{1}{2} (\tilde{x} - \tilde{x}')^T \Lambda^{-1}(\tilde{x} - \tilde{x}')}.

A GP can be thought of as a probability distribution over the possible functions that fit the initial data, which is generated by applying the initial policy in PILCO. PILCO’s GP uses inputs (xt−1,ut−1)(x_{t-1}, u_{t-1}) and outputs

Δt=xt−xt−1+ϵ,ϵ∼N(0,σϵ2)\Delta_t = x_t - x_{t-1} + \epsilon, \quad \epsilon \sim \mathcal{N}(0, \sigma_{\epsilon}^2)

to predict the latent function ff, which in turn is used to predict the difference between states Δt\Delta_t given the previous control signal ut−1u_{t-1} and the previous state xt−1x_{t-1}. This probability distribution is assumed to be Gaussian and gives a one-step prediction of the dynamics of the environment. The values α2,Λ,σϵ2\alpha^2, \Lambda, \sigma_{\epsilon}^2 are hyperparameters learned via evidence maximization in the original PILCO algorithm.

PILCO creates a long-term cost by evaluating these transitions over time TT. To do this, the predictive distribution p(Δt)p(\Delta_t) needs to be calculated. Although an exact representation can be given by an integral, it is not analytically tractable, so it is assumed to be Gaussian and then approximated via Gaussian Moment Matching. p(xt+1)p(x_{t+1}) is then given by

p(xt+1)≈N(xt+1∣μt+1,Σt+1)p(x_{t+1}) \approx \mathcal{N}( x_{t+1} | \mu_{t+1}, \Sigma_{t+1})

where

μt+1=μt+μΔ\mu_{t+1} = \mu_t + \mu_{\Delta} Σt+1=Σt+ΣΔ+cov[xt,Δt]+cov[Δt,xt].\Sigma_{t+1} = \Sigma_t + \Sigma_{\Delta} + \text{cov}[x_t, \Delta_t] + \text{cov} [\Delta_t, x_t].

The total cost is then given by summing over t=0,1,…,Tt = 0, 1, \ldots, T

E[c(xt)]=∫c(xt)N(xt∣μt,Σt) dxt\mathbb{E}[ c(x_t) ] = \int c(x_t) \mathcal{N}(x_t | \mu_t, \Sigma_t) \, dx_t

for a suitable analytically tractable cost function c(xt)c(x_t).

By minimizing the cost function Jπ(θ)J^{\pi}(\theta) with respect to θ\theta, the parameters are learned until convergence to a good but not necessarily optimal policy π∗\pi^{*}.

Neural Network Gaussian Process modifications to PILCO

In a very general sense, a simple Neural Network ff can be defined as

f(x)=Aϕ(Bx)f(x) = A \phi (Bx)

where the matrices AA, BB are the parameters of the Neural Network and ϕ\phi is an element-wise activation function. The goal of the Neural Network is to then learn a relation between the input data xx and the outputs yy by minimizing the loss

L(A,B)=12∑i=1n(y(i)−f(x(i)))2L(A,B) = \frac{1}{2} \sum_{i=1}^n \left(y^{(i)} - f(x^{(i)})\right)^2

given by the sum of the squared differences between the i=1,2,…,ni = 1, 2, \ldots, n training samples y(i)y^{(i)} and the outputs of the Neural Network f(x(i))f(x^{(i)}), which can be minimized via gradient descent

A(t+1)=A(t)−α∂L∂AA^{(t+1)} = A^{(t)} - \alpha \frac{\partial L}{\partial A} B(t+1)=B(t)−α∂L∂BB^{(t+1)} = B^{(t)} - \alpha \frac{\partial L}{\partial B}

When the training of BB is frozen, training a Neural Network under gradient descent is equivalent to kernel regression where ϕ(Bx)\phi(Bx) acts as the feature map. In this low-dimensional case, this is equivalent to linear regression.

Furthermore, when BB is sampled from N(0,I)N(0, I) and the dimensions of AA and BB tend towards infinity, our Neural Network converges to a Gaussian Process. When this infinite limit has a closed form, it is known as a Neural Network Gaussian Process (NNGP). This NNGP has a kernel that depends on the architecture of the neural network and was meant to act as a drop-in replacement for the GP in PILCO.

Results

I did not end up testing NNGP-PILCO. I implemented PILCO in Python with JAX and GPJax on the cart-pole swing-up problem, and planned to build the NNGP version in Neural Tangents. Neural Tangents’ kernel has no α2\alpha^2 term, so I fixed α2=1\alpha^2 = 1.

With that setting, the rollouts were nonsensical. From the zero state, the true next state had entries of about −0.69-0.69 and −2.15-2.15, while my implementation’s predictions were wrong, often reaching about 101310^{13}. Changing how long the lengthscale Λ\Lambda was trained, from 10 to 50,000 iterations, did not fix this.

Conclusion

From this I conjectured that the lengthscale alone cannot encode both μΔ\mu_{\Delta} and ΣΔ\Sigma_{\Delta}, and that an NNGP would therefore not improve on the GP in PILCO. This is not a conclusive result. My implementation may have contained an error, I trained the hyperparameters differently from the original algorithm, and NNGP-PILCO itself was never run. Testing it directly, or re-deriving PILCO for a kernel with at least two parameters, would be the natural next step.

The slides from my presentation have more detail.