optora.divergences.mmd¶
Kernel maximum mean discrepancy between distributions on a finite support.
MMDDivergence
¶
Bases: Divergence
Maximum mean discrepancy of a candidate distribution from a reference.
For distributions p and q on a shared finite support
\(\{x_1, \dots, x_n\}\) and a positive semidefinite kernel \(k\) with Gram
matrix \(K_{ij} = k(x_i, x_j)\), the maximum mean discrepancy is the
distance between their kernel mean embeddings in the reproducing kernel
Hilbert space \(\mathcal{H}\) of \(k\) (Gretton et al. 2012),
It is symmetric and satisfies the triangle inequality, and it is a
metric on distributions over the support whenever \(K\) is positive
definite, as it is for a characteristic kernel such as the Laplacian
\(e^{-\lVert x - y \rVert}\) on distinct points. Unlike a
\(\varphi\)-divergence it stays finite between distributions with
different supports. optora.dro.MMDAmbiguitySet bounds it by its
radius.
Attributes:
| Name | Type | Description |
|---|---|---|
gram |
Tensor
|
Symmetric positive semidefinite Gram matrix of shape |
__init__(gram, validate=False)
¶
Initialize the maximum mean discrepancy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gram
|
Tensor
|
Symmetric positive semidefinite Gram matrix of shape
|
required |
validate
|
bool
|
Whether to check that |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
forward(p, q)
¶
Compute the maximum mean discrepancy between p and q.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
Tensor
|
Candidate distribution of shape |
required |
q
|
Tensor
|
Reference distribution of shape |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
\(\mathrm{MMD}_k(p, q)\) over the broadcast batch, computed in |
Tensor
|
|
Tensor
|
promoted dtype of |
Tensor
|
zero before the square root, so rounding near |
Tensor
|
produces |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the last dimension of |