Class of nonparametric methods
In machine learning, the kernel embedding of distributions (also called the kernel mean or mean map) comprises a class of nonparametric methods in which a probability distribution is represented as an element of a reproducing kernel Hilbert space (RKHS).[1] A generalization of the individual data-point feature mapping done in classical kernel methods, the embedding of distributions into infinite-dimensional feature spaces can preserve all of the statistical features of arbitrary distributions, while allowing one to compare and manipulate distributions using Hilbert space operations such as inner products, distances, projections, linear transformations, and spectral analysis.[2] This learning framework is very general and can be applied to distributions over any space
on which a sensible kernel function (measuring similarity between elements of
) may be defined. For example, various kernels have been proposed for learning from data which are: vectors in
, discrete classes/categories, strings, graphs/networks, images, time series, manifolds, dynamical systems, and other structured objects.[3][4] The theory behind kernel embeddings of distributions has been primarily developed by Alex Smola, Le Song Archived 2021-04-12 at the Wayback Machine, Arthur Gretton, and Bernhard Schölkopf. A review of recent works on kernel embedding of distributions can be found in.[5]
The analysis of distributions is fundamental in machine learning and statistics, and many algorithms in these fields rely on information theoretic approaches such as entropy, mutual information, or Kullback–Leibler divergence. However, to estimate these quantities, one must first either perform density estimation, or employ sophisticated space-partitioning/bias-correction strategies which are typically infeasible for high-dimensional data.[6] Commonly, methods for modeling complex distributions rely on parametric assumptions that may be unfounded or computationally challenging (e.g. Gaussian mixture models), while nonparametric methods like kernel density estimation (Note: the smoothing kernels in this context have a different interpretation than the kernels discussed here) or characteristic function representation (via the Fourier transform of the distribution) break down in high-dimensional settings.[2]
Methods based on the kernel embedding of distributions sidestep these problems and also possess the following advantages:[6]
- Data may be modeled without restrictive assumptions about the form of the distributions and relationships between variables
- Intermediate density estimation is not needed
- Practitioners may specify the properties of a distribution most relevant for their problem (incorporating prior knowledge via choice of the kernel)
- If a characteristic kernel is used, then the embedding can uniquely preserve all information about a distribution, while thanks to the kernel trick, computations on the potentially infinite-dimensional RKHS can be implemented in practice as simple Gram matrix operations
- Dimensionality-independent rates of convergence for the empirical kernel mean (estimated using samples from the distribution) to the kernel embedding of the true underlying distribution can be proven.
- Learning algorithms based on this framework exhibit good generalization ability and finite sample convergence, while often being simpler and more effective than information theoretic methods
Thus, learning via the kernel embedding of distributions offers a principled drop-in replacement for information theoretic approaches and is a framework which not only subsumes many popular methods in machine learning and statistics as special cases, but also can lead to entirely new learning algorithms.
Definitions
Let
denote a random variable with domain
and distribution
. Given a symmetric, positive-definite kernel
the Moore–Aronszajn theorem asserts the existence of a unique RKHS
on
(a Hilbert space of functions
equipped with an inner product
and a norm
) for which
is a reproducing kernel, i.e., in which the element
satisfies the reproducing property

