Description Usage Arguments Details Value Examples
View source: R/match.factors.R
Aligns columns in m.toalign to the ordering of columns in m.alignto based on cosine similarity using bipartite graph matching such that the pairing gives a minimum possible total diagonal cosine distance.
1 | match.factors(m.alignto, m.toalign)
|
m.alignto |
template matrix |
m.toalign |
matrix to match to template, reorder columns, and return |
The Hungarian algorithm is used for bipartite graph matching. The RcppHungarian implementation is natively used. Cosine distance used is from lsmf::sparse.cos
with Euclidean norm.
list of components:
"m.aligned" with m.toalign columns reordered to match m1m2
"cos" distance of each factor to m1
"rel.cos" distance as the best distance over the best distance not used in the pairing
"cost" of the matching
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ## Not run:
data(moca7k)
library(Matrix)
s <- as(sparse.cos(moca7k[,1:1000]), "dgCMatrix")
W1 <- lsmf(s, 10, symmetric = TRUE)$W
W2 <- lsmf(s, 10, symmetric = TRUE)$W
# factors not aligned
plot(as.matrix(W1), as.matrix(W2))
mean(diag(cor(W1,W2)))
# [1] 0.1210305
# factors aligned
W2 <- match.factors(W1, W2)$m.aligned
plot(as.matrix(W1), as.matrix(W2))
mean(diag(cor(W1,W2)))
# [1] 0.9166595
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.