as.kernelMatrix in package KERE can be used
to coerce the kernelMatrix class to matrix objects representing a
kernel matrix. These matrices can then be used with the kernelMatrix
interfaces which most of the functions in KERE support.
Usage
## S4 method for signature 'matrix'
as.kernelMatrix(x, center = FALSE)
Arguments
x
matrix to be assigned the kernelMatrix class
center
center the kernel matrix in feature space (default: FALSE)
## Create toy data
x <- rbind(matrix(rnorm(10),,2),matrix(rnorm(10,mean=3),,2))
y <- matrix(c(rep(1,5),rep(-1,5)))
### Use as.kernelMatrix to label the cov. matrix as a kernel matrix
### which is eq. to using a linear kernel
K <- as.kernelMatrix(crossprod(t(x)))
K
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(KERE)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/KERE/as.kernelMatrix.Rd_%03d_medium.png", width=480, height=480)
> ### Name: as.kernelMatrix
> ### Title: Assing kernelMatrix class to matrix objects
> ### Aliases: kernelMatrix-class as.kernelMatrix as.kernelMatrix-methods
> ### as.kernelMatrix,matrix-method
> ### Keywords: methods
>
> ### ** Examples
>
> ## Create toy data
> x <- rbind(matrix(rnorm(10),,2),matrix(rnorm(10,mean=3),,2))
> y <- matrix(c(rep(1,5),rep(-1,5)))
>
> ### Use as.kernelMatrix to label the cov. matrix as a kernel matrix
> ### which is eq. to using a linear kernel
>
> K <- as.kernelMatrix(crossprod(t(x)))
>
> K
An object of class "kernelMatrix"
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.01878918 -0.1372150 0.1086256 0.2304520 0.1228437 0.03100398
[2,] -0.13721503 1.0051019 -0.8339293 -1.7090449 -0.8201466 -0.37297448
[3,] 0.10862561 -0.8339293 1.1719576 1.6813430 -0.3197225 2.14039067
[4,] 0.23045195 -1.7090449 1.6813430 3.0504845 0.8458464 1.63864392
[5,] 0.12284371 -0.8201466 -0.3197225 0.8458464 2.7531576 -3.51045812
[6,] 0.03100398 -0.3729745 2.1403907 1.6386439 -3.5104581 7.12169126
[7,] 0.10091773 -0.9678954 3.6733079 3.2203959 -5.1904482 11.30645429
[8,] -0.02716205 -0.1569397 4.5974352 2.7175701 -9.1795106 17.09647179
[9,] 0.02210567 -0.3700723 2.9196864 2.0625511 -5.1415254 10.10207518
[10,] 0.15635857 -1.4735959 5.3429944 4.7660824 -7.3824375 16.26209353
[,7] [,8] [,9] [,10]
[1,] 0.1009177 -0.02716205 0.02210567 0.1563586
[2,] -0.9678954 -0.15693972 -0.37007232 -1.4735959
[3,] 3.6733079 4.59743523 2.91968642 5.3429944
[4,] 3.2203959 2.71757006 2.06255109 4.7660824
[5,] -5.1904482 -9.17951062 -5.14152542 -7.3824375
[6,] 11.3064543 17.09647179 10.10207518 16.2620935
[7,] 18.0934793 26.86096201 15.97751933 26.0549452
[8,] 26.8609620 41.59538913 24.37036181 38.5731289
[9,] 15.9775193 24.37036181 14.35537929 22.9673522
[10,] 26.0549452 38.57312893 22.96735217 37.5262848
>
>
>
>
>
>
> dev.off()
null device
1
>