glm_momentum: Implement gradient descent GLM, adaptive (momentum)

Description Usage Arguments Examples

View source: R/glm_momentum.R

Description

This function implements gradient descent GLM using the momentum algorithm

Usage

1
glm_momentum(X, Y, mu_fun, max_n, lr, gamma = 0.8, tol = 1e-10)

Arguments

X

a model matrix, the X variables as columns

Y

a factor vector, the response variable

mu_fun

a function depending on Xbeta, giving the mean of the link function

max_n

max number of iterations (a positive integer)

lr

the learning rate

gamma

the constant weight of the past update (a positive number)

tol

the difference threshold for which we will exit the algorithm for iterations less than max_n

Examples

1
2
3
4
5
6
7
n <- 5000; p <- 3
beta <- c(-1, 0.2, 0.1)
X <- cbind(1, matrix(rnorm(n*(p-1)), ncol = p-1))
eta <- X %*% beta
lambda <- exp(eta)
y <- stats::rpois(n, lambda = lambda)
glm_momentum(X, y, mu_fun = function(eta) exp(eta), lr=0.00000001, max_n = 100000)

kimgannon/bis557 documentation built on Nov. 25, 2020, 7:09 a.m.