grad.logistic: Gradient of the logistic regression risk.

Description Usage Arguments Value Examples

Description

Computes the gradient of the logistic regression error:

f(x) = 1/n sum_{i=1}^n ( log(1 + exp(- b_i * x' * A_i) ) ,

for a given design matrix A and a response binary vector b with values +1 and -1.

Usage

1
grad.logistic(x, opts)

Arguments

x

A p-dimensional vector where the gradient is computed.

opts

List of parameters, which must include:

  • A, a n*p design matrix

  • b, a n-dimensional response vector taking values 1 or -1.

Value

The gradient of the function f(x) = 1/n sum_{i=1}^n ( log(1 + exp(- b_i * x' * A_i) ), which is:

f'(x) = 1/n sum_{i=1}^n -b_i A_i / (1 + exp( b_i * x' * A_i ))

Examples

1
2
3
4
grad.logistic(c(1,3,-2), list(A=diag(3), b=c(1,-1,1))
# The following give the same (elastic net penalized logistic regression without offset):
glmnet(A,b,family="binomial",lambda=0.1,standardize=FALSE,intercept=FALSE, alpha=0.5)$b
apg(grad.logistic, prox.elasticnet, ncol(A), list(A=A, b=b, lambda=0.1, alpha=0.5) )$x

jpvert/apg documentation built on May 19, 2019, 11:51 p.m.