bonmi's title

bonmi(W, r, weights = NULL, rsvd.use = FALSE)

Arguments

W

a list of PPMI matrices, with rownames and colnames being the features

r

rank

weights

The weight vector for the PPMI matrices. Default NULL, the weights will be estimated from data.

rsvd.use

Bool. Default FALSE. If TRUE, we will use the 'rsvd' function to calculate the svd, which is much faster than the 'svd' function when r is small.

Value

An embedding matrix.

Examples

set.seed(1)
N = 3000
r = 10
m = 5
p = 0.1
X0 = matrix(rnorm(N*r),nrow=N)
W0 = X0 %*% t(X0)
rownames(W0) = colnames(W0) = paste0('code',1:N)

W = list()
for(s in 1:m){
  ids = which(runif(N)<p)
  Ns = length(ids)
  Es = matrix(rnorm(Ns*Ns,sd=s*0.01),nrow=Ns)
  Es = Es + t(Es)
  Ws = W0[ids,ids] + Es
  W[[s]] = Ws
}

Xhat <- bonmi(W,r,weights=NULL,rsvd.use=FALSE)
#Xhat <- bonmi(W,r,weights=NULL,rsvd.use=TRUE)
codes = rownames(Xhat)
What = Xhat%*%t(Xhat)

id = match(codes,rownames(W0))
Wstar = W0[id,id]

#bonmi's result
norm(What-Wstar,'F')/norm(Wstar,'F')
#> [1] 0.003746704