F UNCTIONAL V ARIATIONAL B AYESIAN N EURAL N ETWORKS
A BSTRACT
Variational Bayesian neural networks (BNNs) perform variational inference over weights, but it is difﬁcult to specify meaningful priors and approximate posteriors in a high-dimensional weight space.
We introduce functional variational Bayesian neural networks (fBNNs), which maximize an Evidence Lower BOund (ELBO) deﬁned directly on stochastic processes, i e. distributions over functions.
We prove that the KL divergence between stochastic processes equals the supremum of marginal KL divergences over all ﬁnite sets of inputs.
Based on this, we introduce a practical training objective which approximates the functional ELBO using ﬁnite measurement sets and the spectral Stein gradient estimator.
With fBNNs, we can specify priors entailing rich structures, including Gaussian processes and implicit stochastic processes.
Empirically, we ﬁnd fBNNs extrapolate well using various structured priors, provide reliable uncertainty estimates, and scale to large datasets
I NTRODUCTION
Bayesian neural networks (BNNs) (Hinton & Van Camp, 1993; Neal, 1995) have the potential to combine the scalability, ﬂexibility, and predictive performance of neural networks with principled
Bayesian uncertainty modelling.
However, the practical effectiveness of BNNs is limited by our ability to specify meaningful prior distributions and by the intractability of posterior inference.
Choosing a meaningful prior distribution over network weights is difﬁcult because the weights have a complicated relationship to the function computed by the network.
Stochastic variational inference is appealing because the update rules resemble ordinary backprop (Graves, 2011; Blundell et al., 2015), but ﬁtting accurate posterior distributions is difﬁcult due to strong and complicated posterior dependencies (Louizos & Welling, 2016;
Zhang et al., 2018; Shi et al., 2018a).
In a classic result, Neal (1995) showed that under certain assumptions, as the width of a shallow
BNN was increased, the limiting distribution is a Gaussian process (GP).
Lee et al.
(2018) recently extended this result to deep BNNs.
Deep Gaussian Processes (DGP) (Cutajar et al., 2017; Salimbeni & Deisenroth, 2017) have close connections to BNNs due to similar deep structures.
However, the relationship of ﬁnite BNNs to GPs is unclear, and practical variational BNN approximations fail to match the predictions of the corresponding GP.
Furthermore, because the previous analyses related speciﬁc BNN architectures to speciﬁc GP kernels, it’s not clear how to design BNN architectures for a given kernel.
Given the rich variety of structural assumptions that GP kernels can represent (Rasmussen & Williams, 2006; Lloyd et al., 2014; Sun et al., 2018), there remains a signiﬁcant gap in expressive power between BNNs and GPs (not to mention stochastic processes more broadly).
In this paper, we perform variational inference directly on the distribution of functions.
Speciﬁcally, we introduce functional variational BNNs (fBNNs), where a BNN is trained to produce a distribution of functions with small KL divergence to the true posterior over functions.
We prove that the
KL divergence between stochastic processes can be expressed as the supremum of marginal KL divergences at ﬁnite sets of points.
Based on this, we present functional ELBO (fELBO) training objective.
Then we introduce a GAN-like minimax formulation and a sampling-based approximation for functional variational inference.
To approximate the marginal KL divergence gradients, we adopt the recently proposed spectral Stein gradient estimator (SSGE) (Shi et al., 2018b).
[Figure]
Our fBNNs make it possible to specify stochastic process priors which encode richly structured dependencies between function values.
This includes stochastic processes with explicit densities, such as GPs which can model various structures like smoothness and periodicity (Lloyd et al., 2014;
Sun et al., 2018).
We can also use stochastic processes with implicit densities, such as distributions over piecewise linear or piecewise constant functions.
Furthermore, in contrast with GPs, fBNNs efﬁciently yield explicit posterior samples of the function.
This enables fBNNs to be used in settings that require explicit minimization of sampled functions, such as Thompson sampling (Thompson, 1933; Russo & Van Roy, 2016) or predictive entropy search (Hernández-Lobato et al., 2014;
Wang &
Jegelka, 2017).
One desideratum of Bayesian models is that they behave gracefully as their capacity is increased (Rasmussen & Ghahramani, 2001).
Unfortunately, ordinary BNNs don’t meet this basic requirement: unless the asymptotic regime is chosen very carefully (e.g. Neal (1995)), BNN priors may have undesirable behaviors as more units or layers are added.
Furthermore, larger BNNs entail more difﬁcult posterior inference and larger description length for the posterior, causing degeneracy for large networks, as shown in Figure 1.
In contrast, the prior of fBNNs is deﬁned directly over the space of functions, thus the BNN can be made arbitrarily large without changing the functional variational inference problem.
Hence, the predictions behave well as the capacity increases.
Empirically, we demonstrate that fBNNs generate sensible extrapolations for both explicit periodic priors and implicit piecewise priors.
We show fBNNs outperform competing approaches on both small scale and large scale regression datasets.
fBNNs’ reliable uncertainty estimates enable state-of-art performance on the contextual bandits benchmark of Riquelme et al.
B ACKGROUND 2. V ARIATIONAL I NFERENCE FOR B AYESIAN N EURAL N ETWORKS
Given a dataset D = { ( x i , y i ) } ni =1 , a Bayesian neural network (BNN) is deﬁned in terms of a prior p ( w ) on the weights, as well as the likelihood p ( D| w ) .
Variational Bayesian methods (Hinton &
Van Camp, 1993; Graves, 2011; Blundell et al., 2015) attempt to ﬁt an approximate posterior q ( w ) to maximize the evidence lower bound (ELBO):
[Equation]
The most commonly used variational BNN training method is Bayes By Backprop (BBB) (Blundell et al., 2015), which uses a fully factorized Gaussian approximation to the posterior, i.e. q ( w ) =
N ( w ; µ , diag( σ 2 )) .
Using the reparameterization trick (Kingma & Welling, 2013), the gradients of
ELBO towards µ, σ can be computed by backpropagation, and then be used for updates.
Most commonly, the prior p ( w ) is chosen for computational convenience; for instance, independent
Gaussian or Gaussian mixture distributions.
Other priors, including log-uniform priors (Kingma et al., 2015; Louizos et al., 2017) and horseshoe priors (Ghosh et al., 2018;
Louizos et al., 2017), were proposed for speciﬁc purposes such as model compression and model selection.
But the relationships of weight-space priors to the functions computed by networks are difﬁcult to characterize.
2. S TOCHASTIC P ROCESSES
A stochastic process (Lamperti, 2012) F is typically deﬁned as a collection of random variables, on a probability space (Ω , F , P ) .
The random variables, indexed by some set X , all take values in the same mathematical space Y .
In other words, given a probability space (Ω , Σ , P ) , a stochastic process can be simply written as { F ( x ) : x ∈ X} .
For any point ω ∈ Ω , F ( · , ω ) is a sample function mapping index space
X to space Y , which we denote as f for notational simplicity.
For any ﬁnite index set x 1: n = { x 1 , ..., x n } , we can deﬁne the ﬁnite-dimensional marginal joint distribution over function values { F ( x 1 ) , · · · , F ( x n ) } .
For example, Gaussian Processes have marginal distributions as multivariate Gaussians.
The Kolmogorov Extension Theorem (Øksendal, 2003) shows that a stochastic process can be characterized by marginals over all ﬁnite index sets.
Speciﬁcally, for a collection of joint distributions ρ x 1: n , we can deﬁne a stochastic process F such that for all x 1: n , ρ x 1: n is the marginal joint distribution of F at x 1: n , as long as ρ satisﬁes the following two conditions:
Exchangeability.
For any permutation π of { 1 , · · · , n } , ρ π ( x 1: n ) ( π ( y 1: n ))
=
ρ x 1: n ( y 1: n ) .
Consistency.
For any 1 ≤ m ≤ n , ρ x 1: m ( y 1: m ) =
(cid:82) ρ x 1: n ( y 1: n ) dy
m
+1: n .
2. S PECTRAL S TEIN G RADIENT E STIMATOR (SSGE)
When applying Bayesian methods to modern probabilistic models, especially those with neural networks as components (e.g., BNNs and deep generative models), it is often the case that we have to deal with intractable densities.
Examples include the marginal distribution of a non-conjugate model (e.g., the output distribution of a BNN), and neural samplers such as GANs (Goodfellow et al., 2014).
A shared property of these distributions is that they are deﬁned through a tractable sampling process, despite the intractable density.
Such distributions are called implicit distributions (Huszár, 2017).
The Spectral Stein Gradient Estimator (SSGE) (Shi et al., 2018b) is a recently proposed method for estimating the log density derivative function of an implicit distribution, only requiring samples from the distribution.
Speciﬁcally, given a continuous differentiable density q ( x ) , and a positive deﬁnite kernel k ( x , x (cid:48) ) in the Stein class (Liu et al., 2016) of q , they show
[Equation]
where { ψ j } j ≥ 1 is a series of eigenfunctions of k given by Mercer’s theorem: k
( x , x (cid:48) )
= (cid:80) j µ j ψ j ( x ) ψ j ( x (cid:48) ) .
The Nyström method (Baker, 1997; Williams & Seeger, 2001) is used to approximate the eigenfunctions ψ j ( x ) and their derivatives.
The ﬁnal estimator is given by truncating the sum in Equation (2) and replacing the expectation by Monte Carlo estimates.
F UNCTIONAL V ARIATIONAL B AYESIAN N EURAL N ETWORKS 3. F UNCTIONAL E VIDENCE L OWER B OUND ( fELBO )
We introduce function space variational inference analogously to weight space variational inference (see Section 2.1), except that the distributions are over functions rather than weights.
We assume a stochastic process prior p over functions f : X → Y .
This could be a GP, but we also allow stochastic processes without closed-form marginal densities, such as distributions over piecewise linear functions.
For the variational posterior q φ ∈ Q , we consider a neural network architecture with stochastic weights and/or stochastic inputs.
Speciﬁcally, we sample a function from q by sampling a random noise vector ξ and deﬁning f ( x ) =
g φ ( x , ξ ) for some function g φ .
For example, standard weight space BNNs with factorial Gaussian posteriors can be viewed this way using the reparameterization trick (Kingma & Welling, 2013; Blundell et al., 2015).
(In this case, φ corresponds to the means and variances of all the weights.)
Note that because a single vector ξ is shared among all input locations, it corresponds to randomness in the function , rather than observation noise; hence, the sampling of ξ corresponds to epistemic, rather than aleatoric, uncertainty (Depeweg et al., 2017).
Functional variational inference maximizes the functional ELBO (fELBO), akin to the weight space
ELBO in Equation (1), except that the distributions are over functions rather than weights.
[Equation]
Here KL[ q (cid:107) p ] is the KL divergence between two stochastic processes.
As pointed out in Matthews et al.
(2016), it does not have a convenient form as (cid:82) log q ( f ) p ( f ) q ( f ) df due to there is no inﬁnitedimensional Lebesgue measure (Eldredge, 2016).
Since the KL divergence between stochastic processes is difﬁcult to work with, we reduce it to a more familiar object: KL divergence between the marginal distributions of function values at ﬁnite sets of points, which we term measurement sets .
Speciﬁcally, let X ∈ X n denote a ﬁnite measurement set and P X the marginal distribution of function values at X .
We equate the function space KL divergence to the supremum of marginal KL divergences over all ﬁnite measurement sets:
Theorem 1.
For two stochastic processes P and Q ,
[Equation]
Roughly speaking, this result follows because the σ -algebra constructed with the Kolmogorov
Extension Theorem (Section 2.2) is generated by cylinder sets which depend only on ﬁnite sets of points.
A full proof is given in Appendix A. fELBO.
Using this characterization of the functional KL divergence, we rewrite the fELBO:
[Equation]
We also denote L n ( q ) := inf X ∈X n L X ( q ) for the restriction to sets of n points.
This casts maximizing the fELBO as a two-player zero-sum game analogous to a generative adversarial network (GAN) (Goodfellow et al., 2014): one player chooses the stochastic network, and the adversary chooses the measurement set.
Note that the inﬁmum may not be attainable, because the size of the measurement sets is unbounded.
In fact, the function space KL divergence may be inﬁnite, for instance if the prior assigns measure zero to the set of functions representable by a neural network (Arjovsky & Bottou, 2017).
Observe that GANs face the same issue: because a generator network is typically limited to a submanifold of the input domain, an ideal discriminator could discriminate real and fake images perfectly.
However, by limiting the capacity of the discriminator, one obtains a useful training objective.
By analogy, we obtain a well-deﬁned and practically useful training objective by restricting the measurement sets to a ﬁxed ﬁnite size.
This is discussed further in the next section.
3. C HOOSING THE M EASUREMENT S ET
As discussed above, we approximate the fELBO using ﬁnite measurement sets to have a well-deﬁned and practical optimization objective.
We now discuss how to choose the measurement sets.
Adversarial Measurement Sets.
The minimax formulation of the fELBO naturally suggests a two-player zero-sum game, analogous to GANs, whereby one player chooses the stochastic network representing the posterior, and the adversary chooses the measurement set.
[Equation]
We adopt concurrent optimization akin to GANs (Goodfellow et al., 2014).
In the inner loop, we minimize L X ( q ) with respect to X ; in the outer loop, we maximize L X ( q ) with respect to q .
Unfortunately, this approach did not perform well in terms of generalization.
The measurement set which maximizes the KL term is likely to be close to the training data, since these are the points where one has the most information about the function.
But the KL term is the only part of the fELBO encouraging the network to match the prior structure.
Hence, if the measurement set is close to the training data, then nothing will encourage the network to exploit the structured prior for extrapolation.
Sampling-Based Measurement Sets.
Instead, we adopt a sampling-based approach.
In order to use a structured prior for extrapolation, the network needs to match the prior structure both near the training data and in the regions where it must make predictions.
Therefore, we sample measurement sets which include both (a) random training inputs, and (b) random points from the domain where one is interested in making predictions.
We replace the minimization in Equation (6) with a sampling distribution c , and then maximize the expected L X ( q ) :
[Equation]
where X M are M points independently drawn from c .
Consistency.
With the restriction to ﬁnite measurement sets, one only has an upper bound on the true fELBO.
Unfortunately, this means the approximation is not a lower bound on the log marginal likelihood (log-ML) log p ( D ) .
Interestingly, if the measurement set is chosen to include all of the training inputs, then L ( q ) is in fact a log-ML lower bound:
Theorem 2 (Lower Bound) .
If the measurement set X contains all the training inputs X D , then
[Equation]
The proof is given in Appendix B.1.
To better understand the relationship between adversarial and sampling-based inference, we consider the idealized scenario where the measurement points in both approaches include all training locations,
i.e., X = { X D , X M } .
Let f M , f D be the function values at X M , X D , respectively.
By Theorem 2,
[Equation]
So maximizing L X M , X D ( q ) is equivalent to minimizing the KL divergence from the true posterior on points X M , X D .
Based on this, we have the following consistency theorem that helps justify the use of adversarial and sampling-based objectives with ﬁnite measurement points.
Corollary 3 (Consistency under ﬁnite measurement points) .
Assume that the true posterior p ( f |D ) is a Gaussian process and the variational family Q is all Gaussian processes.
We have the following results if M > 1 and supp( c ) =
X :
[Equation]
The proof is given in Appendix B.2.
While it is usually impractical for the measurement set to contain all the training inputs, it is still reassuring that a proper lower bound can be obtained with a ﬁnite measurement set.
3. KL D IVERGENCE G RADIENTS
While the likelihood term of the fELBO is tractable, the KL divergence term remains intractable because we don’t have an explicit formula for the variational posterior density
q φ ( f X ) .
(Even if q φ is chosen to have a tractable density in weight space (Louizos & Welling, 2017), the marginal distribution over f X is likely intractable.)
To derive an approximation, we ﬁrst observe that
[Equation]
The ﬁrst term (expected score function) in Equation (11) is zero, so we discard it.
The Jacobian ∇ φ f X can be exactly multiplied by a vector using backpropagation.
Therefore, it remains to estimate the log-density derivatives ∇ f log q ( f X ) and ∇ f log p ( f X ) .
The entropy derivative ∇ f log q ( f X ) is generally intractable.
For priors with tractable marginal densities such as GPs (Rasmussen & Williams, 2006) 2 and Student-t Processes (Shah et al., 2014), ∇ f log p ( f X ) is tractable.
However, we are also interested in implicit stochastic process priors, i.e. ∇ f log p ( f X ) is also intractable.
Because the SSGE (see Section 2.3) can estimate score functions for both in-distribution and out-of-distribution samples, we use it to estimate both derivative terms in all our experiments.
(We compute ∇ f log p ( f X ) exactly whenever it is tractable.)
Appendix D.1 introduces an additional ﬁx to deal with the GP kernel matrix stability issue.
Require: Dataset D , variational posterior g ( · ) , prior p (explicit or implicit), KL weight λ .
Require:
Sampling distribution c for random measurement points.
1: while φ not converged do 2:
[Equation]
(cid:46) sample measurement points 3:
[Equation]
(cid:46) sample k function values 4:
[Equation]
(cid:46) compute log likelihood gradients 5: ∆
[Equation]
= SSGE( p
[Equation]
f
[Equation]
: k ) (cid:46) estimate KL gradients 6: φ ← Optimizer ( φ, ∆ 1 − λ ∆ 2 ) (cid:46) update the parameters 7: end while
3. T HE A LGORITHM
Now we present the whole algorithm for fBNNs in Algorithm 1.
In each iteration, our measurement points include a mini-batch D s from the training data and random points X M from a distribution c .
We forward
X D s and X M together through the network g ( · ; φ ) which deﬁnes the variational posterior q φ .
Then we try to maximize the following objective corresponding to fELBO:
[Equation]
Here λ is a regularization hyperparameter.
In principle, λ should be set as 1 |D| to match fELBO in
Equation (5).
However, because the KL in Equation (12) uses a restricted number of measurement points, it only terms a lower bound of the functional KL divergence KL[ q ( f ) (cid:107) p ( f )] , thus bigger λ is favored to control overﬁtting.
We used λ =
|D s | in practice, in which case Equation (12) is a proper lower bound of log p ( D s ) , as shown in Theorem 2.
Moreover, when using GP priors, we injected
Gaussian noise on the function outputs for stability consideration (see Appendix D.1 for details).
R ELATED WORK
Bayesian neural networks.
Variational inference was ﬁrst applied to neural networks by Peterson (1987) and Hinton & Van Camp (1993).
More recently, Graves (2011) proposed a practical method for variational inference with fully factorized Gaussian posteriors which used a simple (but biased) gradient estimator.
Improving on that work, Blundell et al.
(2015) proposed an unbiased gradient estimator using the reparameterization trick of Kingma & Welling (2013).
There has also been much work (Louizos & Welling, 2016; Sun et al., 2017;
Zhang et al., 2018; Bae et al., 2018) on modelling the correlations between weights using more complex Gaussian variational posteriors.
Some non-Gaussian variational posteriors have been proposed, such as multiplicative normalizing ﬂows (Louizos & Welling, 2017) and implicit distributions (Shi et al., 2018a).
Neural networks with dropout were also interpreted as BNNs (Gal & Ghahramani, 2016; Gal et al., 2017).
Local reparameterization trick (Kingma et al., 2015) and Flipout (Wen et al., 2018) try to decorrelate the gradients within a mini-batch for reducing variances during training.
However, all these methods place priors over the network parameters.
Often, spherical Gaussian priors are placed over the weights for convenience.
Other priors, including log-uniform priors (Kingma et al., 2015; Louizos et al., 2017) and horseshoe priors (Ghosh et al., 2018;
Louizos et al., 2017), were proposed for speciﬁc purposes such as model compression and model selection.
But the relationships of weight-space priors to the functions computed by networks are difﬁcult to characterize.
Functional Priors.
There have been other recent attempts to train BNNs in the spirit of functional priors.
Flam-Shepherd et al.
(2017) trained a BNN prior to mimic a GP prior, but they still required variational inference in weight space.
Noise Contrastive Priors (Hafner et al., 2018) are somewhat similar in spirit to our work in that they use a random noise prior in the function space.
The prior is incorporated by adding a regularization term to the weight-space ELBO, and is not rich enough to encourage extrapolation and pattern discovery.
Neural Processes (NP) (Garnelo et al., 2018) try to model any conditional distribution given arbitrary data points, whose prior is speciﬁed implicitly by prior samples.
However, in high dimensional spaces, conditional distributions become increasingly
2 4 31 02(a
[Figure]
BBB2 4 31 02(b)
BBB- 0 .
2 4 31 02(c)
FBNN-RBF 2 4 31 02(d)
GP-RBF 2 4 31 02(e)
FBNN-PER 2 4 31 02(f)
[Figure]
PER complicated to model.
Variational Implicit Processes (VIP) (Ma et al., 2018) are, in a sense, the reverse of fBNNs: they specify BNN priors and use GPs to approximate the posterior.
But the use of
BNN priors means they can’t exploit richly structured GP priors or other stochastic processes.
Scalable Gaussian Processes.
Gaussian processes are difﬁcult to apply exactly to large datasets since the computational requirements scale as O ( N 3 ) time, and as O ( N 2 ) memory, where N is the number of training cases.
Multiple approaches have been proposed to reduce the computational complexity.
However, sparse GP methods (Lázaro-Gredilla et al., 2010; Snelson & Ghahramani, 2006; Titsias, 2009; Hensman et al., 2013; 2015; Krauth et al., 2016) still suffer for very large dataset, while random feature methods (Rahimi & Recht, 2008; Le et al., 2013) and KISS-GP (Wilson &
Nickisch, 2015; Izmailov et al., 2017) must be hand-tailored to a given kernel.
E XPERIMENTS
Our experiments had two main aims: (1) to test the ability of fBNNs to extrapolate using various structural motifs, including both implicit and explicit priors, and (2) to test if they perform competitively with other BNNs on standard benchmark tasks such as regression and contextual bandits.
In all of our experiments, the variational posterior is represented as a stochastic neural network with independent Gaussian distributions over the weights, i.e. q ( w ) =
N ( w ; µ , diag( σ 2 )) .
3 We always used the ReLU activation function unless otherwise speciﬁed.
Measurement points were sampled uniformly from a rectangle containing the training inputs.
More precisely, each coordinate was sampled from the interval [ x min − d 2 , x max + d 2 ] , where x min and x max are the minimum and maximum input values along that coordinate, and d = x max − x min .
For experiments where we used
GP priors, we ﬁrst ﬁt the GP hyperparameters to maximize the marginal likelihood on subsets of the training examples, and then ﬁxed those hyperparameters to obtain the prior for the fBNNs.
5. E XTRAPOLATION U SING S TRUCTURED P RIORS
Making sensible predictions outside the range of the observed data requires exploiting the underlying structure.
In this section, we consider some illustrative examples where fBNNs are able to use structured priors to make sensible extrapolations.
Appendix C.2 also shows the extrapolation of fBNNs for a time-series problem.
5.1. L EARNING P ERIODIC S TRUCTURES
Gaussian processes can model periodic structure using a periodic kernel plus a RBF kernel:
[Equation]
where p is the period.
In this experiment, we consider 20 inputs randomly sampled from the interval [ − 2 , − 0 .
5] ∪ [0 . 5 , 2] , and targets y which are noisy observations of a periodic function: y = 2 ∗ sin(4 x ) + (cid:15) with (cid:15) ∼ N (0 , 0 . 04) .
We compared our method with Bayes By Backprop (BBB) (Blundell et al., 2015) (with a spherical Gaussian prior on w ) and Gaussian Processes.
For
[Figure]
fBNNs and GPs, we considered both a single RBF kernel (which does not capture the periodic structure) and PER + RBF as in eq.
(13) (which does).
As shown in Fig.
2, BBB failed to ﬁt the training data, let alone recover the periodic pattern (since its prior does not encode any periodic structure).
For this example, we view the GP with PER + RBF as the gold standard, since its kernel structure is designed to model periodic functions.
Reassuringly, the fBNNs made very similar predictions to the GPs with the corresponding kernels, though they predicted slightly smaller uncertainty.
We emphasize that the extrapolation results from the functional prior, rather than the network architecture, which does not encode periodicity, and which is not well suited to model smooth functions due to the ReLU activation function.
5.1. I MPLICIT P RIORS
Because the KL term in the fELBO is estimated using the SSGE, an implicit variational inference algorithm (as discussed in Section 2.3), the functional prior need not have a tractable marginal density.
In this section, we examine approximate posterior samples and marginals for two implicit priors: a distribution over piecewise constant functions, and a distribution over piecewise linear functions.
Prior samples are shown in Figure 3; see Appendix D.2 for the precise deﬁnitions.
In each run of the experiment, we ﬁrst sampled a random function from the prior, and then sampled 20 points from [0 , 0 . 2] and another 20 points from [0 . 8 , 1] , giving a training set of 40 data points.
To make the task more difﬁcult for the fBNN, we used the tanh activation function, which is not well suited for piecewise constant or piecewise linear functions.
Posterior predictive samples and marginals are shown for three different runs in Figure 3.
We observe that fBNNs made predictions with roughly piecewise constant or piecewise linear structure, although their posterior samples did not seem to capture the full diversity of possible explanations of the data.
Even though the tanh activation function encourages smoothness, the network learned to generate functions with sharp transitions.
5. P REDICTIVE P ERFORMANCE 5.2. S MALL S CALE D ATASETS
Following previous work (Hernández-Lobato & Adams, 2015), we then experimented with standard regression benchmark datasets from the UCI collection (Asuncion & Newman, 2007).
In particular, we only used the datasets with less than 2000 data points so that we could ﬁt GP hyperparameters by
[Table]
maximizing marginal likelihood exactly.
Each dataset was randomly split into training and test sets, comprising 90% and 10% of the data respectively.
This splitting process was repeated 10 times to reduce variability.
We compared our fBNNs with Bayes By Backprop (BBB) (Blundell et al., 2015) and Noisy K-FAC (Zhang et al., 2018).
In accordance with Zhang et al.
(2018), we report root mean square error (RMSE) and test log-likelihood.
The results are shown in Table 1.
On most datasets, our fBNNs outperformed both BBB and NNG, sometimes by a signiﬁcant margin.
5.2. L ARGE S CALE D ATASETS
Observe that fBNNs are naturally scalable to large datasets because they access the data only through the expected log-likelihood term, which can be estimated stochastically.
In this section
[Table]
we verify this experimentally.
We compared fBNNs and BBB with large scale UCI datasets, including Naval ,
Protein Structures , Video Transcoding (Memory, Time) and GPU kernel performance .
We randomly split the datasets into 80% training, 10% validation
[Table]
and 10% test.
We used the validating set to select the hyperparameters and performed early stopping.
[Table]
Both methods were trained for 80,000 iterations.
7 We used 1 hidden layer with 100 hidden units for all datasets.
For the prior of fBNNs, we used a GP with Neural Kernel Network (NKN) kernels as used in Sun et al.
We note that GP hyperparameters were ﬁt using mini-batches of sizewith 10000 iterations.
In each iteration, measurement sets consist of 500 training samples and 5 orpoints from the sampling distribution c , tuned by validation performance.
We ran each experimenttimes, and report the mean and standard deviation in Table 2.
More large scale regression results with bigger networks can be found at Appendix C.4 and Appendix C.
5. C ONTEXTUAL B ANDITS
One of the most important applications of uncertainty modelling is to guide exploration in settings such as bandits, Bayesian optimization (BO), and reinforcement learning.
In this section, we evaluate fBNNs on a recently introduced contextual bandits benchmark (Riquelme et al., 2018).
In contextual bandits problems, the agent tries to select the action with highest reward given some input context.
Because the agent learns about the model gradually, it should balance between exploration
[Table]
and exploitation to maximize the cumulative reward.
Thompson sampling (Thompson, 1933) is one promising approach which repeatedly samples from the posterior distribution over parameters, choosing the optimal action according to the posterior sample.
We compared our fBNNs with the algorithms benchmarked in (Riquelme et al., 2018).
We ran the experiments for all algorithms and tasks using the default settings open sourced by Riquelme et al.
For fBNNs, we kept the same settings, including batchsize (512), training epochs (100) and training frequency (50).
For the prior, we use the multi-task GP of Riquelme et al.
Measurement sets consisted of training batches, combined with 10 points sampled from data regions.
We ran each experiment 10 times; the mean and standard derivation are reported in Table(Appendix C.1 has the full results for all experiments.).
Similarly to Riquelme et al.
(2018), we also report the mean rank and mean regret.
As shown in Table 3, fBNNs outperformed other methods by a wide margin.
Additionally, fBNNs maintained consistent performance even with deeper and wider networks.
By comparison, BBB suffered signiﬁcant performance degradation when the hidden size was increased from 50 to 500.
This is consistent with our hypothesis that functional variational inference can gracefully handle networks with high capacity.
5. B AYESIAN O PTIMIZATION
Another domain where efﬁcient exploration requires accurate uncertainty modeling is Bayesian optimization.
Our experiments with Bayesian optimization are described in App C.3.
We compared
BBB, RBF Random Feature (Rahimi & Recht, 2008) and our fBNNs in the context of Max-value
Entropy Search (MES) (Wang & Jegelka, 2017), which requires explicit function samples for Bayesian
Optimization.
We performed BO over functions sampled from Gaussian Processes corresponding to RBF, Matern12 and ArcCosine kernels, and found our fBNNs achieved comparable or better performance than RBF Random Feature.
C ONCLUSIONS
In this paper we investigated variational inference between stochastic processes.
We proved that the
KL divergence between stochastic processes equals the supremum of KL divergence for marginal distributions over all ﬁnite measurement sets.
Then we presented two practical functional variational inference approaches: adversarial and sampling-based.
Adopting BNNs as the variational posterior yields our functional variational Bayesian neural networks.
Empirically, we demonstrated that fBNNs extrapolate well over various structures, estimate reliable uncertainties, and scale to large datasets.
A CKNOWLEDGEMENTS
We thank Ricky Chen, Kevin Luk and Xuechen Li for their helpful comments on this project.
SS was supported by a Connaught New Researcher Award and a Connaught Fellowship.
GZ was supported by an MRIS Early Researcher Award.
RG acknowledges funding from the CIFAR Canadian AI
Chairs program.
A F UNCTIONAL KL D IVERGENCE A. B ACKGROUND
We begin with some basic terminology and classical results.
See Gray (2011) and Folland (2013) for more details.
Deﬁnition 1 (KL divergence) .
Given a probability measure space (Ω , F , P ) and another probability measure M on the smae space, the KL divergence of P with respect to M is deﬁned as
[Equation]
14) where the supremum is taken over all ﬁnite measurable partitions Q = { Q i } ni =1 of Ω , and P Q , M Q represent the discrete measures over the partition Q , respectively.
Deﬁnition 2 (Pushforward measure) .
Given probability spaces ( X, F X , µ ) and ( Y, F Y , ν ) , we say that measure ν is a pushforward of µ if ν ( A ) =
µ ( f − 1 ( A )) for a measurable f : X → Y and any
A ∈ F Y .
This relationship is denoted by ν = µ ◦ f − 1 .
Deﬁnition 3 (Canonical projection map) .
Let T be an arbitrary index set, and { (Ω t , F t ) } t ∈ T be some collection of measurable spaces.
For each subset J ⊂ I ⊂ T , deﬁne Ω J = (cid:81)
t ∈ J Ω t .
We call π I
→ J the canonical projection map from I to J if
[Equation]
Where w | J is deﬁned as, if w = ( w i ) i ∈ I , then w | J = ( w i ) i ∈ J .
Deﬁnition 4 (Cylindrical σ -algebra) .
Let T be an arbitrary index set, (Ω , F ) be a measurable space.
Suppose
[Equation]
is the set of Ω -valued functions.
A cylinder subset is a ﬁnitely restricted set deﬁned as
[Equation]
Let
[Equation]
We call the σ -algebra F T :
= σ ( G Ω T ) as the cylindrical σ -algebra of Ω T , and (Ω T , F T ) the cylindrical measurable space.
The Kolmogorov Extension Theorem is the foundational result used to construct many stochastic processes, such as Gaussian processes.
A particularly relevant fact for our purposes is that this theorem deﬁnes a measure on a cylindrical measurable space, using only canonical projection measures on ﬁnite sets of points.
Theorem 4 (Kolmogorov extension theorem (Øksendal, 2003)) .
Let T be an arbitrary index set.
(Ω , F ) is a standard measurable space, whose cylindrical measurable space on T is (Ω T , F T ) .
Suppose that for each ﬁnite subset I ⊂ T , we have a probability measure µ I on Ω I , and these measures satisfy the following compatibility relationship: for each subset J ⊂
I , we have
[Equation]
Then there exists a unique probability measure µ on Ω T such that for all ﬁnite subsets I ⊂ T ,
[Equation]
In the context of Gaussian processes, µ is a Gaussian measure on a separable Banach space, and the µ I are marginal Gaussian measures at ﬁnite sets of input positions (Mallasto & Feragen, 2017).
Theorem 5.
Suppose that M and P are measures on the sequence space corresponding to outcomes of a sequence of random variables
X 0 , X 1 , · · · with alphabet A .
Let F n = σ ( X 0 , · · · , X n − 1 ) , which asymptotically generates the σ -algebra σ ( X 0 , X 1 , · · · ) .
Then
[Equation]
Where P F n , M F n denote the pushforward measures with f : f ( X 0 , X 1 , ·
· · ) = f
( X 0 , · · · , X n − 1 ) , respectively.
A. F UNCTIONAL KL DIVERGENCE
Here we clarify what it means for the measurable sets to only depend on the values at a countable set of points.
To begin with, we ﬁrstly introduce some deﬁnitions.
Deﬁnition 5 (Replacing function) .
For f ∈ Ω T , t 0 ∈ T, v ∈ Ω , a replacing function f rt 0 ,v is,
[Equation]
Deﬁnition 6 (Restricted Indices) .
For H ∈ F T , we deﬁne the free indices τ c ( H ) :
τ c ( H ) =
{ t | for any f ∈ H, we have f rt,v ∈ H for all v ∈ Ω } (23)
The complement τ ( H ) =
T \ τ c ( H ) is the set of restricted indices.
For example, for the set H = { f | f ∈ R T , f (0) ∈ ( − 1 , 2) , f (1) ∈ (0 , 1) } , the restricted indices are τ ( H ) = { 0 , 1 } .
Restricted index sets satisfy the following properties:
• for any H ∈ F T , τ ( H ) =
τ ( H c ) .
• for any indices set I and measureable sets { H i ; H i ∈ F T } i ∈
I , τ ( ∪ i ∈
I H i ) ⊆
∪ i ∈
I τ ( H i ) .
Having deﬁned restricted indices, a key step in our proof is to show that, for any measureable set H in a cylindrical measureable space (Ω T , F T ) , its set of restricted indices τ ( H ) is countable.
Lemma 6.
Given a cylindrical measureable space (Ω T , F T ) , for any H ∈ F T , τ ( H ) is countable.
Proof.
Deﬁne H =
{ H | H ∈ F T , τ ( H ) is countable } , H ⊆ F T .
By the two properties of restricted indices in Deﬁnition 6, H is a σ -algebra on Ω T .
On the other hand, F T = σ ( G Ω T ) .
Because any set in G Ω T has ﬁnite restricted indices, G Ω T ⊆ H .
Therefore H is a σ -algebra containing G Ω T .
Thus H ⊇ σ ( G Ω T ) =
F T .
Overall, we conclude H = F T .
For any H ∈ F T , τ ( H ) is countable.
Theorem 7.
For two stochastic processes P, M on a cylindrical measurable space (Ω T , F T ) , the
KL divergence of P with respect to M satisﬁes,
[Equation]
where the supremum is over all ﬁnite indices subsets T d ⊆ T , and P T d , M T d represent the canonical projection maps π T → T d of P, M , respectively.
Proof.
Recall that stochastic processes are deﬁned over a cylindrical σ -algebra F T .
By Lemma 6, for every set H ∈ F T , the restricted index set τ ( H ) is countable.
Our proof proceeds in two steps:
Any ﬁnite measurable partition of Ω T corresponds to a ﬁnite measurable partition over some Ω T c , where T c is a countable index set.
Correspondence between partitions implies correspondence between KL divergences.
KL divergences over a countable indices set can be represented as supremum of KL divergences over ﬁnite indices sets.
Step 1.
By Deﬁnition 1,
[Equation]
where the sup is over all ﬁnite measurable partitions of the function space Ω T , denoted by Q Ω T :
Q Ω
[Equation]
= { Q (1)
[Equation]
, Q ( k ) Ω T | k (cid:91) i =
Q ( i )Ω T = Ω T , Q ( i )Ω T ∈ F T are disjoint sets , k ∈ N + } .
By Lemma 6, each τ ( Q ( i )Ω T ) is countable.
So the combined restricted index set T c :
=
k
[Equation]
i
[Equation]
τ ( Q ( i )Ω T ) is countable.
Consider the canonical projection mapping π T → T c , which induces a partition on Ω T c , denoted by
Q Ω Tc :
[Equation]
The pushforward measure deﬁned by this mapping is
[Equation]
Step 2.
Then we have
[Equation]
Step 3.
Denote D ( T c ) as the collection of all ﬁnite subsets of T c .
For any ﬁnite set T d ∈ D ( T c ) , we denote P T d as the pushforward measure of P T c on Ω T d .
From the Kolmogorov Extension Theorem (Theorem 4), we know that P T d corresponds to the ﬁnite marginals of P at Ω T d .
Because T c is countable, based on Theorem 5, we have,
[Equation]
We are left with the last question: whether each T d is contained in some D ( T c ) ?
For any ﬁnite indices set T d , we build a ﬁnite measureable partition Q .
Let Ω = Ω 0 ∪ Ω 1 , Ω 0 ∩ Ω 1 = ∅ .
Assume | T d | =
K, T d = { T d ( k ) } k
=1: K , let I =
{ I i | I i
=
( I i 1 , I i 2 , · · · I iK ) } i =1:2 K to be all K -length binary vectors.
We deﬁne the partition,
[Equation]
Through this settting, Q is a ﬁnite parition of Ω T , and T c ( Q ) =
T d .
Therefore T d in Equation (28) can range over all ﬁnite index sets, and we have proven the theorem.
[Equation]
A. KL D IVERGENCE BETWEEN C ONDITIONAL S TOCHASTIC P ROCESSES
In this section, we give an example of computing the KL divergence between two conditional stochastic processes.
Consider two datasets D 1 , D 2 , the KL divergence between two conditional stochastic processes is
[Equation]
Therefore, the KL divergence between these two stochastic processes equals to the marginal KL divergence on the observed locations.
When D 2 = ∅ , p ( f |D 2 ) = p ( f ) , this shows the KL divergence between posterior process and prior process are the marginal KL divergence on observed locations.
This also justiﬁes our usage of M measurement points in the adversarial functional VI and samplingbased functional VI of Section 3.
B A DDITIONAL P ROOFS B. P ROOF FOR E VIDENCE L OWER B OUND
This section provides proof for Theorem 2.
Proof of Theorem 2.
Let X M =
X
\ X D be measurement points which aren’t in the training data.
[Equation]
B. C ONSISTENCY FOR G AUSSIAN P ROCESSES
This section provides proof for consistency in Corollary 3.
Proof of Corollary 3.
By the assumption that both q ( D ) and p ( f |D ) are Gaussian processes:
[Equation]
where m and k denote the mean and covariance functions, respectively.
In this theorem, we also assume the measurement points cover all training locations as in Equation (9), where we have (based on Theorem 2):
[Equation]
Therefore, when the variational posterior process is sufﬁciently expressive and reaches its optimum, we must have KL[ q ( f D , f M ) (cid:107) p
( f D , f M |D )]
= 0 and thus KL[ q ( f M ) (cid:107)
p ( f M |D )]
= 0 at X M =
[ x 1 , . . .
, x M ] (cid:62) ∈ X M , which implies
[Equation] [Equation]
[Figure]
Here m ( X ) =
[ m ( x 1 ) , . .
, m ( x M )] (cid:62) , and (cid:2) k
( X M , X M ) (cid:3) ij = k
( x i , x j ) .
Remember that in sampling-based functional variational inference, X M are randomly sampled from c ( x ) , and supp( c ) =
X .
Thus when it reaches optimum, we have E X M ∼ c KL[ q ( f M ) (cid:107) p ( f M |D )]
= 0 .
Because the KL divergence is always non-negative, we have that KL[ q ( f M ) (cid:107) p ( f M |D )]
= 0 for any X M ∈ X M .
For adversarial functional variational inference, this is also obvious due to sup X M KL[ q ( f M ) (cid:107) p
( f M |D )]
= 0 .
So we have that Equation (37) holds for any X M ∈ X M .
Given M > 1 , then for ∀ 1 ≤ i < j ≤ M , we have m p ( x i ) =
m q ( x i ) , and k p ( x i , x j ) =
k q ( x i , x j ) , which implies m p ( ·
[Equation]
= m q ( · ) , k p ( · , · ) =
k q ( · , · ) .
Because GPs are uniquely determined by their mean and covariance functions, we arrive at the conclusion.
C A DDITIONAL E XPERIMENTS C. C ONTEXTUAL B ANDITS
Here we present the full table for the contextual bandits experiment.
[Figure]
[Table]
C. T IME - SERIES E XTRAPOLATION
Besides the toy experiments, we would like to examine the extrapolation behavior of our method on real-world datasets.
Here we consider a classic time-series prediction problem concerning the concentration of CO 2 in the atmosphere at the Mauna Loa Observatory, Hawaii (Rasmussen &
Williams, 2006).
The training data is given from 1958 to 2003 (with some missing values).
Our goal is to model the prediction for an equally long period after 2003 (2004-2048).
In Figure 4 we draw the prediction results given by BBB, fBNN, and GP.
We used the same BNN architecture for BBB and fBNN: a ReLU network with 2 hidden layers, each with 100 units, and the input is a normalized year number augmented by its sin transformation, whose period is set to be one year.
This special design allows both BBB and fBNN to ﬁt the periodic structure more easily.
Both models are trained for 30k iterations by the Adam optimizer, with learning rate 0 .
01 and batch size 20.
For fBNN the prior is the same as the GP experiment, whose kernel is a combination of RBF, RBF ×
PER (period set to one year), and RQ kernels, as suggested in Rasmussen & Williams (2006).
Measurement points include 20 training samples and 10 points sampled from U [1958 , 2048] , and we jointly train the prior GP hyperparameters with fBNN.
In Figure 4 we could see that the performance of fBNN closely matches the exact prediction by GP.
Both of them give visually good extrapolation results that successfully model the long-term trend, local variations, and periodic structures.
In contrast, weight-space prior and inference (BBB) neither captures the right periodic structure, nor does it give meaningful uncertainty estimates.
C. B AYESIAN O PTIMIZATION
[Figure]
In this section, we adopt Bayesian Optimization to explore the advantage of coherent posteriors.
Speciﬁcally, we use Max Value Entropy Search (MES)
(Wang & Jegelka, 2017), which tries to maximize the information gain about the minimum value y (cid:63) ,
[Equation]
Where φ and Ψ are probability density function and cumulative density function of a standard normal distribution, respectively.
The y (cid:63) is the minimum of a random function from the posterior, and γ y (cid:63) ( x )
= µ t ( x ) − y (cid:63) σ t ( x ) .
With a probabilistic model, we can compute or estimate the mean µ t ( x ) and the standard deviation σ t ( x ) .
However, to compute the MES acquisition function, samples y (cid:63) of function minima are required as well, which leads to difﬁculties.
Typically when we model the data with a GP, we can get the posterior on a speciﬁc set of points but we don’t have access to the extremes of the underlying function.
In comparison, if the function posterior is represented in a parametric form, we can perform gradient decent easily and search for the minima.
We use 3-dim functions sampled from some Gaussian process prior for Bayesian optimization.
Concretely, we experiment with samples from RBF, Order-
ArcCosine and Matern12 kernels.
We compare three parametric approaches: fBNN, BBB and Random Feature (Rahimi & Recht, 2008).
For fBNN, we use the true kernel as functional priors.
In contrast, ArcCosine and Matern12 kernels do not have simple explicit random feature expressions, therefore we use RBF random features for all three kernels.
When looking for minima, we sample 10 y (cid:63) .
For each y (cid:63) , we perform gradient descent along the sampled parametric function posterior with 30 different starting points.
We usedimensions for random feature.
We use network with 5 × 100 for fBNN.
For BBB, we select the network within 1 × 100 , 3 × 100 .
Because of the similar issue in Figure 1, using larger networks won’t help for BBB.
We use batch size 30 for both fBNN and BBB.
The measurement points contain 30 training points and 30 points uniformly sampled from the known input domain of functions.
For training, we rescale the inputs to [0 , 1] , and we normalize outputs to have zero mean and unit variance.
We train fBNN and BBB for 20000 iterations and anneal the coefﬁcient of log likelihood term linearly from 0 to 1 for the ﬁrst 10000 iterations.
The results with 10 runs are shown in Figure 5.
As seen from Figure 5, fBNN and Random feature outperform BBB by a large margin on all three functions.
We also observe fBNN performs slightly worse than random feature in terms of RBF priors.
Because random feature method is exactly a GP with RBF kernel asymptotically, it sets a high standard for the parametric approaches.
In contrast, fBNN outperforms random feature for both
ArcCosine and Matern12 functions.
This is because of the big discrepancy between such kernels and
RBF random features.
Because fBNN use true kernels, it models the function structures better.
This experiment highlights a key advantage of fBNN, that fBNN can learn parametric function posteriors for various priors
[Table]
C. V ARYING DEPTH
[Table]
To compare with Variational Free Energy (VFE) (Titsias, 2009)
[Table]
we experimented with two mediumsize datasets so that we can afford to use VFE with full batch.
For VFE
[Table]
we used 1000 inducing points initialized by k-means of training point.
For BBB and FBNNs
[Table]
we used batch size 500 with a budget of 2000 epochs.
As shown in Table
[Table]
FBNNs performed slightly worse than VFE
[Table]
but the gap became smaller as we used larger networks.
By contrast, BBB totally failed with large networks (5 hidden layers with 500 hidden units each layer).
Finally, we note that the gap between FBNNs and
VFE diminishes if we use fewer inducing points (e
[Table]
g., 300 inducing points).
C. L ARGE SCALE REGRESSION WITH DEEPER NETWORKS
[Table]
In this section we experimented on large scale regression datasets with deeper networks.
For BBB and fBNNs, we used a network with 5 hidden layers of 100 units, and kept all other settings the same as Section 5.2.2.
We also compared with the stochastic variational Gaussian processes (SVGP) (Hensman et al., 2013), which provides a principled mini-batch training for sparse GP methods, thus enabling GP to scale up to large scale datasets.
For SVGP, we used 1000 inducing points initialized by k-means of training points (Note we cannot afford larger size of inducing points because of the cubic computational cost).
We used batch size 2000 and iterations 60000 to match the training time with fBNNs.
Likewise for BNNs, we used validation set to tune the learning rate from { 0 . 01 , 0 . 001 } .
We also tuned between not annealing the learning rate or annealing it by 0.1 at 30000 iterations.
We evaluated the validating set in each epoch, and selected the epoch for testing based on the validation performance.
The averaged results over 5 runs are shown in Table 6.
As shown in Table 6, SVGP performs better than BBB and fBNNs in terms of the smallest naval dataset.
However, with dataset size increasing, SVGP performs worse than BBB and fBNNs by a large margin.
This stems from the limited capacity of 1000 inducing points, which fails to act as sufﬁcient statistics for large datasets.
In contrast, BNNs including BBB and fBNNs can use larger networks freely without the intractable computational cost.
D I MPLEMENTATION D ETAILS D. I NJECTED N OISES FOR G AUSSIAN P ROCESS P RIORS
For Gaussian process priors, p ( f X ) is a multivariate Gaussian distribution, which has an explicit density.
Therefore, we can compute the gradients ∇ f log p
φ ( f X ) analytically.
In practice, we found that the GP kernel matrix suffers from stability issues.
To stabilize the gradient computation, we propose to inject a small amount of Gaussian noise on the function values, i.e., to instead estimate the gradients of ∇ φ KL[ q φ ∗ p
γ (cid:107) p ∗ p γ ] , where p γ = N (0 , γ 2 ) is the noise distribution.
This is like the instance-noise trick that is commonly used for stabilizing GAN training (Sønderby et al., 2016).
Note that injecting the noise on the GP prior is equivalent to have a kernel matrix
K + γ 2 I .
Beyond that, injecting the noise on the parametric variational posterior does not affect the reparameterization trick either.
Therefore all the previous estimation formulas still apply.
D. I MPLICIT P RIORS
Our method is applicable to implicit priors.
We experiment with piecewise constant prior and piecewise linear prior.
Concretely, we randomly generate a function f : [0 , 1] → R with the speciﬁc structure.
To sample piecewise functions, we ﬁrst sample n ∼ Poisson(3 . )
, then we have n +1 pieces within [0 , 1] .
We uniformly sample n locations from [0 , 1] as the changing points.
For piecewise constant functions, we uniformly sample n + 1 values from [0 , 1] as the function values in each piece; For piecewise linear functions, we uniformly sample n + 1 values for the values at ﬁrst n +locations, we force f (1) = 0 . .
Then we connect together each piece by a straight line.