dist.matrix | R Documentation |
Compute the distance between two matrices.
The distance between two matrices is defined as the sum of distances between column pairs.
This function matches the columns of two matrices, such that the matrix distance
(i.e., the sum of paired column distances) is minimized.
This is accomplished by solving an optimization over column permutation.
Given two matrices, x
and y
, find permutation p() that minimizes
sum_i similarity(x[,p(i)], y[,i]
),
where the similarity()
can be "euclidean" distance, 1 - "cosine", or "maximum" difference (manhattan distance).
The solution is computed by clue::solve_LSAP()
.
dist.matrix(x, y, method = "euclidean")
x, y |
|
method |
distance measure, "maximum", "cosine", or "euclidean" are implemented. |
a list
of four components:
dist |
|
match |
|
value |
|
method |
|
nrow |
|
clue::solve_LSAP
x <- diag(4)
y <- x + rnorm(16, sd = 0.05) # add some noise
y = t(t(y) / sqrt(colSums(y ^ 2))) ## normalize the columns
## euclidian distance between column pairs, with minimal matches
dist.matrix(x, y, "euclidean")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.