dist {GPUmatrix}R Documentation

Distance Matrix Computation with GPU

Description

This function mimics the 'stats' function dist: 'computes and returns the distance matrix computed by using the specified distance measure to compute the distances between the rows of a data matrix.'

Usage

dist(x, method = "euclidean", diag = FALSE,
    upper = FALSE, p = 2)

## S4 method for signature 'gpu.matrix.torch'
dist(x,method,diag,upper,p)

Arguments

x

a gpu.matrix.

method

the same as the 'stats' function dist: the distance measure to be used. Could be "euclidean", "maximum", "manhattan" or "minkowski". Note that the "canberra", "binary" methods are not included.

diag

the same as the 'stats' function dist: logical value indicating if the diagonal of the distances should be printed. It is set to TRUE and cannot be changed.

upper

the same as the 'stats' function dist: logical value indicating whether the upper triangle of the distance matrix should be printed. It is set to TRUE and cannot be changed.

p

the same as the 'stats' function dist: The power of the Minkowski distance.

Details

The function mimics the 'stat' function dist. The distance measures used are (taken from dist):

euclidean: \sqrt{\sum_i(x_i-y_i)^2}

maximum: Maximum distance between two components of x and y.

manhattan: Absolute distance between the tow vectors.

minkowski: the p norm: the ppth root of the sum of the ppth powers of the differences of the components.

For more details see dist.

The function dist internally calls the corresponding function of the library torch or tensorflow (depending on the type of input gpu.matrix-class).

If the input gpu.matrix-class object is stored on the GPU, then the operations will be performed on the GPU. See gpu.matrix.

Value

The function returns a gpu.matrix-class object with the corresponding distances between the rows of the input gpu.matrix object.

See Also

For more information see: dist, and torch_cdist.

Examples


## Not run: 

#the example compare the results with the
#'stats' function 'dist':

x <- matrix(rnorm(100), nrow = 5)

dist(x,diag = TRUE,upper = TRUE,method = "euclidean")
dist(x = as.gpu.matrix(x),method = "euclidean")

dist(x,diag = TRUE,upper = TRUE,method = "maximum")
dist(x = as.gpu.matrix(x),method = "maximum")

dist(x,diag = TRUE,upper = TRUE,method = "manhattan")
dist(x = as.gpu.matrix(x),method = "manhattan")

dist(x,diag = TRUE,upper = TRUE,method = "minkowski")
dist(x = as.gpu.matrix(x),method = "minkowski")

dist(x,diag = TRUE,upper = TRUE,method = "minkowski",p = 23)
dist(x = as.gpu.matrix(x),method = "minkowski",p = 23)


## End(Not run)


[Package GPUmatrix version 1.0.2 Index]