kgram: Kernel Gram matrices

View source: R/kgram.R

kgramR Documentation

Kernel Gram matrices

Description

Function kgram builds kernel Gram matrices for reference (= training) observations and, eventually, new (= test) observations to predict.

The generated Gram matrices can then be used as input of usual regression functions (e.g. plsr or plsda) for implementing "direct" kernel regressions or discriminations. For instance, the direct kernel PLSR (DKPLSR) is discussed in Bennet & Embrechts (2003). See the examples below.

Usage


kgram(Xr, Xu = NULL, kern = kpol, ...)

Arguments

Xr

A n x p matrix or data frame of reference (= training) observations.

Xu

A m x p matrix or data frame of new (= test) observations to predict.

kern

A function defining the considered kernel (Default to kpol). See kpol for syntax, and other available kernel functions. The user can build any other ad'hoc kernel function.

...

Optionnal arguments to pass in the kernel function defined in kern.

Value

Kr

The n x n training Gram matrix.

Ku

The m x n test Gram matrix.

References

Bennett, K.P., Embrechts, M.J., 2003. An optimization perspective on kernel partial least squares regression, in: Advances in Learning Theory: Methods, Models and Applications, NATO Science Series III: Computer & Systems Sciences. IOS Press Amsterdam, pp. 227-250.

Rosipal, R., Trejo, L.J., 2001. Kernel Partial Least Squares Regression in Reproducing Kernel Hilbert Space. Journal of Machine Learning Research 2, 97-123.

Examples


####### Example of fitting the function sinc(x) (Rosipal & Trejo 2001 p. 105-106) 

x <- seq(-10, 10, by = .2)
x[x == 0] <- 1e-5
n <- length(x)
zy <- sin(abs(x)) / abs(x)
y <- zy + rnorm(n, 0, .2)
plot(x, y, type = "p")
lines(x, zy, lty = 2)
Xu <- Xr <- matrix(x, ncol = 1)

## DKPLSR

res <- kgram(Xr, Xu, kern = krbf, sigma = 1)
ncomp <- 3
fm <- plsr(res$Kr, y, res$Ku, ncomp = ncomp)
fit <- fm$fit$y1[fm$fit$ncomp == ncomp]
plot(Xr, y, type = "p")
lines(Xr, zy, lty = 2)
lines(Xu, fit, col = "red")

## DK Ridge regression

res <- kgram(Xr, Xu, kern = krbf, sigma = 1)
fm <- rr(res$Kr, y, res$Ku, lambda = .1)
fit <- fm$fit$y1
plot(Xr, y, type = "p")
lines(Xr, zy, lty = 2)
lines(Xu, fit, col = "red")


mlesnoff/rnirs documentation built on April 24, 2023, 4:17 a.m.