match.factors: Align and reorder factors

Description Usage Arguments Details Value Examples

View source: R/match.factors.R

Description

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.

Usage

1
match.factors(m.alignto, m.toalign)

Arguments

m.alignto

template matrix

m.toalign

matrix to match to template, reorder columns, and return

Details

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.

Value

list of components:

Examples

 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)

zdebruine/LSMF documentation built on Jan. 1, 2021, 1:50 p.m.