Kernel Bayes' rule
Kenji Fukumizu, Le Song, Arthur Gretton
Introduction
Kernel methods have long provided powerful tools for generalizing linear statistical approaches to nonlinear settings, through an embedding of the sample to a high dimensional feature space, namely a reproducing kernel Hilbert space (RKHS) . Examples include support vector machines, kernel PCA, and kernel CCA, among others. In these cases, data are mapped via a canonical feature map to a reproducing kernel Hilbert space (of high or even infinite dimension), in which the linear operations that define the algorithms are implemented. The inner product between feature mappings need never be computed explicitly, but is given by a positive definite kernel function unique to the RKHS: this permits efficient computation without the need to deal explicitly with the feature representation.
The mappings of individual points to a feature space may be generalized to mappings of probability measures [e.g. 3, Chapter 4]. We call such mappings the kernel means of the underlying random variables. With an appropriate choice of positive definite kernel, the kernel mean on the RKHS uniquely determines the distribution of the variable , and statistical inference problems on distributions can be solved via operations on the kernel means. Applications of this approach include homogeneity testing , where the empirical means on the RKHS are compared directly, and independence testing , where the mean of the joint distribution on the feature space is compared with that of the product of the marginals. Representations of conditional dependence may also be defined in RKHS, and have been used in conditional independence tests .
In this paper, we propose a novel, nonparametric approach to Bayesian inference, making use of kernel means of probabilities. In applying Bayes’ rule, we compute the posterior probability of in given observation in ;
where and are the density functions of the prior and the likelihood of given , respectively, with respective base measures and , and the normalization factor (y) is given by
Our main result is a nonparametric estimate of the kernel mean posterior, given kernel mean representations of the prior and likelihood.
A valuable property of the kernel Bayes’ rule is that the kernel posterior mean is estimated nonparametrically from data; specifically, the prior and the likelihood are represented in the form of samples from the prior and the joint probability that gives the likelihood, respectively. This confers an important benefit: we can still perform Bayesian inference by making sufficient observations on the system, even in the absence of a specific parametric model of the relation between variables. More generally, if we can sample from the model, we do not require explicit density functions for inference. Such situations are typically seen when the prior or likelihood is given by a random process: Approximate Bayesian Computation is widely applied in population genetics, where the likelihood is given by a branching process, and nonparametric Bayesian inference often uses a process prior with sampling methods. Alternatively, a parametric model may be known, however it might be of sufficient complexity to require Markov chain Monte Carlo or sequential Monte Carlo for inference. The present kernel approach provides an alternative strategy for Bayesian inference in these settings. We demonstrate rates of consistency for our posterior kernel mean estimate, and for the expectation of functions computed using this estimate.
An alternative to the kernel mean representation would be to use nonparametric density estimates for the posterior. Classical approaches include kernel density estimation (KDE) or distribution estimation on a finite partition of the domain. These methods are known to perform poorly on high dimensional data, however. By contrast, the proposed kernel mean representation is defined as an integral or moment of the distribution, taking the form of a function in an RKHS. Thus, it is more akin to the characteristic function approach (see e.g. ) to representing probabilities. A well conditioned empirical estimate of the characteristic function can be difficult to obtain, especially for conditional probabilities. By contrast, the kernel mean has a straightforward empirical estimate, and conditioning and marginalization can be implemented easily, at a reasonable computational cost.
The proposed method of realizing Bayes’ rule is an extension of the approach used in for state-space models. In this earlier work, a heuristic approximation was used, where the kernel mean of the new hidden state was estimated by adding kernel mean estimates from the previous hidden state and the observation. Another relevant work is the belief propagation approach in , which covers the simpler case of a uniform prior.
This paper is organized as follows. We begin in Section 2 with a review of RKHS terminology and of kernel mean embeddings. In Section 3, we derive an expression for Bayes’ rule in terms of kernel means, and provide consistency guarantees. We apply the kernel Bayes’ rule in Section 4 to various inference problems, with numerical results and comparisons with existing methods in Section 5. Our proofs are contained in Section 6 (including proofs of the consistency results of Section 3).
Preliminaries: positive definite kernel and probabilities
Throughout this paper, all Hilbert spaces are assumed to be separable. For an operator on a Hilbert space, the range is denoted by . The linear hull of a subset in a vector space is denoted by .
A positive definite kernel on is said to be bounded if there is such that for any .
Let be a measurable space, be a random variable taking values in with distribution , and be a measurable positive definite kernel on such that . The associated RKHS is denoted by . The kernel mean (also written ) of on the RKHS is defined by the mean of the -valued random variable . The existence of the kernel mean is guaranteed by . We usually write for for simplicity, where there is no ambiguity. By the reproducing property, the kernel mean satisfies the relation
for any . Plugging into this relation derives
which shows the explicit functional form. The kernel mean is also denoted by , as it depends only on the distribution with fixed.
Let and be measurable spaces, be a random variable on with distribution , and and be measurable positive definite kernels with respective RKHS and such that and . The (uncentered) covariance operator is defined as the linear operator that satisfies
for all . This operator can be identified with in the product space , which is given by the product kernel on , by the standard identification between the linear maps and the tensor product. We also define for the operator on that satisfies for any . Similarly to Eq. (4), the explicit integral expressions for and are given by
Throughout this paper, when positive definite kernels on a measurable space are discussed, the following assumption is made:
Positive definite kernels are bounded and measurable.
Under this assumption, the mean and covariance always exist with arbitrary probabilities.
Given i.i.d. sample with law , the empirical estimator of the kernel mean and covariance operator are given straightforwardly by
where is written in tensor form. It is known that these estimators are -consistent in appropriate norms, and converges to a Gaussian process on [3, Sec. 9.1]. While we may use non-i.i.d. samples for numerical examples in Section 5, in our theoretical analysis we always assume i.i.d. samples for simplicity.
Kernel expression of Bayes’ rule
Let and be measurable spaces, be a random variable on with distribution , and and be positive definite kernels on and , respectively, with respective RKHS and . Let be a probability on , which serves as a prior distribution. For each , define a probability on by , where is the index function of a measurable set . The prior and the family defines the joint distribution on by
for any and , and its marginal distribution by . Throughout this paper, it is assumed that and are well-defined under some regularity conditions. Let be a random variable on with distribution . It is also assumed that the sigma algebra generated by includes every point (). For , the posterior probability given is defined by the conditional probability
If the probability distributions have density functions with respect to measures on and on , namely, if the p.d.f. of and are given by and , respectively, Eq. (6) is reduced to the well known form Eq. (1).
The goal of this subsection is to derive an estimator of the kernel mean of posterior . The following theorem is fundamental to discuss conditional probabilities with positive definite kernels.
If holds for , then
If is injective, i.e., if the function with is unique, the above relation can be expressed as
Noting , it is easy to see that is injective, if is a topological space, is a continuous kernel, and , where is the support of .
From Theorem 3.1, we have the following result, which expresses the kernel mean of .
Let and be the kernel means of in and in , respectively. If is injective, , and for any , then
Take such that . For any , , which implies . ∎
As discussed in , the operator can be regarded as the kernel expression of the conditional probability or .
Note, however, that the assumption may not hold in general; we can easily give counterexamples in the case of Gaussian kernelsSuppose that and are given by Gaussian kernel, and that and are independent. Then, is a constant function of , which is known not to be included in a RKHS given by a Gaussian kernel [38, Corollary 4.44].. In the following, we nonetheless derive a population expression of Bayes’ rule under this strong assumption, use it as a prototype for defining an empirical estimator, and prove its consistency.
In deriving kernel realization of Bayes’ rule, we will use the following tensor representation of the joint probability , based on Theorem 3.2:
In the above equation, the covariance operator is defined by the random variable taking values on .
In many applications of Bayesian inference, the probability conditioned on a particular value should be computed. By plugging the point measure at into in Eq. (8), we have a population expression
If we replace by and by in Eq. (10), we obtain
This is exactly the kernel mean expression of the posterior, and the next step is to provide a way of deriving the covariance operators and . Recall that the kernel mean can be identified with the covariance operator , and , which is the kernel mean on the product space , with . Then from Eq. (9) and the similar expression , we are able to obtain the operators in Eq. (11), and thus the kernel mean of the posterior.
The above argument can be rigorously implemented, if empirical estimators are considered. Let be an i.i.d. sample with law . Since the kernel method needs to express the information of variables in terms of Gram matrices given by data points, we assume that the prior is also expressed in the form of an empirical estimate, and that we have a consistent estimator of in the form
where is the coefficient of the Tikhonov-type regularization for operator inversion, and is the identity operator. The empirical estimators and for and are identified with and , respectively. In the following, and denote the Gram matrices and , respectively, and is the identity matrix of size .
The Gram matrix expressions of and are given by
The proof is similar to that of Proposition 3.4 below, and is omitted. The expressions in Proposition 3.3 imply that the probabilities and are estimated by the weighted samples and , respectively, with common weights. Since the weight may be negative, in applying Eq. (11) the operator inversion in the form may be impossible or unstable. We thus use another type of Tikhonov regularization, thus obtaining the estimator
For any , the Gram matrix expression of is given by
where is a diagonal matrix with elements in Eq. (12), , and .
Let , and decompose it as , where is orthogonal to . Expansion of gives . Taking the inner product with , we have
The coefficient in is given by , and thus
We call Eqs.(13) and (14) the kernel Bayes’ rule (KBR). The required computations are summarized in Figure 1. The KBR uses a weighted sample to represent the posterior; it is similar in this respect to sampling methods such as importance sampling and sequential Monte Carlo (). The KBR method, however, does not generate samples of the posterior, but updates the weights of a sample by matrix computation. We will give some experimental comparisons between KBR and sampling methods in Section 5.1.
If our aim is to estimate the expectation of a function with respect to the posterior, the reproducing property Eq. (3) gives an estimator
2 Consistency of the KBR estimator
where is given by Eq. (15).
It is possible to extend the covariance operator to one defined on by
If we consider the convergence on average over , we have a slightly better rate on the consistency of the KBR estimator in .
Bayesian inference with Kernel Bayes’ Rule
In Bayesian inference, we are usually interested in finding a point estimate such as the MAP solution, the expectation of a function under the posterior, or other properties of the distribution. Given that KBR provides a posterior estimate in the form of a kernel mean (which uniquely determines the distribution when a characteristic kernel is used), we now describe how our kernel approach applies to problems in Bayesian inference.
First, we have already seen that a consistent estimator for the expectation of can be defined with respect to the posterior. On the other hand, unless holds, there is no theoretical guarantee that it gives a good estimate. In Section 5.1, we discuss some experimental results in such situations.
To obtain a point estimate of the posterior on , it is proposed in to use the preimage , which represents the posterior mean most effectively by one point. We use this approach in the present paper when point estimates are considered. In the case of the Gaussian kernel , the fixed point method
where , can be used to optimize sequentially . This method usually converges very fast, although no theoretical guarantee exists for the convergence to the globally optimal point, as is usual in non-convex optimization.
A notable property of KBR is that the prior and likelihood are represented in terms of samples. Thus, unlike many approaches to Bayesian inference, precise knowledge of the prior and likelihood distributions is not needed, once samples are obtained. The following are typical situations where the KBR approach is advantageous:
The probabilistic relation among variables is difficult to realize with a simple parametric model, while we can obtain samples of the variables easily. We will see such an example in Section 4.3.
The probability density function of the prior and/or likelihood is hard to obtain explicitly, but sampling is possible:
In the field of population genetics, Bayesian inference is used with a likelihood expressed by branching processes to model the split of species, for which the explicit density is hard to obtain. Approximate Bayesian Computation (ABC) is a popular method for approximately sampling from a posterior without knowing the functional form .
Another interesting application along these lines is nonparametric Bayesian inference ( and references therein), in which the prior is typically given in the form of a process without a density form. In this case, sampling methods are often applied ( among others). Alternatively, the posterior may be approximated using variational methods .
We will present an experimental comparison of KBR and ABC in Section 5.2.
Even if explicit forms for the likelihood and prior are available, and standard sampling methods such as MCMC or sequential MC are applicable, the computation of a posterior estimate given might still be computationally costly, making real-time applications unfeasible. Using KBR, however, the expectation of a function of the posterior given different is obtained simply by taking the inner product as in Eq. (15), once has been computed.
2 Discussions concerning implementation
When implementing KBR, a number of factors should be borne in mind to ensure good performance. First, in common with many nonparametric approaches, KBR requires training data in the region of the new “test” points for results to be meaningful. In other words, if the point on which we condition appears in a region far from the sample used for the estimation, the posterior estimator will be unreliable.
Second, in computing the posterior in KBR, Gram matrix inversion is necessary, which would cost for sample size if attempted directly. Substantial cost reductions can be achieved if the Gram matrices are approximated by low rank matrix approximations. A popular choice is the incomplete Cholesky decomposition , which approximates a Gram matrix in the form of with matrix () at cost . Using this and the Woodbury identity, the KBR can be approximately computed at cost .
Third, kernel choice or model selection is key to the effectiveness of any kernel method. In the case of KBR, we have three model parameters: the kernel (or its parameter, e.g. the bandwidth), the regularization parameter , and . The strategy for parameter selection depends on how the posterior is to be used in the inference problem. If it is to be applied in regression, we can use standard cross-validation. In the filtering experiments in Section 5, we use a validation method where we divide the training sample in two.
A more general model selection approach can also be formulated, by creating a new regression problem for the purpose. Suppose the prior is given by the marginal of . The posterior averaged with respect to is then equal to the marginal itself. We are thus able to compare the discrepancy of the empirical kernel mean of and the average of the estimators over . This leads to a -fold cross validation approach: for a partition of into disjoint subsets , let be the kernel mean of posterior computed using Gram matrices on data , and based on the prior mean with data . We can then cross validate by minimizing \sum_{a=1}^{K}\bigl{\|}\frac{1}{|T_{a}|}\sum_{j\in T_{a}}\widehat{m}_{Q_{\mathcal{X}|y=Y_{j}}}^{[-a]}-\widehat{m}_{X}^{[a]}\bigr{\|}^{2}_{{\mathcal{H}_{\mathcal{X}}}}, where .
3 Application to nonparametric state-space model
We next describe how KBR may be used in a particular application: namely, inference in a general time invariant state-space model,
where is an observable variable, and is a hidden state variable. We begin with a brief review of alternative strategies for inference in state-space models with complex dynamics, for which linear models are not suitable. The extended Kalman filter (EKF) and unscented Kalman filter (UKF, ) are nonlinear extensions of the standard linear Kalman filter, and are well established in this setting. Alternatively, nonparametric estimates of conditional density functions can be employed, including kernel density estimation or distribution estimates on a partitioning of the space . The latter nonparametric approaches are effective only for low-dimensional cases, however. Most relevant to this paper are and , in which the kernel means and covariance operators are used to implement the nonparametric HMM.
In this paper, we apply the KBR for inference in the nonparametric state-space model. We do not assume the conditional probabilities and to be known explicitly, nor do we estimate them with simple parametric models. Rather, we assume a sample is given for both the observable and hidden variables in the training phase. The conditional probability for observation process and the transition are represented by the empirical covariance operators as computed on the training sample,
While the sample is not i.i.d., we can use the empirical covariances, which are consistent by the mixing property of Markov models.
where the coefficients are given by
In sequential filtering, a substantial reduction in computational cost can be achieved by low rank matrix approximations, as discussed above. Given an approximation of rank for the Gram matrices and transfer matrix, and employing the Woodbury identity, the computation costs just for each time step.
4 Bayesian computation without likelihood
We next address the setting where the likelihood is not known in analytic form, but sampling is possible. In this case, Approximate Bayesian Computation (ABC) is a popular method for Bayesian inference. The simplest form of ABC, which is called the rejection method, generates a sample from as follows: (i) generate a sample from the prior , (ii) generate a sample from , (iii) if , accept ; otherwise reject, (iv) go to (i). In step (iii), is a distance measure of the space , and is tolerance to acceptance.
In the same setting as ABC, KBR gives the following sampling-based method for computing the kernel posterior mean:
Generate a sample from the prior .
Generate a sample from ().
Compute Gram matrices and with , and .
Alternatively, since is an sample from , it is possible to use Eq. (10) for the kernel mean of the conditional probability . As in , the estimator is given by
The distribution of a sample generated by ABC approaches to the true posterior if goes to zero, while empirical estimates via the kernel approaches converge to the true posterior mean in the limit of infinite sample size. The efficiency of ABC, however, can be arbitrarily poor for small , since a sample is then rarely accepted in Step (iii).
The ABC method generates a sample, hence any statistics based on the posterior can be approximated. Given a posterior mean obtained by one of the kernel methods, however, we may only obtain expectations of functions in the RKHS, meaning that certain statistics (such as confidence intervals) are not straightforward to obtain. In Section 5.2, we present an experimental evaluation of the trade-off between computation time and accuracy for ABC and KBR.
Numerical Examples
2 Bayesian computation without likelihood
We compare ABC and the kernel methods, KBR and conditional mean, in terms of estimation accuracy and computational time, since they have an obvious tradeoff. To compute the estimation accuracy rigorously, the ground truth is needed: thus we use Gaussian distributions for the true prior and likelihood, which makes the posterior easy to compute in closed form. The samples are taken from the same model used in Section 5.1, and is evaluated at 10 different points of . We performed 10 random runs with different random generation of the true distributions.
For ABC, we used only the rejection method; while there are more advanced sampling schemes , their implementation is dependent on the problem being solved. Various values for the acceptance region are used, and the accuracy and computational time are shown in Fig. 3 together with total sizes of the generated samples. For the kernel methods, the sample size is varied. The regularization parameters are given by and for KBR, and for the conditional kernel mean. The kernels in the kernel methods are Gaussian kernels for which the bandwidth parameters are chosen by the median of the pairwise distances on the data (). The incomplete Cholesky decomposition is employed for the low-rank approximation. The results indicate that kernel methods achieve more accurate results than ABC at a given computational cost, and the conditional kernel mean shows better results.
3 Filtering problems
We next compare the KBR filtering method (proposed in Section 4.3) with EKF and UKF on synthetic data.
KBR has the regularization parameters , and kernel parameters for and (e.g., the bandwidth parameter for an RBF kernel). Under the assumption that a training sample is available, cross-validation can be performed on the training sample to select the parameters. By dividing the training sample into two, one half is used to estimate the covariance operators Eq. (17) with a candidate parameter set, and the other half to evaluate the estimation errors. To reduce the search space and attendant computational cost, we used a simpler procedure, setting , and using the Gaussian kernel bandwidths and , where and are the median of pairwise distances in the training samples (). This leaves only two parameters and to be tuned.
where is an increment of the angle and is independent process noise. Note that the dynamics of are nonlinear even for . The observation follows
where is independent noise. The two dynamics are defined as follows. (a) (rotation with noisy observation) , , . (b) (oscillatory rotation with noisy observation) , , , . (See Fig.5).
We assume the correct dynamics are known to the EKF and UKF. The results are shown in Fig. 4. In all the cases, EKF and UKF show unrecognizably small difference. The dynamics in (a) are weakly nonlinear, and KBR has slightly worse MSE than EKF and UKF. For dataset (b), which has strong nonlinearity, KBR outperforms the nonlinear Kalman filter for .
In our second synthetic example, we applied the KBR filter to the camera rotation problem used in Song et al. . The angle of a camera, which is located at a fixed position, is a hidden variable, and movie frames recorded by the camera are observed. The data are generated virtually using a computer graphics environment. As in , we are given 3600 downsampled frames of RGB pixels (), where the first 1800 frames are used for training, and the second half are used to test the filter. We make the data noisy by adding Gaussian noise to .
Our experiments cover two settings. In the first, we assume we do not know that the hidden state is included in , but only that it is a general matrix. In this case, we use the Kalman filter by estimating the relations under a linear assumption, and the KBR filter with Gaussian kernels for and as Euclidean vectors. In the second setting, we exploit the fact that : for the Kalman Filter, is represented by a quanternion, which is a standard vector representation of rotations; for the KBR filter the kernel is used for , and is estimated within . Table 1 shows the Frobenius norms between the estimated matrix and the true one. The KBR filter significantly outperforms the EKF, since KBR has the advantage in extracting the complex nonlinear dependence between the observation and the hidden state.
Proofs
The proof idea for the consistency rates of the KBR estimators is similar to , in which the basic techniques are taken from the general theory of regularization .
The first preliminary result is a rate of convergence for the mean transition in Theorem 3.2. In the following means .
Assume that for some , where and are the p.d.f. of and , respectively. Let be an estimator of such that as for some . Then, with , we have
Take such that . Then, we have
First we show the rate of the estimation error:
as . By using for any invertible operators and , the left hand side of Eq. (21) is upper bounded by
By the decomposition with , we have \|\widehat{C}^{(n)}_{YX}\bigl{(}\widehat{C}^{(n)}_{XX}+\varepsilon_{n}I\bigr{)}^{-1}\|=O_{p}(\varepsilon_{n}^{-1/2}), which implies the first term is of . From the consistency of the covariance operators and , a similar argument to the first term proves that the second and third terms are of the order and , respectively, which means Eq. (21).
Next, we show the rate for the approximation error
Let be the decomposition with . It follows from Eq. (20) and the relation
that the left hand side of Eq. (22) is upper bounded by
By the eigendecomposition , where are the positive eigenvalues and are the corresponding unit eigenvectors, the expansion
holds. If , we have . If , then . The dominated convergence theorem shows that the the above sum converges to zero of the order as .
From Eqs. (21) and (22), the optimal order of and the optimal rate of consistency are given as claimed. ∎
The following theorem shows the consistency rate of the estimator used in the conditioning step Eq. (11).
Let be a function in , and be a random variable taking values in . Assume that for some , and and be compact operators, which may not be positive definite, such that and for some . Then, for a positive sequence , we have as
Let such that . First we show
The left hand side of Eq. (23) is upper bounded by
Let be the eigendecomposition, where is the unit eigenvectors and is the corresponding eigenvalues. From \bigl{|}\lambda_{i}/(\lambda_{i}^{2}+\delta_{n})\bigr{|}=1/|\lambda_{i}+\delta_{n}/\lambda_{i}|\leq 1/(2\sqrt{|\lambda_{i}|}\sqrt{\delta_{n}/|\lambda_{i}|})=1/(2\sqrt{\delta_{n}}), we have \|\widehat{C}^{(n)}_{WW}\bigl{(}(\widehat{C}^{(n)}_{WW})^{2}+\delta_{n}I\bigr{)}^{-1}\|\leq 1/(2\sqrt{\delta_{n}}), and thus the first term of the above bound is of . A similar argument by the eigendecomposition of combined with the decomposition with shows that the second term is of . From the fact , the third term is of . This implies Eq. (23).
From and , the convergence rate
can be proved by the same way as Eq. (22).
Combination of Eqs.(23) and (24) proves the assertion. ∎
Note that for we have . It follows that the left hand side of the assertion is equal to
First, by the similar argument to the proof of Eq. (23), it is easy to show that the rate of the estimation error is given by
The consistency of KBR follows by combining the above theorems.
Let be a function in , be a random variable that has the distribution with p.d.f. , and be an estimator of such that () for some . Assume that with , and for some . For the regularization constants and , where , we have for any
where is given by Eq. (14).
By applying Theorem 6.1 to and , we see that both of and are of . Since
combination of Theorems 6.1 and 6.2 proves the theorem. ∎
The next theorem shows the rate on average w.r.t. . The proof is similar to the above theorem, and omitted.
We also have consistency of the estimator for the kernel mean of posterior , if we make stronger assumptions. First, we formulate the expectation with the posterior in terms of operators. Let be a random variable with distribution . Assume that for any the conditional expectation is included in . We then have a linear operator defined by
If we further assume that is bounded, the adjoint operator satisfies
for any , and thus is equal to the kernel mean of the conditional probability of given .
We make the following further assumptions: Assumption (S)
The covariance operator is injective.
There exists such that for any there is with , and the linear map
Let be a random variable that has the distribution with p.d.f. , and be an estimator of such that () for some . Assume (S) above, and with some . For the regularization constants and , where , we have for any
as , where is the kernel mean of the posterior given .
First, in a similar manner to the proof of Eq. (23), we have
is proved. The left hand side of Eq. (25) is upper-bounded by
It follows from Theorem 3.1 that , and thus . The eigendecomposition of together with the inequality () completes the proof. ∎
We thank Arnaud Doucet, Lorenzo Rosasco, Yee Whye Teh and Shuhei Mano for their helpful comments.