Bayesian Learning of Kernel Embeddings

Seth Flaxman, Dino Sejdinović, John P. Cunningham, Sarah Filippi · DOI

Abstract

Kernel methods are one of the mainstays of machine learning, but the problem of kernel learning remains challenging, with only a few heuristics and very little theory. This is of particular importance in methods based on estimation of kernel mean embeddings of probability measures. For characteristic kernels, which include most commonly used ones, the kernel mean embedding uniquely determines its probability measure, so it can be used to design a powerful statistical testing framework, which includes nonparametric two-sample and independence tests. In practice, however, the performance of these tests can be very sensitive to the choice of kernel and its lengthscale parameters. To address this central issue, we propose a new probabilistic model for kernel mean embeddings, the Bayesian Kernel Embedding (BKE) model, combining a Gaussian process prior over the Reproducing Kernel Hilbert Space (RKHS) containing the mean embedding with a conjugate likelihood function, thus yielding a closed form posterior over the mean embedding. The posterior mean of our model is closely related to recently proposed shrinkage estimators for kernel mean embeddings, while the posterior uncertainty is a new, interesting feature with various possible applications. Critically for the purposes of kernel learning, our model gives a simple, closed form marginal pseudolikelihood of the observed data given the kernel hyperparameters. This marginal pseudolikelihood can either be optimized to inform the hyperparameter choice or fully Bayesian inference can be used.

Introduction: The Challenge of Kernel Selection

Kernel mean embeddings map probability distributions into a Reproducing Kernel Hilbert Space (RKHS). They serve as the mathematical engine behind powerful non-parametric statistical tools, such as the Maximum Mean Discrepancy (MMD) for two-sample testing and the Hilbert Schmidt Independence Criterion (HSIC) for independence testing. These tools allow researchers to ask fundamental questions: Are these two datasets from the same distribution? Are these two variables independent?

However, the statistical power of these tests is notoriously sensitive to the choice of kernel and its hyperparameters, such as the lengthscale of a Radial Basis Function (RBF) kernel. In supervised learning, practitioners typically use cross-validation to select hyperparameters. In unsupervised settings or hypothesis testing, however, cross-validation is not straightforward. Consequently, many researchers fall back on the "median heuristic"—setting the lengthscale to the median distance between data points. This heuristic is often a blunt instrument that fails to capture the nuances of the data, leading to tests that cannot detect significant differences between distributions. This paper introduces a principled, unsupervised framework for learning these critical hyperparameters.

The Bayesian Kernel Embedding (BKE) Model

The authors propose the Bayesian Kernel Embedding (BKE) model, which treats the estimation of the kernel mean embedding as a Bayesian inference problem. The model consists of three primary components:

  1. The Prior: A Gaussian Process (GP) prior is placed over the RKHS. To ensure that the GP sample paths reside within the RKHS, the authors construct a specific covariance function by convolving the chosen kernel with itself.
  2. The Likelihood: The model uses the standard empirical mean embedding as the "observations." These are linked to the true embedding using a Gaussian likelihood, a choice theoretically motivated by the Central Limit Theorem.
  3. The Posterior: Because the model pairs a GP prior with a Gaussian likelihood, the posterior distribution over the mean embedding is available in closed form.
Visualizing the BKE framework: (A) Prior draws, (B) Empirical mean, and (C) The resulting posterior with uncertainty bands.

As shown in the figure above, the BKE framework allows for a transition from prior assumptions (A) and empirical observations (B) to a refined posterior estimate (C) that includes explicit uncertainty quantification.

Bayesian Kernel Learning (BKL)

By integrating out the mean embedding, the authors derive a tractable marginal pseudolikelihood of the observations given the hyperparameters. This objective function allows for Bayesian Kernel Learning (BKL). Practitioners can optimize this objective to find the best lengthscale (Empirical Bayes) or use Markov Chain Monte Carlo (MCMC) methods for fully Bayesian inference over the hyperparameters. This provides a statistically grounded alternative to the fragile median heuristic.

Experimental Evaluation and Key Results

The BKE model and BKL approach were tested across several synthetic and real-world scenarios:

  • Rescuing the Two-Sample Test: In a challenging "grid of Gaussians" dataset, the standard MMD using the median heuristic completely failed to reject the null hypothesis (Type II error near 1.0) because the heuristic-selected lengthscale was too large. BKL optimized the lengthscale to a more appropriate value, achieving near 0.0 Type II error.
  • Meaningful Uncertainty: In a Normal vs. Laplace distribution test, the fully Bayesian approach successfully generated uncertainty intervals for the "witness function" (the function showing where two distributions differ). With smaller sample sizes, the uncertainty bands correctly overlapped zero, reflecting model uncertainty. With larger samples, the bands tightened, confidently identifying the distributional differences.
  • Causal Discovery: On the real-world Ozone dataset, BKL was used to set HSIC hyperparameters within a causal discovery algorithm. BKL successfully identified a scientifically backed causal edge (Temperature → Ozone) that was missed by researchers relying on the median heuristic.

Conclusion

The Bayesian Kernel Embedding model provides a principled framework for unsupervised kernel learning and uncertainty quantification. By moving beyond heuristics, BKL enables more robust non-parametric testing and discovery. Future work may involve extending the model to handle heteroscedastic variance and developing scalable versions, such as those using random Fourier features, to accommodate massive datasets.

Summary updated

BibTeX
@inproceedings{flaxman2016bayesian,
  author = {Seth Flaxman and Dino Sejdinović and John P. Cunningham and Sarah Filippi},
  title = {{Bayesian Learning of Kernel Embeddings}},
  booktitle = {Conference on Uncertainty in Artificial Intelligence},
  year = {2016},
  url = {https://openreview.net/forum?id=o3Nvlhg410},
}
Figure