library(Matrix)
# compute the semi-projectors and projector for the partition
# provided by a community detection method
g <- barabasi.game(20, m=1.5)
eb <- edge.betweenness.community(g)
memb <- membership(eb)
lr <- scgSemiProjectors(memb)
#In the symmetric case L = R
tcrossprod(lr$R) # same as lr$R %*% t(lr$R)
P <- crossprod(lr$R) # same as t(lr$R) %*% lr$R
#P is an orthogonal projector
isSymmetric(P)
sum( (P %*% P-P)^2 )
## use L and R to coarse-grain the graph Laplacian
lr <- scgSemiProjectors(memb, mtype="laplacian")
L <- graph.laplacian(g)
Lt <- lr$L %*% L %*% t(lr$R)
## or better lr$L \%*\% tcrossprod(L,lr$R)
rowSums(Lt)
Run the code above in your browser using DataLab