View source: R/kernel_fusion.R
MKC | R Documentation |
Combination of kernel matrices coming from different datasets / feature types into a single kernel matrix.
MKC(K, coeff = NULL)
K |
A three-dimensional NxDxM array containing M kernel matrices. |
coeff |
A vector of length M with the weight of each kernel matrix. If NULL, all kernel matrices have the same weight. (Defaults: NULL) |
A kernel matrix.
# For illustrating a possible use of this function, we work with a dataset
# that contains numeric and categorical features.
summary(mtcars)
cat_feat_idx <- which(colnames(mtcars) %in% c("vs", "am"))
# vs and am are categorical variables. We make a list, with the numeric features
# in the first element and the categorical features in the second:
DATA <- list(num=mtcars[,-cat_feat_idx], cat=mtcars[,cat_feat_idx])
# Our N, D and M dimensions are:
N <- nrow(mtcars); D <- ncol(mtcars); M <- length(DATA)
# Now we prepare a kernel matrix:
K <- array(dim=c(N,N,M))
K[,,1] <- Linear(DATA[[1]],cos.norm = TRUE) ## Kernel for numeric data
K[,,2] <- Dirac(DATA[[2]]) ## Kernel for categorical data
# Here, K1 has the same weight than K2 when computing the final kernel, although
# K1 has 9 variables and K2 has only 2.
Kconsensus <- MKC(K)
Kconsensus[1:5,1:5]
# If we want to weight equally each one of the 11 variables in the final
# kernel, K1 will weight 9/11 and K2 2/11.
coeff <- sapply(DATA,ncol)
coeff
Kweighted <- MKC(K,coeff=coeff)
Kweighted[1:5,1:5]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.