GPUglm {GPUmatrix} | R Documentation |
Fitting Generalized Linear Models using GPUmatrix objects
Description
These functions mimic the functions speedglm
and speedglm.wfit
of the library 'speedglm' to compute on gpu.matrix-class objects. At the same time, these functions mimic the functions glm
, and glm.fit
from the library 'stats' to compute on large data sets.
Usage
glm.fit.GPU(x, y, intercept = TRUE, weights = NULL, family =
gaussian(), start = NULL, etastart = NULL, mustart =
NULL, offset = NULL, acc = 1e-08, maxit = 25, k = 2,
sparse = NULL, trace = FALSE, dtype = "float64", device =
NULL, type = NULL, ...)
GPUglm(...)
Arguments
As mentioned in the description, these functions mimic speedglm
, so almost every parameter does too. There is only three new parameters explained below.
The common parameters with speedglm
:
x |
the same as |
y |
the same as |
intercept |
the same as |
weights |
the same as |
family |
the same as |
start |
the same as |
etastart |
the same as |
mustart |
the same as |
offset |
the same as |
acc |
the same as |
maxit |
the same as |
k |
the same as |
sparse |
if matrix |
trace |
If the user wants to see the development of the iterations. By default FALSE |
... |
For |
The glm.fit.GPU
function internally initialises matrices of the 'GPUmatrix' class by calling the gpu.matrix
function. The following parameters correspond to this function:
dtype |
parameter of the function |
device |
parameter of the function |
type |
parameter of the function |
Details
The GPUglm
function internally calls the glm
function by selecting glm.fit.GPU
as the method. The input parameters of the GPUglm
function are equivalent to those of the glm
function.
If the gpu.matrix-class object(s) are stored on the GPU, then the operations will be performed on the GPU. See gpu.matrix
.
Value
Both glmGPU
, and glm.fit.GPU
returns an object of class "GPUglm". This object can be treated as a list. This object mimics the output of the function speedglm
:
coefficients |
the estimated coefficients. |
logLik |
the log likelihood of the fitted model. |
iter |
the number of iterations of IWLS used. |
tol |
the maximal value of tolerance reached. |
family |
the maximal value of tolerance reached. |
link |
the link function used. |
df |
the degrees of freedom of the model. |
XTX |
the product X'X (weighted, if the case). |
dispersion |
the estimated dispersion parameter of the model. |
ok |
the set of column indeces of the model matrix where the model has been fitted. |
rank |
the rank of the model matrix. |
RSS |
the estimated residual sum of squares of the fitted model. |
method |
TODO |
aic |
the estimated Akaike Information Criterion. |
offset |
he model offset. |
sparse |
a logical value which indicates if the model matrix is sparse. |
deviance |
the estimated deviance of the fitted model. |
nulldf |
the degrees of freedom of the null model. |
nulldev |
the estimated deviance of the null model. |
ngoodobs |
the number of non-zero weighted observations. |
n |
the number of observations. |
intercept |
a logical value which indicates if an intercept has been used. |
convergence |
a logical value which indicates if convergence was reached. |
terms |
the terms object used. |
call |
the matched call. |
xlevels |
(where relevant) a record of the levels of the factors used in fitting. |
See Also
Also of interest may be the function LR_GradientConjugate_gpumatrix
for logistic regression.
Examples
## Not run:
require(MASS,quietly = TRUE)
require(stats,quietly = TRUE)
# linear model (example taken from 'glm'):
utils::data(anorexia, package = "MASS")
anorex_glm <- glm(Postwt ~ Prewt + Treat + offset(Prewt),
family = gaussian(), data = anorexia)
summary(anorex_glm)
#Using GPUglm:
anorex_GPUglm <- GPUglm(Postwt ~ Prewt + Treat + offset(Prewt),
family = gaussian, data = anorexia)
summary(anorex_GPUglm)
#linear model using glm.fit.gpu
x <- model.matrix(~Treat+Prewt,data=anorexia)
y <- as.matrix(anorexia$Postwt)
s1_glm <- glm.fit(x=x,y=y)
s1_gpu <- glm.fit.GPU(x=x,y=y)
s1_glm$coefficients
s1_gpu$coefficients
# poisson (example taken from 'glm'):
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
glm.D93 <- glm(counts ~ outcome + treatment, family = poisson())
summary(glm.D93)
gpu.glm.D93 <- GPUglm(counts ~ outcome + treatment, family = poisson())
summary(gpu.glm.D93)
#logistic:
data(menarche)
glm.out <- glm(cbind(Menarche, Total-Menarche) ~ Age, family=binomial(), data=menarche)
summary(glm.out)
glm.out_gpu <- GPUglm(cbind(Menarche, Total-Menarche) ~ Age, family=binomial(), data=menarche)
summary(glm.out_gpu)
#can be also called using glm.fit.gpu:
new_menarche <- data.frame(Age=rep(menarche$Age,menarche$Total))
observations <- c()
for(i in 1:nrow(menarche)){
observations <- c(observations,rep(c(0,1),c(menarche$Total[i]-menarche$Menarche[i],
menarche$Menarche[i])))
}
new_menarche$observations <- observations
x <- model.matrix(~Age,data=new_menarche)
head(new_menarche)
glm.fit_gpu <- glm.fit.GPU(x=x,y=new_menarche$observations, family=binomial())
summary(glm.fit_gpu)
#GPUmatrix package also include the function 'LR_GradientConjugate_gpumatrix'
lr_gran_sol <- LR_GradientConjugate_gpumatrix(X = x,y = observations)
#check results
glm.out$coefficients
glm.out_gpu$coefficients
glm.fit_gpu$coefficients
lr_gran_sol
## End(Not run)