|
1 | 1 | # ------------------------------------------------
|
2 | 2 | # Cross-validation, preliminary
|
3 | 3 |
|
4 |
| -cvMakeFolds <- function(x, nfolds = 10) { |
5 |
| - #inds <- sample(1:nrow(x), replace=FALSE) |
6 |
| - inds <- 1:nrow(x) |
| 4 | +cvMakeFolds <- function(x, nfolds = 5) { |
| 5 | + inds <- sample(1:nrow(x), replace=FALSE) |
| 6 | + #inds <- 1:nrow(x) |
7 | 7 | foldsize <- floor(nrow(x)/nfolds)
|
8 |
| - lapply(1:nfolds, function(f) return(inds[1:foldsize+(f-1)*foldsize])) |
| 8 | + folds <- lapply(1:nfolds, function(f) return(inds[1:foldsize+(f-1)*foldsize])) |
| 9 | + if (nfolds*foldsize < nrow(x)) { |
| 10 | + # remainder observations added to first several folds |
| 11 | + for (i in 1:(nrow(x) - nfolds*foldsize)) { |
| 12 | + folds[[i]] <- c(folds[[i]], inds[nfolds*foldsize + i]) |
| 13 | + } |
| 14 | + } |
| 15 | + return(folds) |
9 | 16 | }
|
10 | 17 |
|
11 | 18 | ############################################
|
@@ -87,6 +94,7 @@ cvfs <- function(x, y, index = 1:ncol(x), maxsteps, sigma = NULL, intercept = TR
|
87 | 94 | fold <- folds[[f]]
|
88 | 95 | fit <- groupfs(X[-fold,], Y[-fold], index=index, maxsteps=maxsteps, sigma=sigma, intercept=FALSE, center=FALSE, normalize=FALSE)
|
89 | 96 | fit$fold <- fold
|
| 97 | + # Why is this commented out? |
90 | 98 | ## projections[[f]] <- lapply(fit$projections, function(step.projs) {
|
91 | 99 | ## lapply(step.projs, function(proj) {
|
92 | 100 | ## # Reduce from n by n matrix to svdu_thresh
|
|
0 commit comments