diff --git a/R/abclass.R b/R/abclass.R index d39dbf0..47333ce 100644 --- a/R/abclass.R +++ b/R/abclass.R @@ -75,7 +75,7 @@ ##' @param max_iter A positive integer specifying the maximum number of ##' iteration. The default value is \code{10^5}. ##' @param epsilon A positive number specifying the relative tolerance that -##' determines convergence. The default value is \code{1e-5}. +##' determines convergence. The default value is \code{1e-3}. ##' @param standardize A logical value indicating if each column of the design ##' matrix should be standardized internally to have mean zero and standard ##' deviation equal to the sample size. The default value is \code{TRUE}. @@ -120,7 +120,7 @@ abclass <- function(x, y, lum_c = 1.0, boost_umin = -5.0, max_iter = 1e5, - epsilon = 1e-4, + epsilon = 1e-3, standardize = TRUE, varying_active_set = TRUE, verbose = 0, diff --git a/inst/examples/ex-abclass.R b/inst/examples/ex-abclass.R index db24a30..e666e83 100644 --- a/inst/examples/ex-abclass.R +++ b/inst/examples/ex-abclass.R @@ -4,9 +4,9 @@ set.seed(123) ## toy examples for demonstration purpose ## reference: example 1 in Zhang and Liu (2014) ntrain <- 100 # size of training set -ntest <- 1000 # size of testing set -p0 <- 10 # number of actual predictors -p1 <- 100 # number of random predictors +ntest <- 100 # size of testing set +p0 <- 5 # number of actual predictors +p1 <- 5 # number of random predictors k <- 5 # number of categories n <- ntrain + ntest; p <- p0 + p1 @@ -24,60 +24,16 @@ y <- factor(paste0("label_", y)) train_y <- y[train_idx] test_y <- y[- train_idx] -### Regularization through elastic-net penalty -## logistic deviance loss -model1 <- abclass(train_x, train_y, nlambda = 10, nfolds = 3, - loss = "logistic", lambda_min_ratio = 1e-4) +## Regularization through ridge penalty +model1 <- abclass(train_x, train_y, nlambda = 5, nfolds = 3, + loss = "logistic", alpha = 0, lambda_min_ratio = 1e-2) pred1 <- predict(model1, test_x) table(test_y, pred1) mean(test_y == pred1) # accuracy -## exponential loss approximating AdaBoost -model2 <- abclass(train_x, train_y, nlambda = 10, nfolds = 3, - loss = "boost", rel_tol = 1e-3) +## groupwise regularization via group lasso +model2 <- abclass(train_x, train_y, nlambda = 5, nfolds = 3, + grouped = TRUE, loss = "boost") pred2 <- predict(model2, test_x) table(test_y, pred2) mean(test_y == pred2) # accuracy - -## hybrid hinge-boost loss -model3 <- abclass(train_x, train_y, nlambda = 10, nfolds = 3, - loss = "hinge-boost", rel_tol = 1e-3) -pred3 <- predict(model3, test_x) -table(test_y, pred3) -mean(test_y == pred3) # accuracy - -## large-margin unified loss -model4 <- abclass(train_x, train_y, nlambda = 10, nfolds = 3, - loss = "lum", rel_tol = 1e-3) -pred4 <- predict(model4, test_x) -table(test_y, pred4) -mean(test_y == pred4) # accuracy - -### groupwise regularization via group lasso -## logistic deviance loss -model1 <- abclass(train_x, train_y, nlambda = 10, nfolds = 3, - grouped = TRUE, loss = "logistic", rel_tol = 1e-3) -pred1 <- predict(model1, test_x) -table(test_y, pred1) -mean(test_y == pred1) # accuracy - -## exponential loss approximating AdaBoost -model2 <- abclass(train_x, train_y, nlambda = 10, nfolds = 3, - grouped = TRUE, loss = "boost", rel_tol = 1e-3) -pred2 <- predict(model2, test_x) -table(test_y, pred2) -mean(test_y == pred2) # accuracy - -## hybrid hinge-boost loss -model3 <- abclass(train_x, train_y, nlambda = 10, nfolds = 3, - grouped = TRUE, loss = "hinge-boost", rel_tol = 1e-3) -pred3 <- predict(model3, test_x) -table(test_y, pred3) -mean(test_y == pred3) # accuracy - -## large-margin unified loss -model4 <- abclass(train_x, train_y, nlambda = 10, nfolds = 3, - grouped = TRUE, loss = "lum", rel_tol = 1e-3) -pred4 <- predict(model4, test_x) -table(test_y, pred4) -mean(test_y == pred4) # accuracy diff --git a/man/abclass.Rd b/man/abclass.Rd index f81b22e..211e403 100644 --- a/man/abclass.Rd +++ b/man/abclass.Rd @@ -22,7 +22,7 @@ abclass( lum_c = 1, boost_umin = -5, max_iter = 1e+05, - epsilon = 1e-04, + epsilon = 0.001, standardize = TRUE, varying_active_set = TRUE, verbose = 0, @@ -100,7 +100,7 @@ internal majorization procedure.} iteration. The default value is \code{10^5}.} \item{epsilon}{A positive number specifying the relative tolerance that -determines convergence. The default value is \code{1e-5}.} +determines convergence. The default value is \code{1e-3}.} \item{standardize}{A logical value indicating if each column of the design matrix should be standardized internally to have mean zero and standard @@ -133,9 +133,9 @@ set.seed(123) ## toy examples for demonstration purpose ## reference: example 1 in Zhang and Liu (2014) ntrain <- 100 # size of training set -ntest <- 1000 # size of testing set -p0 <- 10 # number of actual predictors -p1 <- 100 # number of random predictors +ntest <- 100 # size of testing set +p0 <- 5 # number of actual predictors +p1 <- 5 # number of random predictors k <- 5 # number of categories n <- ntrain + ntest; p <- p0 + p1 @@ -153,63 +153,19 @@ y <- factor(paste0("label_", y)) train_y <- y[train_idx] test_y <- y[- train_idx] -### Regularization through elastic-net penalty -## logistic deviance loss -model1 <- abclass(train_x, train_y, nlambda = 10, nfolds = 3, - loss = "logistic", lambda_min_ratio = 1e-4) +## Regularization through ridge penalty +model1 <- abclass(train_x, train_y, nlambda = 5, nfolds = 3, + loss = "logistic", alpha = 0, lambda_min_ratio = 1e-2) pred1 <- predict(model1, test_x) table(test_y, pred1) mean(test_y == pred1) # accuracy -## exponential loss approximating AdaBoost -model2 <- abclass(train_x, train_y, nlambda = 10, nfolds = 3, - loss = "boost", rel_tol = 1e-3) +## groupwise regularization via group lasso +model2 <- abclass(train_x, train_y, nlambda = 5, nfolds = 3, + grouped = TRUE, loss = "boost") pred2 <- predict(model2, test_x) table(test_y, pred2) mean(test_y == pred2) # accuracy - -## hybrid hinge-boost loss -model3 <- abclass(train_x, train_y, nlambda = 10, nfolds = 3, - loss = "hinge-boost", rel_tol = 1e-3) -pred3 <- predict(model3, test_x) -table(test_y, pred3) -mean(test_y == pred3) # accuracy - -## large-margin unified loss -model4 <- abclass(train_x, train_y, nlambda = 10, nfolds = 3, - loss = "lum", rel_tol = 1e-3) -pred4 <- predict(model4, test_x) -table(test_y, pred4) -mean(test_y == pred4) # accuracy - -### groupwise regularization via group lasso -## logistic deviance loss -model1 <- abclass(train_x, train_y, nlambda = 10, nfolds = 3, - grouped = TRUE, loss = "logistic", rel_tol = 1e-3) -pred1 <- predict(model1, test_x) -table(test_y, pred1) -mean(test_y == pred1) # accuracy - -## exponential loss approximating AdaBoost -model2 <- abclass(train_x, train_y, nlambda = 10, nfolds = 3, - grouped = TRUE, loss = "boost", rel_tol = 1e-3) -pred2 <- predict(model2, test_x) -table(test_y, pred2) -mean(test_y == pred2) # accuracy - -## hybrid hinge-boost loss -model3 <- abclass(train_x, train_y, nlambda = 10, nfolds = 3, - grouped = TRUE, loss = "hinge-boost", rel_tol = 1e-3) -pred3 <- predict(model3, test_x) -table(test_y, pred3) -mean(test_y == pred3) # accuracy - -## large-margin unified loss -model4 <- abclass(train_x, train_y, nlambda = 10, nfolds = 3, - grouped = TRUE, loss = "lum", rel_tol = 1e-3) -pred4 <- predict(model4, test_x) -table(test_y, pred4) -mean(test_y == pred4) # accuracy } \references{ Zhang, C., & Liu, Y. (2014). Multicategory Angle-Based Large-Margin