SZVD_kFold_cv {accSDA} | R Documentation |
Cross-validation of sparse zero variance discriminant analysis
Description
Applies alternating direction methods of multipliers to solve sparse zero variance discriminant analysis.
Usage
SZVD_kFold_cv(X, ...)
## Default S3 method:
SZVD_kFold_cv(
X,
Y,
folds,
gams,
beta,
D,
q,
maxits,
tol,
ztol,
feat,
penalty,
quiet,
...
)
Arguments
X |
n by p data matrix, variables should be scaled to by sd |
... |
Parameters passed to SZVD.default. |
Y |
n by K indicator matrix. |
folds |
number of folds to use in K-fold cross-validation. |
gams |
Number of regularly spaced regularization parameters to try in [0,1]*max_gamma. See details for how max_gamma is computed in the function. |
beta |
Augmented Lagrangian parameter. Must be greater than zero. |
D |
Penalty dictionary basis matrix. |
q |
Desired number of discriminant vectors. |
maxits |
Number of iterations to run ADMM algorithm. |
tol |
Stopping tolerances for ADMM, must have tol$rel and tol$abs. |
ztol |
Rounding tolerance for truncating entries to 0. |
feat |
Maximum fraction of nonzero features desired in validation scheme. |
penalty |
Controls whether to apply reweighting of l1-penalty (using sigma = within-class std devs) |
quiet |
toggles between displaying intermediate statistics. |
Details
Add how max_gamma is calculated from the ZVD solution. This function might require a wrapper similar to ASDA.
Value
SZVDcv
returns an object of class
"SZVDcv
"
including a list with the named components DVs
and gambest
.
Where DVs
are the discriminant vectors for the best l1 regularization
parameter and gambest
is the best regularization parameter found
in the cross-validation.
NULL
See Also
Used by: SZVDcv
.
Examples
P <- 150 # Number of variables
N <- 20 # Number of samples per class
# Mean for classes, they are zero everywhere except the first 3 coordinates
m1 <- rep(0,P)
m1[1] <- 3
m2 <- rep(0,P)
m2[2] <- 3
m3 <- rep(0,P)
m3[3] <- 3
# Sample dummy data
Xtrain <- rbind(MASS::mvrnorm(n=N,mu = m1, Sigma = diag(P)),
MASS::mvrnorm(n=N,mu = m2, Sigma = diag(P)),
MASS::mvrnorm(n=N,mu = m3, Sigma = diag(P)))
# Generate the labels
Ytrain <- cbind(c(rep(1,N),rep(0,2*N)),
c(rep(0,N),rep(1,N),rep(0,N)),
c(rep(0,2*N),rep(1,N)))
# Normalize the data
Xt <- accSDA::normalize(Xtrain)
Xtrain <- Xt$Xc
# Train the classifier and increase the sparsity parameter from the default
# so we penalize more for non-sparse solutions.
res <- accSDA::SZVD_kFold_cv(Xtrain,Ytrain,folds=2,gams=2,beta=2.5,q=1, D=diag(P),
maxits=50,tol=list(abs=1e-2,rel=1e-2),
ztol=1e-3,feat=0.3,quiet=FALSE,penalty=TRUE)