distance-matrix

R Interclass distance matrix

☆樱花仙子☆ 提交于 2019-12-06 08:46:19
This question is sort of a follow-up to how to extract intragroup and intergroup distances from a distance matrix? in R . In that question, they first computed the distance matrix for all points, and then simply extracted the inter-class distance matrix. I have a situation where I'd like to bypass the initial computation and skip right to extraction, i.e. I want to directly compute the inter-class distance matrix. Drawing from the linked example, with tweaks, let's say I have some data in a dataframe called df : values<-c(0.002,0.3,0.4,0.005,0.6,0.2,0.001,0.002,0.3,0.01) class<-c("A","A","A",

Extract diagonals from a distance matrix in R

帅比萌擦擦* 提交于 2019-12-03 18:17:49
问题 I would like to know how can I extract the values of the first diagonal from a distance matrix. For example: > mymatrix [,1] [,2] [1,] 1 2 [2,] 3 4 [3,] 6 4 [4,] 8 6 > dist(mymatrix) 1 2 3 2 2.828427 3 5.385165 3.000000 4 8.062258 5.385165 2.828427 I want to get in a vector the values: 2.828427, 3.000000, 2.828427 Thanks! 回答1: One work around is to convert the dist object to matrix and then extract elements where row index is one larger than the column index: mat = as.matrix(dist(mymatrix))

Optimizing execution of a CUDA kernel for Triangular Matrix calculation

末鹿安然 提交于 2019-12-03 08:42:41
I am developing my first Cuda application, and I have a kernel with "below-expected throughput", which seems to be the biggest bottleneck at the moment. The task of the kernel is to compute an N by N sized matrix ( DD ) containing squared distances between all elements on a data matrix. The data matrix ( Y ) is size N by D (to support multi dimensional data) and stored as row-major. Source: __global__ void computeSquaredEuclideanDistance(const float * __restrict__ Y, float * __restrict__ DD, const int N, const int D) { int index = blockIdx.x * blockDim.x + threadIdx.x; int stride = blockDim.x

Extract diagonals from a distance matrix in R

北城以北 提交于 2019-11-29 17:39:02
I would like to know how can I extract the values of the first diagonal from a distance matrix. For example: > mymatrix [,1] [,2] [1,] 1 2 [2,] 3 4 [3,] 6 4 [4,] 8 6 > dist(mymatrix) 1 2 3 2 2.828427 3 5.385165 3.000000 4 8.062258 5.385165 2.828427 I want to get in a vector the values: 2.828427, 3.000000, 2.828427 Thanks! One work around is to convert the dist object to matrix and then extract elements where row index is one larger than the column index: mat = as.matrix(dist(mymatrix)) mat[row(mat) == col(mat) + 1] # [1] 2.828427 3.000000 2.828427 A seemingly complicated but extremely

as.matrix on a distance object is extremely slow; how to make it faster?

邮差的信 提交于 2019-11-29 16:34:58
I found an R package Rlof which uses multithreading to calculate distance matrices and it does a wonderful job. However, the output of the function distmc is a vector rather than a matrix. Applying as.matrix to this "dist" object turns out much more expensive than the multi-threaded calculation of distances. Looking at the function help , the options for printing the diagonal and upper triangle are there, but I don't understand where they are supposed to be used. Is there a way of saving the time of as.matrix somehow? Reproducible example: set.seed(42) M1 = matrix(rnorm(15000*20), nrow = 15000

Example of increasing the work per thread in CUDA

浪尽此生 提交于 2019-11-29 03:58:46
Algorithm : I'm writing a program with CUDA and the problem is the following: Two matrices A (n * 128) and B (m * 128) I take the first row of A, and I compute the distance between that vector and all the rows of B, one by one. I write the result of each distance on a row of a matrix C, so the element C(i,j) of C contains the distance between row i of A and row j of B. and I proceed with the next row of A. I've implemented it this way: I've got a grid made by ( n * m ) blocks, and 128 threads per block. ( 1 * 128 ). QUESTION : The program runs successfully with the expected results but the

as.matrix on a distance object is extremely slow; how to make it faster?

拟墨画扇 提交于 2019-11-28 10:01:31
问题 I found an R package Rlof which uses multithreading to calculate distance matrices and it does a wonderful job. However, the output of the function distmc is a vector rather than a matrix. Applying as.matrix to this "dist" object turns out much more expensive than the multi-threaded calculation of distances. Looking at the function help, the options for printing the diagonal and upper triangle are there, but I don't understand where they are supposed to be used. Is there a way of saving the

Example of increasing the work per thread in CUDA

点点圈 提交于 2019-11-27 17:58:43
问题 Algorithm : I'm writing a program with CUDA and the problem is the following: Two matrices A (n * 128) and B (m * 128) I take the first row of A, and I compute the distance between that vector and all the rows of B, one by one. I write the result of each distance on a row of a matrix C, so the element C(i,j) of C contains the distance between row i of A and row j of B. and I proceed with the next row of A. I've implemented it this way: I've got a grid made by ( n * m ) blocks, and 128 threads