Skip to content

Commit 31f159f

Browse files
committed
documentation for parameters
1 parent da9fcc7 commit 31f159f

File tree

1 file changed

+66
-3
lines changed

1 file changed

+66
-3
lines changed

R/rehline.R

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
1+
##' Solving Regularized Composite ReLU-ReHU Loss Minimization Problems
2+
##'
3+
##' @description
4+
##' This function solves the regularized composite ReLU-ReHU minimization
5+
##' problem (called \emph{ReHLine optimization} for short) of the following form:
6+
##' \deqn{
7+
##' \min_{\beta}\ \sum_{i=1}^n \sum_{l=1}^L\mathrm{ReLU}(u_{li}x_i^T\beta+v_{li})+
8+
##' \sum_{i=1}^n \sum_{h=1}^H\mathrm{ReHU}_{\tau_{hi}}(s_{hi}x_i^T\beta+t_{hi})+
9+
##' \frac{1}{2}\Vert\beta\Vert^2
10+
##' }
11+
##' subject to general linear constraints \eqn{A\beta+b\ge 0},
12+
##' where \eqn{\beta\in\mathbb{R}^d}{\beta} is a length-\eqn{d} vector,
13+
##' \eqn{x_i\in\mathbb{R}^d} is the feature vector for the \eqn{i}-th observation,
14+
##' \eqn{U=(u_{li})} and \eqn{V=(v_{li})} are \eqn{L\times n} matrices,
15+
##' \eqn{S=(s_{hi})}, \eqn{T=(t_{hi})}, and \eqn{\tau=(\tau_{hi})} are
16+
##' \eqn{H\times n} matrices, \eqn{A} is an \eqn{m\times d} matrix,
17+
##' and \eqn{b} is a length-\eqn{m} vector.
18+
##'
19+
##' The \eqn{\mathrm{ReLU}} function is \eqn{\mathrm{ReLU}(x)=\max(x, 0)},
20+
##' and \eqn{\mathrm{ReHU}_\tau} is defined as
21+
##' \deqn{
22+
##' \mathrm{ReHU}_\tau(z)=
23+
##' \begin{cases}
24+
##' 0, & z\le 0 \\
25+
##' z^2/2, & 0<z\le\tau \\
26+
##' \tau(z-\tau/2), & z>\tau
27+
##' \end{cases}.
28+
##' }
29+
##'
30+
##' Many popular empirical risk minimization problems can be expressed
31+
##' in the form of ReHLine optimization, such as SVM, quantile regression,
32+
##' Huber regression, etc.
33+
##'
34+
##' @param Xmat The data matrix \eqn{X=(x_1,\ldots,x_n)^T} of size
35+
##' \eqn{n\times d}, representing \eqn{n} observations
36+
##' and \eqn{d} features.
37+
##' @param Umat,Vmat,Smat,Tmat The matrices \eqn{U=(u_{li})}, \eqn{V=(v_{li})},
38+
##' \eqn{S=(s_{hi})}, and \eqn{T=(t_{hi})} in the
39+
##' ReHLine optimization problem. Can be set to
40+
##' \code{NULL}, meaning excluding the ReLU or ReHU
41+
##' terms in the objective function.
42+
##' @param Tau Either a numeric scalar, or an \eqn{H\times n} matrix
43+
##' representing \eqn{\tau=(\tau_{hi})}.
44+
##' @param Amat An \eqn{m\times d} matrix representing the
45+
##' coefficients of \eqn{m} constraints. Can be
46+
##' set to \code{NULL}, meaning no constraint is imposed.
47+
##' @param bvec A length-\eqn{m} vector. Can be set to \code{NULL},
48+
##' meaning no constraint is imposed.
49+
##' @param max_iter Maximum number of iterations.
50+
##' @param tol Tolerance parameter for convergence test.
51+
##' @param shrink Whether to use the shrinkage algorithm.
52+
##' @param verbose Level of verbosity.
53+
##'
154
rehline = function(
255
Xmat, Umat, Vmat, Smat = NULL, Tmat = NULL, Tau = Inf,
356
Amat = NULL, bvec = NULL,
@@ -6,18 +59,28 @@ rehline = function(
659
n = nrow(Xmat)
760
d = ncol(Xmat)
861

9-
if(is.null(Umat) || is.null(Vmat))
62+
# If U is NULL, exclude U and V
63+
# If U is not NULL but V is NULL, set V to zero
64+
if(is.null(Umat))
1065
{
1166
Umat = Vmat = matrix(0, 0, n)
67+
} else if(is.null(Vmat)) {
68+
Vmat = matrix(0, nrow(Umat), ncol(Umat))
1269
}
13-
if(is.null(Smat) || is.null(Tmat))
70+
# Similar for S and T
71+
if(is.null(Smat))
1472
{
1573
Smat = Tmat = matrix(0, 0, n)
74+
} else if(is.null(Tmat)) {
75+
Tmat = matrix(0, nrow(Smat), ncol(Smat))
1676
}
17-
if(is.null(Amat) || is.null(bvec))
77+
# Similar for A and b
78+
if(is.null(Amat))
1879
{
1980
Amat = matrix(0, 0, d)
2081
bvec = numeric(0)
82+
} else if(is.null(bvec)) {
83+
bvec = numeric(nrow(Amat))
2184
}
2285

2386
# Expand Tau to a matrix

0 commit comments

Comments
 (0)