# kernelMatrix

0th

Percentile

##### Kernel Matrix functions

kernelMatrix calculates the kernel matrix $K_{ij} = k(x_i,x_j)$ or $K_{ij} = k(x_i,y_j)$. kernelPol computes the quadratic kernel expression $H = z_i z_j k(x_i,x_j)$, $H = z_i k_j k(x_i,y_j)$. kernelMult calculates the kernel expansion $f(x_i) = \sum_{i=1}^m z_i k(x_i,x_j)$ kernelFast computes the kernel matrix, identical to kernelMatrix, except that it also requires the squared norm of the first argument as additional input, useful in iterative kernel matrix calculations.

Keywords
algebra, array
##### Usage
# S4 method for kernel
kernelMatrix(kernel, x, y = NULL)# S4 method for kernel
kernelPol(kernel, x, y = NULL, z, k = NULL)# S4 method for kernel
kernelMult(kernel, x, y = NULL, z, blocksize = 256)# S4 method for kernel
kernelFast(kernel, x, y, a)
##### Arguments
kernel

the kernel function to be used to calculate the kernel matrix. This has to be a function of class kernel, i.e. which can be generated either one of the build in kernel generating functions (e.g., rbfdot etc.) or a user defined function of class kernel taking two vector arguments and returning a scalar.

x

a data matrix to be used to calculate the kernel matrix, or a list of vector when a stringkernel is used

y

second data matrix to calculate the kernel matrix, or a list of vector when a stringkernel is used

z

a suitable vector or matrix

k

a suitable vector or matrix

a

the squared norm of x, e.g., rowSums(x^2)

blocksize

the kernel expansion computations are done block wise to avoid storing the kernel matrix into memory. blocksize defines the size of the computational blocks.

##### Details

Common functions used during kernel based computations. The kernel parameter can be set to any function, of class kernel, which computes the inner product in feature space between two vector arguments. kernlab provides the most popular kernel functions which can be initialized by using the following functions:

• rbfdot Radial Basis kernel function

• 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 the Spline kernel

(see example.)

kernelFast is mainly used in situations where columns of the kernel matrix are computed per invocation. In these cases, evaluating the norm of each row-entry over and over again would cause significant computational overhead.

##### Value

kernelMatrix returns a symmetric diagonal semi-definite matrix. kernelPol returns a matrix. kernelMult usually returns a one-column matrix.

rbfdot, polydot, tanhdot, vanilladot

##### Aliases
• kernelMatrix
• kernelMult
• kernelPol
• kernelFast
• kernelPol,kernel-method
• kernelMatrix,kernel-method
• kernelMult,kernel-method
• kernelFast,kernel-method
• kernelMatrix,rbfkernel-method
• kernelMatrix,polykernel-method
• kernelMatrix,vanillakernel-method
• kernelMatrix,tanhkernel-method
• kernelMatrix,laplacekernel-method
• kernelMatrix,anovakernel-method
• kernelMatrix,splinekernel-method
• kernelMatrix,besselkernel-method
• kernelMatrix,stringkernel-method
• kernelMult,rbfkernel,ANY-method
• kernelMult,splinekernel,ANY-method
• kernelMult,polykernel,ANY-method
• kernelMult,tanhkernel,ANY-method
• kernelMult,laplacekernel,ANY-method
• kernelMult,besselkernel,ANY-method
• kernelMult,anovakernel,ANY-method
• kernelMult,vanillakernel,ANY-method
• kernelMult,character,kernelMatrix-method
• kernelMult,stringkernel,ANY-method
• kernelPol,rbfkernel-method
• kernelPol,splinekernel-method
• kernelPol,polykernel-method
• kernelPol,tanhkernel-method
• kernelPol,vanillakernel-method
• kernelPol,anovakernel-method
• kernelPol,besselkernel-method
• kernelPol,laplacekernel-method
• kernelPol,stringkernel-method
• kernelFast,rbfkernel-method
• kernelFast,splinekernel-method
• kernelFast,polykernel-method
• kernelFast,tanhkernel-method
• kernelFast,vanillakernel-method
• kernelFast,anovakernel-method
• kernelFast,besselkernel-method
• kernelFast,laplacekernel-method
• kernelFast,stringkernel-method
• kernelFast,splinekernel-method
##### Examples
# NOT RUN {
## use the spam data
data(spam)
dt <- as.matrix(spam[c(10:20,3000:3010),-58])

## initialize kernel function
rbf <- rbfdot(sigma = 0.05)
rbf

## calculate kernel matrix
kernelMatrix(rbf, dt)

yt <- as.matrix(as.integer(spam[c(10:20,3000:3010),58]))
yt[yt==2] <- -1

## calculate the quadratic kernel expression
kernelPol(rbf, dt, ,yt)

## calculate the kernel expansion
kernelMult(rbf, dt, ,yt)
# }

Documentation reproduced from package kernlab, version 0.9-27, License:

### Community examples

Looks like there are no examples yet.