View source: R/extra_functions.R
construct_D | R Documentation |
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).
construct_D(nodes = 264)
nodes |
Number of nodes in the network, by default is 264 (Power parcellation). |
A sparse matrix
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.