如果您从 R 中使用 igraph,请使用此选项
scg {igraph} | R 文档 |
此函数处理一些矩阵和图的谱粗粒化 (SCG) 中涉及的所有步骤,如下面的参考文献中所述。
scg(
X,
ev,
nt,
groups = NULL,
mtype = c("symmetric", "laplacian", "stochastic"),
algo = c("optimum", "interv_km", "interv", "exact_scg"),
norm = c("row", "col"),
direction = c("default", "left", "right"),
evec = NULL,
p = NULL,
use.arpack = FALSE,
maxiter = 300,
sparse = igraph_opt("sparsematrices"),
output = c("default", "matrix", "graph"),
semproj = FALSE,
epairs = FALSE,
stat.prob = FALSE
)
X |
输入图或方阵。可以是 |
ev |
一个正整数向量,给出要保留的特征对的索引。对于实特征对,1 表示代数值最大的特征值,2 表示代数值第二大的特征值,依此类推。在复数情况下,幅度很重要。 |
nt |
长度为 1 或等于 |
groups |
一个 |
mtype |
字符标量。用于 SCG 的半投影算子的类型。目前可以使用“symmetric”、“laplacian”和“stochastic”。 |
algo |
字符标量。用于解决 SCG 问题的算法。可能的值为“optimum”、“interv_km”、“interv”和“exact_scg”。 |
norm |
字符标量。可以是 “row” 或 “col”。如果设置为 “row”,则拉普拉斯矩阵的行总和为零,随机矩阵的行总和为一;否则为列。 |
direction |
字符标量。当设置为“right”或“left”时,参数 |
evec |
一个数字矩阵,包含要通过粗粒化保留的(特征)向量(向量应按列方式存储在 |
p |
长度为 |
use.arpack |
逻辑标量。当设置为 |
maxiter |
当 |
sparse |
逻辑标量。如果请求矩阵,是否在结果中返回稀疏矩阵。 |
输出 |
字符标量。将此参数设置为 “default” 以检索与 |
semproj |
逻辑标量。将此参数设置为 |
epairs |
逻辑标量。将其设置为 |
stat.prob |
逻辑标量。这是为了在处理随机矩阵时收集平稳概率 |
请参阅 scg-method 以获取介绍。
在下面,V
是为其求解 SCG 的特征向量矩阵。如果未在 evec
参数中给出,则 V
是从 X
计算得出的。
算法“optimum”精确地解决了 V
中每个特征向量的 SCG 问题。对于对称和拉普拉斯矩阵问题(即当 mtype
为“symmetric”或“laplacian”时),此算法的运行时间为 O(\max nt \cdot m^2)
。对于随机问题,运行时间为 O(m^3)
。这里 m
是 V
中的行数。在这三种情况下,内存使用量均为 O(m^2)
。
算法“interv”和“interv_km”通过对特征向量的分量执行(目前)恒定的分箱来近似解决 SCG 问题,即使用 nt[i]
个恒定大小的 bin 来划分 V[,i]
。当 algo
= “interv_km” 时,在由 “interv” 获得的每个分区上运行 (Lloyd) k-means 算法以提高准确性。
一旦为每个特征向量找到最小化分区(无论是精确的还是近似的),最终分组将按以下方式进行:如果两个顶点在每个最小化分区中分组在一起,则它们在最终分区中分组在一起。通常,当 ncol(V)
>1 时,最终分区的大小是事先未知的。
最后,算法“exact_scg”将每个特征向量中具有相等分量的顶点分组。最后三个算法本质上具有线性运行时间和内存负载。
Xt |
粗粒化图或矩阵,可能是稀疏矩阵。 |
groups |
一个 |
L |
如果 |
R |
如果 |
values |
如果 |
vectors |
如果 |
p |
如果 |
David Morton de Lachapelle, http://people.epfl.ch/david.morton.
D. Morton de Lachapelle, D. Gfeller, and P. De Los Rios, Shrinking Matrices while Preserving their Eigenpairs with Application to the Spectral Coarse Graining of Graphs. Submitted to SIAM Journal on Matrix Analysis and Applications, 2008. http://people.epfl.ch/david.morton
scg-method 获取介绍。scg_eps
、scg_group
和 scg_semi_proj
。
## We are not running these examples any more, because they
## take a long time (~20 seconds) to run and this is against the CRAN
## repository policy. Copy and paste them by hand to your R prompt if
## you want to run them.
## Not run:
# SCG of a toy network
g <- make_full_graph(5) %du% make_full_graph(5) %du% make_full_graph(5)
g <- add_edges(g, c(1,6, 1,11, 6, 11))
cg <- scg(g, 1, 3, algo="exact_scg")
#plot the result
layout <- layout_with_kk(g)
nt <- vcount(cg$Xt)
col <- rainbow(nt)
vsize <- table(cg$groups)
ewidth <- round(E(cg$Xt)$weight,2)
op <- par(mfrow=c(1,2))
plot(g, vertex.color = col[cg$groups], vertex.size = 20,
vertex.label = NA, layout = layout)
plot(cg$Xt, edge.width = ewidth, edge.label = ewidth,
vertex.color = col, vertex.size = 20*vsize/max(vsize),
vertex.label=NA, layout = layout_with_kk)
par(op)
## SCG of real-world network
library(igraphdata)
data(immuno)
summary(immuno)
n <- vcount(immuno)
interv <- c(100,100,50,25,12,6,3,2,2)
cg <- scg(immuno, ev= n-(1:9), nt=interv, mtype="laplacian",
algo="interv", epairs=TRUE)
## are the eigenvalues well-preserved?
gt <- cg$Xt
nt <- vcount(gt)
Lt <- laplacian_matrix(gt)
evalt <- eigen(Lt, only.values=TRUE)$values[nt-(1:9)]
res <- cbind(interv, cg$values, evalt)
res <- round(res,5)
colnames(res) <- c("interv","lambda_i","lambda_tilde_i")
rownames(res) <- c("N-1","N-2","N-3","N-4","N-5","N-6","N-7","N-8","N-9")
print(res)
## use SCG to get the communities
com <- scg(laplacian_matrix(immuno), ev=n-c(1,2), nt=2)$groups
col <- rainbow(max(com))
layout <- layout_nicely(immuno)
plot(immuno, layout=layout, vertex.size=3, vertex.color=col[com],
vertex.label=NA)
## display the coarse-grained graph
gt <- simplify(as.undirected(gt))
layout.cg <- layout_with_kk(gt)
com.cg <- scg(laplacian_matrix(gt), nt-c(1,2), 2)$groups
vsize <- sqrt(as.vector(table(cg$groups)))
op <- par(mfrow=c(1,2))
plot(immuno, layout=layout, vertex.size=3, vertex.color=col[com],
vertex.label=NA)
plot(gt, layout=layout.cg, vertex.size=15*vsize/max(vsize),
vertex.color=col[com.cg],vertex.label=NA)
par(op)
## End(Not run)