forked from PoisotLab/lpbrim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lesscommon.r
31 lines (28 loc) · 825 Bytes
/
lesscommon.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
netToAdjacency = function(net,useSparse=FALSE){
x <- as.factor(net[,1])
y <- as.factor(net[,2])
z <- net[,3]
if(!useSparse){
adj <- matrix(0,
nrow=nlevels(x),
ncol=nlevels(y),
dimnames=list(levels(x),levels(y))
)
adj[cbind(x, y)] <- z
}else{
adj <- sparseMatrix(i=as.integer(x),
j=as.integer(y),
x=z,
dims=c(nlevels(x),nlevels(y)),
dimnames=list(levels(x), levels(y))
)
}
adj
}
modulesToSmat = function(modules){
comms <- unique(modules)
nc <- length(comms)
Smat <- matrix(0,nrow=length(names(modules)),ncol=nc,dimnames=list(names(modules),comms))
Smat[cbind(names(modules),modules)] <- 1
Smat
}