Learn R Programming

KRLS (version 0.3-1)

gausskernel: Gaussian Kernel Distance Computation

Description

This function computes and returns a distance matrix computed by using a Gaussian Kernel distance measure to compute the distances between the rows of a data matrix.

Usage

gausskernel(X = NULL, sigma = NULL)

Arguments

X
an n by k numeric matrix.
sigma
a scalar value that specifies the width of the Gaussian kernel sigma^2 (see details).

Value

  • An n by n numeric distance matrix that contains the pairwise distances between teh rows of X.

Details

Given two k dimensional vectors x_i and x_j. The Gaussian kernel is defined as: k(x_i,x_j)= exp(-|| x_i - x_j ||^2/sigma^2). Where ||x_i - x_j|| is the Euclidean distance between x_i and x_j ||x_i - x_j||=((x_i1-x_j1)^2 + (x_i2-x_j2)^2 + ... + (x_ik-x_jk)^2)^.5. Note that the Gaussian kernel is a measure of similarity between the two input vectors (it evalues to 1 if the two input arguments are identical, and approaches 0 as the two vectors get very far apart.). The function relies on the dist function in the stats package for an initial estimate of the euclidean distance.

See Also

dist function in the stats package.

Examples

Run this code
X <- matrix(rnorm(6),ncol=2)
gausskernel(X=X,sigma=1)

Run the code above in your browser using DataLab