MMD | R Documentation |
This function returns the estimator for the two-sample MMD.
MMD( y, x, y_kmmd = NULL, var = 1, bias = FALSE, threshold = Inf, approx_exp = 0, sigma = NULL, w_y = NULL, w_x = NULL )
y |
either a numeric vector or matrix with number of rows equal to number of observations and number of columns equal to dimension of observations. |
x |
either a numeric vector or matrix with number of rows equal to number of observations and number of columns equal to dimension of observations. |
y_kmmd |
precomputed first term in MMD calculation. |
var |
matrix kernel variance covariance matrix. |
bias |
logical; if |
threshold |
numeric filter out values for exponentiation. |
approx_exp |
integer; if 0 the usual function for the exponential distribution is used; if 1 a much faster but less accurate version of the exponential distribution is used. |
sigma |
numeric DEPRECATED square root of variance. |
w_y |
numeric weights for y |
w_x |
numeric weights for x |
Gretton, Arthur, et al. "A kernel method for the two-sample-problem." Advances in neural information processing systems. 2007.
set.seed(1) y <- rnorm(2000) x <- rnorm(2000, 5) MMD_1 <- MMD(y, x) MMD_1 # Precompute y_kmmd for faster speed y_kmmd <- kmmd(y) MMD_2 <- MMD(y, x, y_kmmd) MMD_2 system.time(MMD_1 <- MMD(y, x)) system.time(MMD_2 <- MMD(y, x, y_kmmd)) # Different var MMD_4 <- MMD(y, x, var = 0.25) # Matrix version library(mvtnorm) x <- rmvnorm(100, c(0,0), diag(c(2,2))) sigma <- matrix(c(2,1.5,1.5,2), ncol=2) y <- rmvnorm(100, c(0,0), sigma = sigma) MMD(y, x, var = diag(c(0.5, 0.5)), bias = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.