`RBF()` computes the RBF kernel between all possible pairs of rows of a matrix or data.frame with dimension NxD.
Details
Let \(x_i,x_j\) be two real vectors. Then, the RBF kernel is defined as: $$K_{RBF}(x_i,x_j)=\exp(-\gamma \|x_i - x_j \|^2)$$
Sometimes the RBF kernel is given a hyperparameter called sigma. In that case: \(\gamma = 1/\sigma^2\).
Examples
dat <- matrix(rnorm(250),ncol=50,nrow=5)
RBF(dat,g=0.1)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1.0000000000 3.117137e-04 1.355691e-03 0.0014509756 0.0001324322
#> [2,] 0.0003117137 1.000000e+00 7.520068e-05 0.0001258129 0.0001864737
#> [3,] 0.0013556906 7.520068e-05 1.000000e+00 0.0006218804 0.0004282548
#> [4,] 0.0014509756 1.258129e-04 6.218804e-04 1.0000000000 0.0003363011
#> [5,] 0.0001324322 1.864737e-04 4.282548e-04 0.0003363011 1.0000000000