# kernels and similarity (in R)

I am trying fit different kernels to calculate similarity matrix in R. Here is example data - X matrix :

X <- matrix(rep(0,200*1000),200,1000)
set.seed(123)
for (i in 1:200) {
X[i,] <- ifelse(runif(1000)<0.5,-1,1)
}


What kernels can be used to generate a similarity matrix and how can I do this in R ?

Background:

"kernel methods are a class of algorithms for pattern analysis (see wikipedia).The general task of pattern analysis is to find and study general types of relations (for example clusters, rankings, principal components, correlations, classifications) in datasets. For many of these tasks, data have to be represented as feature vectors, but kernel methods replace this representation by similarities to other data points."

" Kernel methods owe their name to the use of kernel functions.which enable them to operate in a high-dimensional, implicit feature space without ever computing the coordinates of the data in that space, but rather by simply computing the inner products between the images of all pairs of data in the feature space. This operation is often computationally cheaper than the explicit computation of the coordinates. This approach is called the kernel trick. Kernel functions have been introduced for sequence data, graphs, text, images, as well as vectors".

Gaussian Kernel

Given two D dimensional vectors xi and xj . The Gaussian kernel is defined as:

where

is is the Euclidean distance and and $\sigma$$^2$ is the bandwidth of the kernel. The the Gaussian kernel is a measure of similarity between xi and xj . It evalues to 1 if the xi and xj are identical, and approaches 0 as xi and xj move further apart. The function gausskernel from package KRLS calculate such similarity matrix.

 require(KRLS)
gausskernel(X=X,sigma=1)


The package kernellab has many kernels and discussions. The function kcca in this package can perform Kernel Canonical Correlation Analysis which include different Kernels -

rbfdot Radial Basis kernel function "Gaussian"

polydot Polynomial kernel function

vanilladot Linear kernel function

tanhdot Hyperbolic tangent kernel function

laplacedot Laplacian kernel function

besseldot Bessel kernel function

anovadot ANOVA RBF kernel function

splinedot Spline kernel

Example:

## initialize kernel function
rbf <- rbfdot(sigma = 0.05)
rbf
## calculate kernel matrix
kernelMatrix(rbf, X)


I am not sure how many of these kernel measures can be used as similarity measure. The package also perform Kernel Principal Components Analysis (function - kha).