renate.shift.mmd_helpers module#
- renate.shift.mmd_helpers.mmd_gram(K, z, num_permutations=0)[source]#
Maximum mean discrepancy based on a precomputed kernel-Gram matrix.
This computes the test statistic and (optionally) p-value to conduct an MMD two-sample test to decide whether two sets are generated by the same distribution. The inputs are passed implicitly in the form of a kernel Gram matrix, evaluated across the union of both sets, and a binary vector indicating the assignments of data points to the two sets. I.e., a value of
z[i] = 0
indicates that thei
-th data point belongs to set zero. Optionally, a permutation test is carried out and a p-value is returned alongside the raw test statistic.MMD tests have been proposed by
[1] Gretton, A., et al. A kernel two-sample test. JMLR (2012).
- Parameters:
- Return type:
Tuple
[Tensor
,Optional
[Tensor
]]- Returns:
A tuple
(t, p)
of two scalar floats, wheret
is the value of the MMD test statistic andp
is the p-value (orNone
ifnum_permutations=0
).
- renate.shift.mmd_helpers.mmd(X0, X1, kernel, num_permutations=0)[source]#
Compute MMD between two samples.
Optionally, return an estimated p-value based on a permutation test.
- Parameters:
- Return type:
Tuple
[Tensor
,Optional
[Tensor
]]- Returns:
A tuple
(t, p)
wheret
is the value of the MMD test statistic andp
is the p-value (orNone
ifnum_permutations=0
).