These functions mimic the stats
functions cov
and cor
to compute on gpu.matrix
objects: "cov
and cor
compute the covariance and correlation of x
and y
if these are vectors. If x
and y
are matrices then the covariances (or correlations) between the columns of x
and the columns of y
are computed."
cov2cor
scales a covariance matrix into the corresponding correlation matrix efficiently.
# S4 method for gpu.matrix.tensorflow,ANY,ANY,ANY
cor(x,y)
# S4 method for gpu.matrix.tensorflow,ANY,missing,character
cor(x,y,method)
# S4 method for gpu.matrix.tensorflow,missing,missing,character
cor(x,y,method)
# S4 method for ANY,gpu.matrix.tensorflow,ANY,ANY
cor(x,y)
# S4 method for gpu.matrix.tensorflow,missing,ANY,ANY
cor(x,y)# S4 method for ANY,gpu.matrix.torch,ANY,ANY
cor(x,y)
# S4 method for gpu.matrix.torch,ANY,ANY,ANY
cor(x,y)
# S4 method for gpu.matrix.torch,ANY,missing,character
cor(x,y,method)
# S4 method for gpu.matrix.torch,missing,missing,character
cor(x,y,method)
# S4 method for gpu.matrix.torch,missing,missing,missing
cor(x,y)
# S4 method for gpu.matrix.torch,missing,ANY,ANY
cor(x,y)
# S4 method for gpu.matrix.tensorflow
cov(x,y)
# S4 method for ANY,gpu.matrix.tensorflow
cov(x,y)
# S4 method for gpu.matrix.tensorflow,ANY
cov(x,y)
# S4 method for gpu.matrix.tensorflow,missing
cov(x,y)
# S4 method for gpu.matrix.torch
cov(x,y)
# S4 method for ANY,gpu.matrix.torch
cov(x,y)
# S4 method for gpu.matrix.torch,ANY
cov(x,y)
# S4 method for gpu.matrix.torch,missing
cov(x,y)
# S4 method for gpu.matrix.tensorflow
cov2cor(V)
# S4 method for gpu.matrix.torch
cov2cor(V)
The result obtained by applying these functions will be a gpu.matrix
object. For each function the result will be:
- cor
correlation between x
and y
(when two vectors are the input) or the correlation between the columns of x
and y
if x
and y
are a gpu.matrix class object. If y
is empty, is equivalent to y=x
.
- cov
the same as cor
but compute the covariance.
- cov2cor
scales a covariance matrix into the corresponding correlation matrix efficiently.
a gpu.matrix
.
NULL
(default) or a vector, matrix, data frame or gpu.matrix
with compatible dimensions to x.
a character string indicating which correlation coefficient (or covariance) is to be computed. One of "pearson"
(default) or "spearman"
.
symmetric numeric gpu.matrix, usually positive definite such as a covariance matrix.
These functions work in the same way as their counterparts in the 'stats' library. Note that the 'Kendal' method (implemented in the 'stats' library) is not available for working with gpu.matrix-class objects.
Notice that the inputs can be either an object of class 'matrix', 'Matrix' or 'gpu.matrix'. User must be sure that the input values must be numeric.
If the input gpu.matrix-class object(s) are stored on the GPU, then the operations will be performed on the GPU. See gpu.matrix
. The result will be a gpu.matrix object.
# \donttest{
if (FALSE) {
a <- gpu.matrix(rnorm(10))
b <- gpu.matrix(rnorm(10))
cor(a,b)
#example taken from stats corresponding help page:
longley_matrix <- as.matrix(longley)
longley_gpu <- as.gpu.matrix(longley_matrix)
C1 <- cor(longley_gpu)
cov(longley_gpu)
cov2cor(cov(longley_gpu))
}
# }
Run the code above in your browser using DataLab