A Unified Particle-Optimization Framework for Scalable Bayesian Sampling
Changyou Chen, Ruiyi Zhang, Wenlin Wang, Bai Li, Liqun Chen
missingum@section Introduction
Bayesian methods have been playing an important role in modern machine learning, especially in unsupervised learning (Kingma and Welling,, 2014; Li et al.,, 2017), and recently in deep reinforcement learning (Houthooft et al.,, 2016; Liu et al.,, 2017). When dealing with big data, two lines of research directions have been developed to scale up Bayesian methods, e.g., variational-Bayes-based and sampling-based methods. Stochastic gradient Markov chain Monte Carlo (SG-MCMC) is a family of scalable Bayesian learning algorithms designed to efficiently sample from a target distribution such as a posterior distribution (Welling and Teh,, 2011; Chen et al.,, 2014; Ding et al.,, 2014; Chen et al.,, 2015). In principle, SG-MCMC generates samples from a Markov chain, which are used to approximate a target distribution. Under a standard setting, samples from SG-MCMC are able to match a target distribution exactly with an infinite number of samples (Teh et al.,, 2016; Chen et al.,, 2015). However, this is practically infeasible, as only a finite number of samples are obtained. Although nonasymptotic approximation bounds w.r.t. the number of samples have been investigated (Teh et al.,, 2016; Vollmer et al.,, 2016; Chen et al.,, 2015), there are no theory/algorithms to guide learning an optimal set of fixed-size samples/particles. This is an undesirable property of SG-MCMC, because in practice one often seeks to learn the optimal samples of a finite size that best approximate a target distribution.
A remedy for this issue is to adopt the idea of particle-based sampling methods, where a set of particles (or samples) are initialized from some simple distribution, followed by iterative updates to better approximate a target distribution. The updating procedure is usually done by optimizing some metrics such as a distance measure between the target distribution and the current approximation. There is not much work in this direction for large-scale Bayesian sampling, with an outstanding representative being the Stein variational gradient descent (SVGD) (Liu and Wang, 2016a, ). In SVGD, the update of particles are done by optimizing the KL-divergence between the empirical particle distribution and a target distribution, thus the samples are designed to be updated optimally to reduce the KL-divergence in each iteration. Because of this property, SVGD is found to perform better than SG-MCMC when the number of samples used to approximate a target distribution is limited, and has been applied to other problems such as deep generative models (Feng et al.,, 2017) and deep reinforcement learning (Liu et al.,, 2017; Haarnoja et al.,, 2017; Zhang et al., 2018b, ).
Though often achieving comparable performance in practice, little work has been done on investigating connections between SG-MCMC and SVGD, and on developing particle-optimization schemes for SG-MCMC. In this paper, adopting ideas from Waserstein-gradient-flow literature, we propose a unified particle-optimization framework for scalable Bayesian sampling. The idea of our framework is to work directly on the evolution of a density functions on the space of probability measures, e.g., the Fokker-Planck equation in SG-MCMC. To make the evolution solution computationally feasible, particle approximations are adopted for densities, where particles can be optimized during the evolution process. Both SG-MCMC and SVGD are special cases of our framework, and are shown to be highly related. Notably, sampling with SG-MCMC becomes a deterministic particle-optimization problem as SVGD on the space of probability measures, overcoming the aforementioned correlated-sample issue. Furthermore, we are able to develop new unified particle-optimization algorithms by combing SG-MCMC and SVGD, which is less prone to high-dimension space and thus obtains better performance for large-scale Bayesian sampling. We conduct extensive experiments on both synthetic data and Bayesian learning of deep neural networks, verifying the effectiveness and efficiency of our proposed framework.
missingum@section Preliminaries
In this section, we review related concepts and algorithms for SG-MCMC, SVGD, and Wasserstein gradient flows (WGF) on the space of probability measures.
Generating random samples from a distribution (e.g., a posterior distribution) is one of the fundamental problems in Bayesian statistics, which has many important applications in machine learning. Traditional Markov Chain Monte Carlo methods (MCMC), such as the Metropolis–Hastings algorithm (Metropolis et al.,, 1953) produces unbiased samples from a desired distribution when the density function is known up to a normalizing constant. However, most of these methods are based on random walk proposals which suffer from high dimensionality and often lead to highly correlated samples. On the other hand, dynamics-based sampling methods such as the Metropolis adjusted Langevin algorithm (MALA) (Xifara et al.,, 2014) avoid this high degree of correlation by combining dynamical systems with the Metropolis step. In fact, these dynamical systems are derived from a more general mathematical technique called diffusion process, or more specifically, Itó diffusion (Øksendal,, 1985).
is referred to as the potential energy based on an i.i.d. assumption of the model, and is the normalizing constant. In Bayesian sampling, the posterior distribution corresponds to the (marginal) stationary distribution of a (continuous-time) Itó diffusion, defined as a stochastic differential equation of the form:
Let the density of be , it is known is characterized by the Fokker-Planck (FP) equation (Risken,, 1989):
where , for vectors and , for matrices and . The FP equation is the key to develop our particle-optimization framework for SG-MCMC. In the following, we focus on the simplest case of 1st-order Langevin dynamics if not stated explicitly, though the derivations apply to other variants.
Stochastic gradient MCMC
SG-MCMC algorithms are discretized numerical approximations of the Itó diffusion (1). They mitigate the slow mixing and non-scalability issues encountered in traditional MCMC algorithms by adopting gradient information of the posterior distribution, using minibatches of the data in each iteration of the algorithm to generate samples, and ignoring the rejection step as in standard MCMC. To make the algorithms scalable in a big-data setting, three developments will be implemented based on the Itó diffusion: define appropriate functions and in the Itó-diffusion formula so that the (marginal) stationary distributions coincide with the target posterior distribution ; replace or with unbiased stochastic approximations to reduce the computational complexity, e.g., approximating with a random subset of the data instead of using the full data. For example, in the 1st-order Langevin dynamics, could be approximated by an unbiased estimator with a subset of data:
where is a size- random subset of , leading to the first SG-MCMC algorithm in machine learning – stochastic gradient Langevin dynamics (SGLD) (Welling and Teh,, 2011); and solve the generally intractable continuous-time Itô diffusions with a numerical method, e.g., the Euler method (Chen et al.,, 2015). For example, this leads to the following update in SGLD:
2 Stein variational gradient descent
Different from SG-MCMC, SVGD initializes a set of particles which are iteratively updated so that the empirical particle distribution approximates the posterior distribution. Specifically, we consider a set of particles drawn from some distribution . SVGD tries to update these particles by doing gradient descent on the interactive particle system via
where is a function perturbation direction chosen to minimize the KL divergence between the updated density estimated by the particles and the posterior ( for short). Since is convex in , global optimum of can be guaranteed. SVGD considers as the unit ball of a vector-valued reproducing kernel Hilbert space (RKHS) associated with a kernel . In such as setting, Liu and Wang, 2016b shown:
where is called the Stein operator. Assuming that the update function is in a RKHS with kernel , it was shown in (Liu and Wang, 2016b, ) that (4) is maximized with:
SVGD applies updates (6) repeatedly, moving the samples to a target distribution .
3 Wasserstein Gradient Flows
For a better motivation of WGF, we start from gradient flows defined on the Euclidean space.
Wasserstein gradient flows
Let be an absolutely continuous curve in with finite second-order moments. We consider to define the change of ’s by investigating . Motivated by the Euclidean-space case, this is reflected by a vector field, called the velocity of the particle. A gradient flow can be defined on correspondingly (Ambrosio et al.,, 2005).
Let be an absolutely-continuous curve in with finite second-order moments. Then for a.e. , the above vector field defines a gradient flow on as: .
Intuitively, an energy functional characterizes the landscape structure (appearance) of the corresponding manifold in , and the gradient flow (7) defines a geodesic path on this manifold. Usually, by choosing appropriate , the landscape is convex, e.g., for the cases of both SG-MCMC and SVGD described below. This provides a theoretical guarantee on the optimal convergence of a gradient flow.
missingum@section Particle-Optimization-based Sampling
In this section, we interpret the continuous versions of both SG-MCMC and SVGD as WGFs, followed by several techniques for particle optimization in the next section. In the following, denotes the distribution of .
The continuous-time and infinite-particle limit of SVGD with full gradients, denoted as SVGD∞, is known to be a special instance of the Vlasov equation in nonlinear partial-differential-equation literature (Liu,, 2017):
Under this setting, we can specify the function for SVGD∞ as
As will be shown in Section 4, in (3.1) naturally leads to the SVGD algorithm, without the need to derive from an RKHS perspective.
The stationary distribution of (8) is .
To interpret SVGD∞ as a WGF, we need to specify two quantities, the energy functional and an underlying metric to measure distances between density functions.
There are two ways to derive energy functionals for SVGD∞, depending on the underlying metrics for probability distributions. When adopting the WGF framework where is used as the underlying metric, according to (7), the energy functional must satisfy
In general, there is no close-form solution for the above equation. Alternatively, Liu, (2017) proved another form of the energy functional by defining a different distance metric on the space of probability measures, called -Wasserstein distance:
where , and is the norm in the Hilbert space induced by . Under this metric, the underlying energy functional is proved to be the standard KL-divergence between and , e.g.,
As can be seen in Section 4, this interpretation allows one to derive SVGD, a particle-optimization-based algorithm to approximate the continuous-time equation (8).
2 SG-MCMC as WGF
The continuous-time limit of SG-MCMC, when considering gradients to be exact, corresponds to standard Itó diffusions. We consider the Itó diffusion of SGLD for simplicity, e.g.,
The energy functional for SG-MCMC is easily seen by noting that the corresponding FP equation (2) is in the gradient-flow form of (7). Specifically, the energy functional is defined as:
Note is the energy functional of a pure Brownian motion (e.g., in (12)). We can verify (13) by showing that it satisfies that FP equation. According to (7), the first variation of and is calculated as
Substituting (14) into (7) recovers the FP equation (2) for the Itó diffusion (12).
missingum@section Particle Optimization
Lemma 3 suggests the discrete gradient flow can approximate the original WGF arbitrarily well if a small enough stepsize is adopted. Consequently, one solves (16) through a sequence of optimization procedures to update the particles. We will derive a particle-approximation method for the term in (15), which allows us to solve SG-MCMC efficiently. However, this technique is not applicable to SVGD, as we neither have an explicit form of the energy functional in (10) when adopting the metric, nor have an explicit form for the metric in (3.1) when adopting the KL-divergence as the energy functional. Fortunately, this can be solved by the second approximation method called blob methods.
Particle approximation by blob methods
The name of blob methods comes from the classical fluids literature, where instead of evolving the density in (7), one evolves all particles on a grid with time-spacing (Carrillo et al.,, 2017). Specifically, note the function in (7) represents velocity of particles via transportation map , thus solving a WGF is equivalent to evolving the particles along their velocity in each iteration. Formally, one can prove
Let . Assume in (7) is well-defined and continuous w.r.t. each at time . Then solving the PDE (7) reduces to solving a system of ordinary differential equations for the locations of the Dirac masses:
Proposition 4 suggests evolving each particle along the directions defined by , eliminating the requirement to know an explicit form of the energy functional. In the following, we apply the above particle-optimization techniques to derive algorithms for SVGD and SG-MCMC.
1 A particle-optimization algorithm for SVGD
As mentioned above, discrete-gradient-flow approximation does not apply to SVGD. We thus rely on the blob method. From Section 3.1, in SVGD is defined as . When is approximated by particles, is simplified as:
As a result, with the definition of in (3.1), updating by time discretizing (17) recovers the update equations for standard SVGD in (6).
2 Particle-optimization algorithms for SG-MCMC
Both the discrete-gradient-flow and the blob methods can be applied for SG-MCMC, which are detailed below.
We first specify Lemma 3 in the case of SG-MCMC in Lemma 5, which is known as the Jordan-Kinderlehrer-Otto scheme (Jordan et al.,, 1998).
According to Lemma 5, it is apparent that SG-MCMC can be implemented by iteratively solving the optimization problem in (18). However, particle approximations for both terms in (18) are challenging. In the following, we develop efficient techniques to solve the problem.
First, rewrite the optimization problem in (18) as
We aim at deriving gradient formulas for both the and terms under a particle approximation in order to perform gradient descent for the particles. Let . The gradient of is easily approximated as
where is the weight for the regularizer. The optimal ’s can be obtained by applying KKT conditions to set the derivative w.r.t. to be zero, ending up with the following form:
where , . As a result, the particle gradients on can be approximated as
Theoretically, we need to adaptively update as well to ensure the constraints in (20). In practice, however, we use a fixed scaling factor to approximate for the sake of simplicity.
Particle gradients are obtained by combining (19) and (21), which are then used to update the particles by standard gradient descent. Intuitively, (19) encourages particles move to local modes while (21) regularizes particle interactions. Different from SVGD, our scheme imposes both attractive and repulsive forces for the particles. Specifically, by inspecting (21), we can conclude that: When is far from a previous particle , i.e., , is pulled close to with force proportional to ; when is close enough to a previous particle , i.e., , is pushed away, preventing it from collapsing to .
Particle optimization with blob methods
Given , particle updates can be obtained by solving (17) numerically as in SVGD. By inspecting the formula of in (4.2), the last two terms both act as repulsive forces. Interestingly, the mechanism is similar to SVGD, but with adaptive force between different particle pairs.
missingum@section The General Recipe
Based on the above development, a more general particle-optimization framework is proposed by combining the PDEs of both SG-MCMC and SVGD. As a result, we propose the following PDE to drive evolution of densities
where and are two constants. It is easily seen that to ensure the stationary distribution of (5) to be equal to , the following condition must be satisfied:
There are many feasible choices for the functions and parameters to satisfy (5). However, the verification procedure might be complicated given the present of a convolutional term in (5). We recommend the following choices for simplicity:
, , and : this reduces to the Wasserstein-based SGLD with particle optimization. Specifically, when the discrete-gradient-flow approximation is adopted, the algorithm is denoted as -SGLD; whereas when the blob method is adopted, it is denoted as -SGLD-B.
, , is defined as (3.1): this reduces to standard SVGD.
, , is defined as (3.1), and : this is the combination of SGLD and SVGD, and is called particle interactive SGLD, denoted as PI-SGLD or -SGLD.
It is easy to verify that condition (5) is satisfied for all the above three particle-optimization algorithms. Furthermore, particle updates are readily developed by applying either the discrete-gradient-flow or blob-based methods.
missingum@section Related Particle-Based MCMC Methods
There have been related particle-based MCMC algorithms. Representative methods are sequential Monte Carlo (SMC) (Moral et al.,, 2006), particle MCMC (PMCMC) (Andrieu et al.,, 2010) and many variants. In SMC, particles are sample from a proposal distribution, and the corresponding weights are updated by a resampling step. PMCMC extends SMC by sampling from an extended distribution interacted with a MH-rejection step. Compared to our framework, their proposal distributions are typically hard to choose; furthermore, optimality of the particles from both methods can not be guaranteed. Furthermore, the methods are typically much more computationally expensive. Recently, Dai et al., (2016) proposed a particle-based MCMC algorithm by approximating a target distribution with weighted kernel density estimator, which updates particle weights based on likelihoods of the corresponding particles. This approach is theoretically sound but lacks an underlying geometry interpretation. Finally, we note that -SGLD has been successfully applied to reinforcement learning recently for improved policy optimization (Zhang et al., 2018a, ).
missingum@section Experiments
We verify our framework on a set of experiments, including a number of toy experiments and applications to Bayesian sampling of deep neural networks (DNNs).
We compare various sampling methods on multi-mode toy examples, i.e., SGLD, SVGD, -SGLD, -SGLD-B and -SGLD. We aim to sample from four unnormalized 2D densities , with detailed functional form provided in the SM. We optimize/sample 2000 particles to approximate target distributions. The results are shown in Figure 1. It can be seen from Figure 1 that though SGLD maintains good asymptotic properties, it is inaccurate to approximate distributions with only a few samples; in some case, the samples cannot even cover all the modes. Interestingly, all other particle-optimization-based algorithms successfully find all the modes and fit the distributions well. -SGLD is good at finding modes, but worse at modeling the correct variance due to difficulty of controlling the balance between attractive and repulsive forces between particles. -SGLD-B is better than -SGLD at modeling the distribution variance, performing similarly to SVGD and -SGLD. Even though, we note that -SGLD is very useful when the number of particles is small, which fits a distribution better, as shown in Section E of the SM.
Bayesian Logistic regression
We next compare the three variants of our framework (i.e.SVGD, -SGLD and -SGLD-B) on a simple logistic-regression task with quantitative evaluations. We use the same model, data and experimental settings as Liu and Wang, 2016a . The Covertype dataset contains 581,012 data points and 54 features. We perform 5 runs for each setting and report the mean of testing accuracies/log-likelihoods. Figure 2 plots both test accuracies and test log-likelihoods w.r.t. the number of training iterations. It is clearly that while all methods converge to the same accuracy/likelihood level, both -SGLD and -SGLD-B converge slightly faster than SVGD. In addition, -SGLD and -SGLD-B have similar convergence behaviors, thus we only use -SGLD in the DNN experiments below.
Parameter Sensitivity
Now we study the role of hyperparameters in -SGLD: the number of particles and the scaling factor to replace the -term in (21). We use the same dataset and model as the above experiment. Figure 3 plots test accuracies along with different parameter settings. As expected, the best performance is achieved with appropriate scale of . The performance keep improving with increasing particles. Interestingly, the Wasserstein regularization is more important when the number of particles is small, demonstrating the superiority when approximate distributions with very few particles.
2 Applications on deep neural networks
We conduct experiments for Bayesian learning of DNNs. Different from traditional optimization for DNNs, we are interested in modeling weight uncertainty of neural networks, an important topic that has been well explored (Hernández-Lobato and Adams,, 2015; Blundell et al., 2015a, ; Li et al.,, 2016; Louizos and Welling,, 2016). We assign priors to the weights, which are simple isotropic Gaussian priors in our case, and perform posterior sampling with the proposed particle-optimization-based algorithms, as well as other standard algorithms such as SGLD and SGD. We use the RMSprop optimizer for feed-forward networks (FNN), and Adam for for convolutional neural networks (CNNs) and recurrent neural networks (RNNs). For all methods, we use a RBF kernel , with the bandwidth set to . Here is the median of the pairwise distance between particles. All experiments are conducted on a single TITAN X GPU.
We perform the classification tasks on the standard MNIST dataset. A two-layer model 784-X-X-10 with ReLU activation function is used, with X being the number of hidden units for each layer. The training epoch is set to 100. The test errors are reported in Table LABEL:Table:FNN. Not surprisingly, Bayesian methods generally perform better than their optimization counterparts. The new -SGLD which combines -SGLD and SVGD improves both methods with little computational overhead. In additional, -SGLD seems to perform better than SVGD in this case, partially due to a better asymptotic property mentioned in (Liu,, 2017). Furthermore, standard SGLD which is based on MCMC obtains higher test errors compared to particle-optimization-based algorithms, partially due to the correlated-sample issue discussed in the introduction. See (Blundell et al., 2015b, ) for details on the other methods in Table LABEL:Table:FNN.
We follow the standard set up as Wang et al., (2017). Specifically, we lower case all the word tokens and filter out word tokens that occur less than 10 times. All the datasets are divided into training, development and testing sets. For the language model set up, we consider a 1-layer LSTM model with 600 hidden units. The sequence length is fixed to be 30. In order to alleviate overfitting, dropout with a rate of 0.4 is used in each LSTM layer. Results in terms of test perplexities are presented in Table 3. Again, we see that -SGLD performs best among all algorithms, and -SGLD is slightly better than SVGD, both of which are better than other algorithms.
We propose a unified particle-optimization framework for large-scale Bayesian sampling. Our framework defines gradient flows on the space of probability measures, and uses particles to approximate the corresponding densities. Consequently, solving gradient flows reduces to optimizing particles on the parameter space. Our framework includes the standard SVGD as a special case, and also allows us to develop efficient particle-optimization algorithms for SG-MCMC, which is highly related to SVGD. Extensive experiments are conducted, demonstrating the effectiveness and efficiency of our proposed framework. Interesting future work includes designing more practically efficient variants of the proposed particle-optimization framework, and developing theory to study general convergence behaviors of the algorithms, in addition to the asymptotic results presented in (Liu,, 2017).
Appendix A Proof of Proposition 2
Proof A stationary distribution of (8) means . Assuming , then we need to prove that
By the definition of in (3.1), and applying Stein’s identity Liu and Wang, 2016a , we have . Consequently, we have .
The above argument indicates is a stationary distribution of (8). This completes the proof.
Appendix B More Details on Lemma 3
We first specify the conditions the energy functional needs to satisfy in Assumption 1.
proper: .
coercive: There exists , such that .
lower semicontinuous: For all such that , .
Appendix C Derivation of (22)
The derivation of (4.2) relies on the following Lemma from Carrillo et al., (2017).
where denotes function composition, i.e., is evaluated on the output of . Then we have
Now it is ready to derive (4.2). In this case, . Let , . We use particles to approximate , e.g., . We have
Combing (C) and (C) gives the formula for in (4.2).