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 ?
 A: 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 $x_i$ and $x_j$, the Gaussian kernel is defined as:
$K(x_i,x_j) = \exp\{\frac{-||x_i - x_j||^2}{\sigma^2}\}$
where
$ ||x_i - x_j||^2 = \sum_{k=0}^D (x_{ik} - x_{jk})^2$
is the Euclidean distance and $\sigma^2$ is the bandwidth of the kernel. The Gaussian kernel is a measure of similarity between $x_i$ and $x_j$ . It evaluates to 1 if the $x_i$
and $x_j$ are identical, and approaches 0 as $x_i$
and $x_j$ 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).
Also see:
How Good is a Kernel When Used as a Similarity Measure?
