igraph / xdata-igraph

xdata igraph, has been merged into igraph/igraph
GNU General Public License v2.0
18 stars 3 forks source link

Sign Change for Directed ASE #51

Closed dpmcsuss closed 10 years ago

dpmcsuss commented 10 years ago

It appears that sometimes the sign of X is switched compared to Y when embedding a directed graph. For example, we should have below that the mean is around .3 for the outer product between X and Y since that should approximate the density reasonable well.. But depending on the (separate) randomness in the embedding procedure, I get either 0.2999806 or -0.2999806.

You might need to run this a few times to see the phenomenon. Not sure why this is happening.

set.seed(12345)
pref.matrix <- diag(0.2,2)+0.2
block.sizes <-c(800,800)
n <- sum(block.sizes)
g<-sbm.game(n,pref.matrix,block.sizes,directed=TRUE)
ase <-  adjacency.spectral.embedding(g,2) # Embed to high dimensions
mean(ase$X %*% t(ase$Y))
gaborcsardi commented 10 years ago

The problem is calculating the eigendecomposition twice. There is a workaround I can implement:

library(igraph)
A <- graph.tree(5, 3)[sparse=FALSE]
null <- matrix(0, 5, 5)
A2 <- cbind(rbind(null, A), rbind(t(A), null))
svd(A)
eigen(A2)

What seems to be tricky is the case with multiple eigenvalues.

gaborcsardi commented 10 years ago

And here is an example on how to compute the left singular values from the right ones: https://nanohub.org/tools/seteb/browser/trunk/lib/ARPACK/EXAMPLES/SVD/dsvd.f?rev=9

gaborcsardi commented 10 years ago

Should be OK now.