One may alternatively consider
as an implicit feature mapping
(which is therefore also called the feature space), so that
can be viewed as a measure of similarity between points
While the similarity measure is linear in the feature space, it may be highly nonlinear in the original space depending on the choice of kernel.
Kernel embedding
The kernel embedding of the distribution
in
(also called the kernel mean or mean map) is given by:[1]
![{\displaystyle \mu _{X}:=\mathbb {E} [k(X,\cdot )]=\mathbb {E} [\varphi (X)]=\int _{\Omega }\varphi (x)\ \mathrm {d} P(x)}](https://wikimedia.org/api/rest_v1/media/math/render/svg/f862d6986fd2f8fcea5ddb48489ef835a972f817)
If
allows a square integrable density
, then
, where
is the Hilbert–Schmidt integral operator. A kernel is characteristic if the mean embedding
is injective.[7] Each distribution can thus be uniquely represented in the RKHS and all statistical features of distributions are preserved by the kernel embedding if a characteristic kernel is used.
Empirical kernel embedding
Given
training examples
drawn independently and identically distributed (i.i.d.) from
the kernel embedding of
can be empirically estimated as

Joint distribution embedding
If
denotes another random variable (for simplicity, assume the co-domain of
is also
with the same kernel
which satisfies
), then the joint distribution
can be mapped into a tensor product feature space
via [2]
![{\displaystyle {\mathcal {C}}_{XY}=\mathbb {E} [\varphi (X)\otimes \varphi (Y)]=\int _{\Omega \times \Omega }\varphi (x)\otimes \varphi (y)\ \mathrm {d} P(x,y)}](https://wikimedia.org/api/rest_v1/media/math/render/svg/6fe80c305396f4fbd17eb41b43d9d504af250211)
By the equivalence between a tensor and a linear map, this joint embedding may be interpreted as an uncentered cross-covariance operator
from which the cross-covariance of functions
can be computed as [8]
![{\displaystyle \operatorname {Cov} (f(X),g(Y)):=\mathbb {E} [f(X)g(Y)]-\mathbb {E} [f(X)]\mathbb {E} [g(Y)]=\langle f,{\mathcal {C}}_{XY}g\rangle _{\mathcal {H}}=\langle f\otimes g,{\mathcal {C}}_{XY}\rangle _{{\mathcal {H}}\otimes {\mathcal {H}}}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/3d05786215aaf75e79826544e049058ebdb27728)
Given
pairs of training examples
drawn i.i.d. from
, we can also empirically estimate the joint distribution kernel embedding via

Conditional distribution embedding
Given a conditional distribution
one can define the corresponding RKHS embedding as [2]
![{\displaystyle \mu _{Y\mid x}=\mathbb {E} [\varphi (Y)\mid X]=\int _{\Omega }\varphi (y)\ \mathrm {d} P(y\mid x)}](https://wikimedia.org/api/rest_v1/media/math/render/svg/74368d151ac85df1f1195e129893309282add667)
Note that the embedding of
thus defines a family of points in the RKHS indexed by the values
taken by conditioning variable
. By fixing
to a particular value, we obtain a single element in
, and thus it is natural to define the operator

which given the feature mapping of
outputs the conditional embedding of
given
Assuming that for all
it can be shown that [8]

This assumption is always true for finite domains with characteristic kernels, but may not necessarily hold for continuous domains.[2] Nevertheless, even in cases where the assumption fails,
may still be used to approximate the conditional kernel embedding
and in practice, the inversion operator is replaced with a regularized version of itself
(where
denotes the identity matrix).
Given training examples
the empirical kernel conditional embedding operator may be estimated as [2]

where
are implicitly formed feature matrices,
is the Gram matrix for samples of
, and
is a regularization parameter needed to avoid overfitting.
Thus, the empirical estimate of the kernel conditional embedding is given by a weighted sum of samples of
in the feature space:

where
and
Properties
- The expectation of any function
in the RKHS can be computed as an inner product with the kernel embedding:
![{\displaystyle \mathbb {E} [f(X)]=\langle f,\mu _{X}\rangle _{\mathcal {H}}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/308b871f33b57cbb59b80f7a754ecfacec6aaafa)
- In the presence of large sample sizes, manipulations of the
Gram matrix may be computationally demanding. Through use of a low-rank approximation of the Gram matrix (such as the incomplete Cholesky factorization), running time and memory requirements of kernel-embedding-based learning algorithms can be drastically reduced without suffering much loss in approximation accuracy.[2]
Convergence of empirical kernel mean to the true distribution embedding
- If
is defined such that
takes values in
for all
with
(as is the case for the widely used radial basis function kernels), then with probability at least
:[6]
![{\displaystyle \|\mu _{X}-{\widehat {\mu }}_{X}\|_{\mathcal {H}}=\sup _{f\in {\mathcal {B}}(0,1)}\left|\mathbb {E} [f(X)]-{\frac {1}{n}}\sum _{i=1}^{n}f(x_{i})\right|\leq {\frac {2}{n}}\mathbb {E} \left[{\sqrt {\operatorname {tr} K}}\right]+{\sqrt {\frac {\log(2/\delta )}{2n}}}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/1345c55427797498d758c5bdef2bcb0b542cde3b)
- where
denotes the unit ball in
and
is the Gram matrix with 
- The rate of convergence (in RKHS norm) of the empirical kernel embedding to its distribution counterpart is
and does not depend on the dimension of
.
- Statistics based on kernel embeddings thus avoid the curse of dimensionality, and though the true underlying distribution is unknown in practice, one can (with high probability) obtain an approximation within
of the true kernel embedding based on a finite sample of size
.
- For the embedding of conditional distributions, the empirical estimate can be seen as a weighted average of feature mappings (where the weights
depend on the value of the conditioning variable and capture the effect of the conditioning on the kernel embedding). In this case, the empirical estimate converges to the conditional distribution RKHS embedding with rate
if the regularization parameter
is decreased as
though faster rates of convergence may be achieved by placing additional assumptions on the joint distribution.[2]
Universal kernels
- Let
be a compact metric space and
the set of continuous functions. The reproducing kernel
is called universal if and only if the RKHS
of
is dense in
, i.e., for any
and all
there exists an
such that
.[9] All universal kernels defined on a compact space are characteristic kernels but the converse is not always true.[10]
- Let
be a continuous translation invariant kernel
with
. Then Bochner's theorem guarantees the existence of a unique finite Borel measure
(called the spectral measure) on
such that

- For
to be universal it suffices that the continuous part of
in its unique Lebesgue decomposition
is non-zero. Furthermore, if

- then
is the spectral density of frequencies
in
and
is the Fourier transform of
. If the support of
is all of
, then
is a characteristic kernel as well.[11][12][13]
- If
induces a strictly positive definite kernel matrix for any set of distinct points, then it is a universal kernel.[6] For example, the widely used Gaussian RBF kernel

- on compact subsets of
is universal.
Parameter selection for conditional distribution kernel embeddings
- The empirical kernel conditional distribution embedding operator
can alternatively be viewed as the solution of the following regularized least squares (function-valued) regression problem [14]

- where
is the Hilbert–Schmidt norm.
- One can thus select the regularization parameter
by performing cross-validation based on the squared loss function of the regression problem.
Rules of probability as operations in the RKHS
This section illustrates how basic probabilistic rules may be reformulated as (multi)linear algebraic operations in the kernel embedding framework and is primarily based on the work of Song et al.[2][8] The following notation is adopted:
joint distribution over random variables 
marginal distribution of
;
marginal distribution of 
conditional distribution of
given
with corresponding conditional embedding operator 
prior distribution over 
is used to distinguish distributions which incorporate the prior from distributions
which do not rely on the prior
In practice, all embeddings are empirically estimated from data
and it assumed that a set of samples
may be used to estimate the kernel embedding of the prior distribution
.
Kernel sum rule
In probability theory, the marginal distribution of
can be computed by integrating out
from the joint density (including the prior distribution on
)

The analog of this rule in the kernel embedding framework states that
the RKHS embedding of
, can be computed via
![{\displaystyle \mu _{X}^{\pi }=\mathbb {E} [{\mathcal {C}}_{X\mid Y}\varphi (Y)]={\mathcal {C}}_{X\mid Y}\mathbb {E} [\varphi (Y)]={\mathcal {C}}_{X\mid Y}\mu _{Y}^{\pi }}](https://wikimedia.org/api/rest_v1/media/math/render/svg/304ebef9f47f404410529a1d570478374138626b)
where
is the kernel embedding of
In practical implementations, the kernel sum rule takes the following form

where

is the empirical kernel embedding of the prior distribution,
, and
are Gram matrices with entries
respectively.
Kernel chain rule
In probability theory, a joint distribution can be factorized into a product between conditional and marginal distributions

The analog of this rule in the kernel embedding framework states that
the joint embedding of
can be factorized as a composition of conditional embedding operator with the auto-covariance operator associated with

where
![{\displaystyle {\mathcal {C}}_{XY}^{\pi }=\mathbb {E} [\varphi (X)\otimes \varphi (Y)],}](https://wikimedia.org/api/rest_v1/media/math/render/svg/973ab0f3a4484e4049c355822145adb5b8222735)
![{\displaystyle {\mathcal {C}}_{YY}^{\pi }=\mathbb {E} [\varphi (Y)\otimes \varphi (Y)].}](https://wikimedia.org/api/rest_v1/media/math/render/svg/322ce140000f7582b47a3a3679f24bffc9d42c97)
In practical implementations, the kernel chain rule takes the following form

Kernel Bayes' rule
In probability theory, a posterior distribution can be expressed in terms of a prior distribution and a likelihood function as
where 
The analog of this rule in the kernel embedding framework expresses the kernel embedding of the conditional distribution in terms of conditional embedding operators which are modified by the prior distribution

where from the chain rule:

In practical implementations, the kernel Bayes' rule takes the following form

where

Two regularization parameters are used in this framework:
for the estimation of
and
for the estimation of the final conditional embedding operator

The latter regularization is done on square of
because
may not be positive definite.
Applications
Measuring distance between distributions
The maximum mean discrepancy (MMD) is a distance-measure between distributions
and
which is defined as the distance between their embeddings in the RKHS [6]

While most distance-measures between distributions such as the widely used Kullback–Leibler divergence either require density estimation (either parametrically or nonparametrically) or space partitioning/bias correction strategies,[6] the MMD is easily estimated as an empirical mean which is concentrated around the true value of the MMD. The characterization of this distance as the maximum mean discrepancy refers to the fact that computing the MMD is equivalent to finding the RKHS function that maximizes the difference in expectations between the two probability distributions
![{\displaystyle {\text{MMD}}(P,Q)=\sup _{\|f\|_{\mathcal {H}}\leq 1}\left(\mathbb {E} [f(X)]-\mathbb {E} [f(Y)]\right),}](https://wikimedia.org/api/rest_v1/media/math/render/svg/4cfb3272a3525278930c0e0a0a9c9666e06dcee0)
a form of integral probability metric.
Kernel two-sample test
Given n training examples from
and m samples from
, one can formulate a test statistic based on the empirical estimate of the MMD
![{\displaystyle {\begin{aligned}{\widehat {\text{MMD}}}(P,Q)&=\left\|{\frac {1}{n}}\sum _{i=1}^{n}\varphi (x_{i})-{\frac {1}{m}}\sum _{i=1}^{m}\varphi (y_{i})\right\|_{\mathcal {H}}^{2}\\[5pt]&={\frac {1}{n^{2}}}\sum _{i=1}^{n}\sum _{j=1}^{n}k(x_{i},x_{j})+{\frac {1}{m^{2}}}\sum _{i=1}^{m}\sum _{j=1}^{m}k(y_{i},y_{j})-{\frac {2}{nm}}\sum _{i=1}^{n}\sum _{j=1}^{m}k(x_{i},y_{j})\end{aligned}}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/3ea882089dd8c094015f533408f7b4bac1105e6f)
to obtain a two-sample test [15] of the null hypothesis that both samples stem from the same distribution (i.e.
) against the broad alternative
.
Density estimation via kernel embeddings
Although learning algorithms in the kernel embedding framework circumvent the need for intermediate density estimation, one may nonetheless use the empirical embedding to perform density estimation based on n samples drawn from an underlying distribution
. This can be done by solving the following optimization problem [6][16]
subject to ![{\displaystyle \|{\widehat {\mu }}_{X}-\mu _{X}[P_{X}]\|_{\mathcal {H}}\leq \varepsilon }](https://wikimedia.org/api/rest_v1/media/math/render/svg/e43ddd88bd1c059293a828452ce9ed6a0eeb14e3)
where the maximization is done over the entire space of distributions on
Here,
is the kernel embedding of the proposed density
and
is an entropy-like quantity (e.g. Entropy, KL divergence, Bregman divergence). The distribution which solves this optimization may be interpreted as a compromise between fitting the empirical kernel means of the samples well, while still allocating a substantial portion of the probability mass to all regions of the probability space (much of which may not be represented in the training examples). In practice, a good approximate solution of the difficult optimization may be found by restricting the space of candidate densities to a mixture of M candidate distributions with regularized mixing proportions. Connections between the ideas underlying Gaussian processes and conditional random fields may be drawn with the estimation of conditional probability distributions in this fashion, if one views the feature mappings associated with the kernel as sufficient statistics in generalized (possibly infinite-dimensional) exponential families.[6]
Measuring dependence of random variables
A measure of the statistical dependence between random variables
and
(from any domains on which sensible kernels can be defined) can be formulated based on the Hilbert–Schmidt Independence Criterion [17]

and can be used as a principled replacement for mutual information, Pearson correlation or any other dependence measure used in learning algorithms. Most notably, HSIC can detect arbitrary dependencies (when a characteristic kernel is used in the embeddings, HSIC is zero if and only if the variables are independent), and can be used to measure dependence between different types of data (e.g. images and text captions). Given n i.i.d. samples of each random variable, a simple parameter-free unbiased estimator of HSIC which exhibits concentration about the true value can be computed in
time,[6] where the Gram matrices of the two datasets are approximated using
with
. The desirable properties of HSIC have led to the formulation of numerous algorithms which utilize this dependence measure for a variety of common machine learning tasks such as: feature selection (BAHSIC [18]), clustering (CLUHSIC [19]), and dimensionality reduction (MUHSIC [20]).
HSIC can be extended to measure the dependence of multiple random variables. The question of when HSIC captures independence in this case has recently been studied:[21] for
more than two variables
- on
: the characteristic property of the individual kernels remains an equivalent condition.
- on general domains: the characteristic property of the kernel components is necessary but not sufficient.
Kernel belief propagation
Belief propagation is a fundamental algorithm for inference in graphical models in which nodes repeatedly pass and receive messages corresponding to the evaluation of conditional expectations. In the kernel embedding framework, the messages may be represented as RKHS functions and the conditional distribution embeddings can be applied to efficiently compute message updates. Given n samples of random variables represented by nodes in a Markov random field, the incoming message to node t from node u can be expressed as

if it assumed to lie in the RKHS. The kernel belief propagation update message from t to node s is then given by [2]

where
denotes the element-wise vector product,
is the set of nodes connected to t excluding node s,
,
are the Gram matrices of the samples from variables
, respectively, and
is the feature matrix for the samples from
.
Thus, if the incoming messages to node t are linear combinations of feature mapped samples from
, then the outgoing message from this node is also a linear combination of feature mapped samples from
. This RKHS function representation of message-passing updates therefore produces an efficient belief propagation algorithm in which the potentials are nonparametric functions inferred from the data so that arbitrary statistical relationships may be modeled.[2]
Nonparametric filtering in hidden Markov models
In the hidden Markov model (HMM), two key quantities of interest are the transition probabilities between hidden states
and the emission probabilities
for observations. Using the kernel conditional distribution embedding framework, these quantities may be expressed in terms of samples from the HMM. A serious limitation of the embedding methods in this domain is the need for training samples containing hidden states, as otherwise inference with arbitrary distributions in the HMM is not possible.
One common use of HMMs is filtering in which the goal is to estimate posterior distribution over the hidden state
at time step t given a history of previous observations
from the system. In filtering, a belief state
is recursively maintained via a prediction step (where updates
are computed by marginalizing out the previous hidden state) followed by a conditioning step (where updates
are computed by applying Bayes' rule to condition on a new observation).[2] The RKHS embedding of the belief state at time t+1 can be recursively expressed as

by computing the embeddings of the prediction step via the kernel sum rule and the embedding of the conditioning step via kernel Bayes' rule. Assuming a training sample
is given, one can in practice estimate

and filtering with kernel embeddings is thus implemented recursively using the following updates for the weights
[2]


where
denote the Gram matrices of
and
respectively,
is a transfer Gram matrix defined as
and
Support measure machines
The support measure machine (SMM) is a generalization of the support vector machine (SVM) in which the training examples are probability distributions paired with labels
.[22] SMMs solve the standard SVM dual optimization problem using the following expected kernel
![{\displaystyle K\left(P(X),Q(Z)\right)=\langle \mu _{X},\mu _{Z}\rangle _{\mathcal {H}}=\mathbb {E} [k(x,z)]}](https://wikimedia.org/api/rest_v1/media/math/render/svg/1a6a129234a929a502edbd41889f7d78f12a2197)
which is computable in closed form for many common specific distributions
(such as the Gaussian distribution) combined with popular embedding kernels
(e.g. the Gaussian kernel or polynomial kernel), or can be accurately empirically estimated from i.i.d. samples
via

Under certain choices of the embedding kernel
, the SMM applied to training examples
is equivalent to a SVM trained on samples
, and thus the SMM can be viewed as a flexible SVM in which a different data-dependent kernel (specified by the assumed form of the distribution
) may be placed on each training point.[22]
Domain adaptation under covariate, target, and conditional shift
The goal of domain adaptation is the formulation of learning algorithms which generalize well when the training and test data have different distributions. Given training examples
and a test set
where the
are unknown, three types of differences are commonly assumed between the distribution of the training examples
and the test distribution
:[23][24]
- Covariate shift in which the marginal distribution of the covariates changes across domains:

- Target shift in which the marginal distribution of the outputs changes across domains:

- Conditional shift in which
remains the same across domains, but the conditional distributions differ:
. In general, the presence of conditional shift leads to an ill-posed problem, and the additional assumption that
changes only under location-scale (LS) transformations on
is commonly imposed to make the problem tractable.
By utilizing the kernel embedding of marginal and conditional distributions, practical approaches to deal with the presence of these types of differences between training and test domains can be formulated. Covariate shift may be accounted for by reweighting examples via estimates of the ratio
obtained directly from the kernel embeddings of the marginal distributions of
in each domain without any need for explicit estimation of the distributions.[24] Target shift, which cannot be similarly dealt with since no samples from
are available in the test domain, is accounted for by weighting training examples using the vector
which solves the following optimization problem (where in practice, empirical approximations must be used) [23]
subject to