emeryyi / gglasso
Showing 2 of 15 files from the diff.

@@ -1,108 +1,111 @@
Loading
1 1
#' Fits the regularization paths for group-lasso penalized learning problems
2 -
#' 
2 +
#'
3 3
#' Fits regularization paths for group-lasso penalized learning problems at a
4 4
#' sequence of regularization parameters lambda.
5 -
#' 
5 +
#'
6 6
#' Note that the objective function for \code{"ls"} least squares is
7 7
#' \deqn{RSS/(2*n) + lambda * penalty;} for \code{"hsvm"} Huberized squared
8 8
#' hinge loss, \code{"sqsvm"} Squared hinge loss and \code{"logit"} logistic
9 9
#' regression, the objective function is \deqn{-loglik/n + lambda * penalty.}
10 10
#' Users can also tweak the penalty by choosing different penalty factor.
11 -
#' 
11 +
#'
12 12
#' For computing speed reason, if models are not converging or running slow,
13 13
#' consider increasing \code{eps}, decreasing \code{nlambda}, or increasing
14 14
#' \code{lambda.factor} before increasing \code{maxit}.
15 -
#' 
15 +
#'
16 16
#' @param x matrix of predictors, of dimension \eqn{n \times p}{n*p}; each row
17 -
#' is an observation vector.
17 +
#'   is an observation vector.
18 18
#' @param y response variable. This argument should be quantitative for
19 -
#' regression (least squares), and a two-level factor for classification
20 -
#' (logistic model, huberized SVM, squared SVM).
19 +
#'   regression (least squares), and a two-level factor for classification
20 +
#'   (logistic model, huberized SVM, squared SVM).
21 21
#' @param group a vector of consecutive integers describing the grouping of the
22 -
#' coefficients (see example below).
22 +
#'   coefficients (see example below).
23 23
#' @param loss a character string specifying the loss function to use, valid
24 -
#' options are: \itemize{ \item \code{"ls"} least squares loss (regression),
25 -
#' \item \code{"logit"} logistic loss (classification).  \item \code{"hsvm"}
26 -
#' Huberized squared hinge loss (classification), \item \code{"sqsvm"} Squared
27 -
#' hinge loss (classification), }Default is \code{"ls"}.
24 +
#'   options are: \itemize{ \item \code{"ls"} least squares loss (regression),
25 +
#'   \item \code{"logit"} logistic loss (classification).  \item \code{"hsvm"}
26 +
#'   Huberized squared hinge loss (classification), \item \code{"sqsvm"} Squared
27 +
#'   hinge loss (classification), }Default is \code{"ls"}.
28 28
#' @param nlambda the number of \code{lambda} values - default is 100.
29 29
#' @param lambda.factor the factor for getting the minimal lambda in
30 -
#' \code{lambda} sequence, where \code{min(lambda)} = \code{lambda.factor} *
31 -
#' \code{max(lambda)}.  \code{max(lambda)} is the smallest value of
32 -
#' \code{lambda} for which all coefficients are zero. The default depends on
33 -
#' the relationship between \eqn{n} (the number of rows in the matrix of
34 -
#' predictors) and \eqn{p} (the number of predictors). If \eqn{n >= p}, the
35 -
#' default is \code{0.001}, close to zero.  If \eqn{n<p}, the default is
36 -
#' \code{0.05}.  A very small value of \code{lambda.factor} will lead to a
37 -
#' saturated fit. It takes no effect if there is user-defined \code{lambda}
38 -
#' sequence.
30 +
#'   \code{lambda} sequence, where \code{min(lambda)} = \code{lambda.factor} *
31 +
#'   \code{max(lambda)}.  \code{max(lambda)} is the smallest value of
32 +
#'   \code{lambda} for which all coefficients are zero. The default depends on
33 +
#'   the relationship between \eqn{n} (the number of rows in the matrix of
34 +
#'   predictors) and \eqn{p} (the number of predictors). If \eqn{n >= p}, the
35 +
#'   default is \code{0.001}, close to zero.  If \eqn{n<p}, the default is
36 +
#'   \code{0.05}.  A very small value of \code{lambda.factor} will lead to a
37 +
#'   saturated fit. It takes no effect if there is user-defined \code{lambda}
38 +
#'   sequence.
39 39
#' @param lambda a user supplied \code{lambda} sequence. Typically, by leaving
40 -
#' this option unspecified users can have the program compute its own
41 -
#' \code{lambda} sequence based on \code{nlambda} and \code{lambda.factor}.
42 -
#' Supplying a value of \code{lambda} overrides this. It is better to supply a
43 -
#' decreasing sequence of \code{lambda} values than a single (small) value, if
44 -
#' not, the program will sort user-defined \code{lambda} sequence in decreasing
45 -
#' order automatically.
46 -
#' @param pf penalty factor, a vector in length of bn (bn is the total number
47 -
#' of groups). Separate penalty weights can be applied to each group of
48 -
#' \eqn{\beta}{beta's}s to allow differential shrinkage. Can be 0 for some
49 -
#' groups, which implies no shrinkage, and results in that group always being
50 -
#' included in the model. Default value for each entry is the square-root of
51 -
#' the corresponding size of each group.
52 -
#' @param dfmax limit the maximum number of groups in the model. Useful for
53 -
#' very large \code{bs} (group size), if a partial path is desired. Default is
54 -
#' \code{bs+1}.
40 +
#'   this option unspecified users can have the program compute its own
41 +
#'   \code{lambda} sequence based on \code{nlambda} and \code{lambda.factor}.
42 +
#'   Supplying a value of \code{lambda} overrides this. It is better to supply a
43 +
#'   decreasing sequence of \code{lambda} values than a single (small) value, if
44 +
#'   not, the program will sort user-defined \code{lambda} sequence in
45 +
#'   decreasing order automatically.
46 +
#' @param pf penalty factor, a vector in length of bn (bn is the total number of
47 +
#'   groups). Separate penalty weights can be applied to each group of
48 +
#'   \eqn{\beta}{beta's}s to allow differential shrinkage. Can be 0 for some
49 +
#'   groups, which implies no shrinkage, and results in that group always being
50 +
#'   included in the model. Default value for each entry is the square-root of
51 +
#'   the corresponding size of each group.
52 +
#' @param weight a \eqn{nxn} observation weight matrix in the where \eqn{n} is
53 +
#'   the number of observations. Only used if \code{loss='wls'} is specified.
54 +
#'   Note that cross-validation is NOT IMPLEMENTED for \code{loss='wls'}.
55 +
#' @param dfmax limit the maximum number of groups in the model. Useful for very
56 +
#'   large \code{bs} (group size), if a partial path is desired. Default is
57 +
#'   \code{bs+1}.
55 58
#' @param pmax limit the maximum number of groups ever to be nonzero. For
56 -
#' example once a group enters the model, no matter how many times it exits or
57 -
#' re-enters model through the path, it will be counted only once. Default is
58 -
#' \code{min(dfmax*1.2,bs)}.
59 +
#'   example once a group enters the model, no matter how many times it exits or
60 +
#'   re-enters model through the path, it will be counted only once. Default is
61 +
#'   \code{min(dfmax*1.2,bs)}.
59 62
#' @param eps convergence termination tolerance. Defaults value is \code{1e-8}.
60 63
#' @param maxit maximum number of outer-loop iterations allowed at fixed lambda
61 -
#' value. Default is 3e8. If models do not converge, consider increasing
62 -
#' \code{maxit}.
64 +
#'   value. Default is 3e8. If models do not converge, consider increasing
65 +
#'   \code{maxit}.
63 66
#' @param delta the parameter \eqn{\delta}{delta} in \code{"hsvm"} (Huberized
64 -
#' squared hinge loss). Default is 1.
67 +
#'   squared hinge loss). Default is 1.
65 68
#' @param intercept Whether to include intercept in the model. Default is TRUE.
66 69
#' @return An object with S3 class \code{\link{gglasso}}.  \item{call}{the call
67 -
#' that produced this object} \item{b0}{intercept sequence of length
68 -
#' \code{length(lambda)}} \item{beta}{a \code{p*length(lambda)} matrix of
69 -
#' coefficients.} \item{df}{the number of nonzero groups for each value of
70 -
#' \code{lambda}.} \item{dim}{dimension of coefficient matrix (ices)}
71 -
#' \item{lambda}{the actual sequence of \code{lambda} values used}
72 -
#' \item{npasses}{total number of iterations (the most inner loop) summed over
73 -
#' all lambda values} \item{jerr}{error flag, for warnings and errors, 0 if no
74 -
#' error.} \item{group}{a vector of consecutive integers describing the
75 -
#' grouping of the coefficients.}
70 +
#'   that produced this object} \item{b0}{intercept sequence of length
71 +
#'   \code{length(lambda)}} \item{beta}{a \code{p*length(lambda)} matrix of
72 +
#'   coefficients.} \item{df}{the number of nonzero groups for each value of
73 +
#'   \code{lambda}.} \item{dim}{dimension of coefficient matrix (ices)}
74 +
#'   \item{lambda}{the actual sequence of \code{lambda} values used}
75 +
#'   \item{npasses}{total number of iterations (the most inner loop) summed over
76 +
#'   all lambda values} \item{jerr}{error flag, for warnings and errors, 0 if no
77 +
#'   error.} \item{group}{a vector of consecutive integers describing the
78 +
#'   grouping of the coefficients.}
76 79
#' @author Yi Yang and Hui Zou\cr Maintainer: Yi Yang <yi.yang6@@mcgill.ca>
77 80
#' @seealso \code{plot.gglasso}
78 81
#' @references Yang, Y. and Zou, H. (2015), ``A Fast Unified Algorithm for
79 -
#' Computing Group-Lasso Penalized Learning Problems,'' \emph{Statistics and
80 -
#' Computing}. 25(6), 1129-1141.\cr BugReport:
81 -
#' \url{https://github.com/emeryyi/gglasso}\cr
82 +
#'   Computing Group-Lasso Penalized Learning Problems,'' \emph{Statistics and
83 +
#'   Computing}. 25(6), 1129-1141.\cr BugReport:
84 +
#'   \url{https://github.com/emeryyi/gglasso}\cr
82 85
#' @keywords models regression
83 86
#' @examples
84 -
#' 
87 +
#'
85 88
#' # load gglasso library
86 89
#' library(gglasso)
87 -
#' 
90 +
#'
88 91
#' # load bardet data set
89 92
#' data(bardet)
90 -
#' 
93 +
#'
91 94
#' # define group index
92 95
#' group1 <- rep(1:20,each=5)
93 -
#' 
96 +
#'
94 97
#' # fit group lasso penalized least squares
95 98
#' m1 <- gglasso(x=bardet$x,y=bardet$y,group=group1,loss="ls")
96 -
#' 
99 +
#'
97 100
#' # load colon data set
98 101
#' data(colon)
99 -
#' 
102 +
#'
100 103
#' # define group index
101 104
#' group2 <- rep(1:20,each=5)
102 -
#' 
105 +
#'
103 106
#' # fit group lasso penalized logistic regression
104 107
#' m2 <- gglasso(x=colon$x,y=colon$y,group=group2,loss="logit")
105 -
#' 
108 +
#'
106 109
#' @export
107 110
gglasso <- function(x, y, group = NULL, loss = c("ls", "logit", "sqsvm", 
108 111
    "hsvm","wls"), nlambda = 100, lambda.factor = ifelse(nobs < nvars, 0.05, 0.001), 

@@ -46,8 +46,8 @@
Loading
46 46
}
47 47
48 48
49 -
KKT <- function(b0, beta, y, x, weight = NULL, lambda, pf, group, thr, delta, loss = c("ls", 
50 -
    "logit", "sqsvm", "hsvm","wls")) {
49 +
KKT <- function(b0, beta, y, x, weight = NULL, lambda, pf, group, thr, delta, 
50 +
                loss = c("ls", "logit", "sqsvm", "hsvm","wls")) {
51 51
    loss <- match.arg(loss)
52 52
	y <- drop(y)
53 53
    bn <- as.integer(max(group))
@@ -76,4 +76,5 @@
Loading
76 76
    }
77 77
    # cat("# of violations", ctr/length(lambda), "\n")
78 78
    cat("Averge # of violations per lambda", ctr/length(lambda))
79 +
    return(ctr)
79 80
} 
Files Coverage
R 63.51%
src 94.82%
Project Totals (15 files) 83.59%
Notifications are pending CI completion. Periodically Codecov will check the CI state, when complete notifications will be submitted. Push notifications now.
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading