construct_D: Constructor for penalty matrix

View source: R/extra_functions.R

construct_DR Documentation

Constructor for penalty matrix

Description

This function constructs an auxiliary matrix to compute the node penalty in the regularized classifier, which is internally used by the optimization algorithm. This matrix can be passed to the function graphclass in order to avoid creating it every time this function is called. Use it for efficiency when running the classifier multiple times (for example, in a cross-validation routine).

Usage

construct_D(nodes = 264)

Arguments

nodes

Number of nodes in the network, by default is 264 (Power parcellation).

Value

A sparse matrix

Examples

D263 = construct_D(263)

# Load COBRE data
data(COBRE.data)
X <- COBRE.data$X.cobre
Y <- COBRE.data$Y.cobre

# 5-fold cross validation of the subgraph selection penalty
fold_index <- (1:length(Y) %% 5) + 1

gclist <- list()
for(fold in 1:5) {
    foldout <- which(fold_index == fold) 
    gclist[[fold]] <- graphclass(X = X[-foldout,], Y = factor(Y[-foldout]),
                     Xtest = X[foldout,], Ytest = factor(Y[foldout]),
                     type = "intersection",
                     lambda = 1e-4, rho = 1, gamma = 1e-5,
                     D = D263)
}
# test error on each fold
lapply(gclist, function(gc) gc$test_error)


jesusdaniel/graphclass documentation built on Aug. 10, 2022, 3:10 p.m.