如何用iGraph挖掘R中的图案

Eri*_*man 7 r graph igraph

我正在尝试使用该软件包在R中挖掘3节点图案igraph.我想检索图中每个顶点的图案数量,这从graph.motifs()函数中看不出来.

因此,对于示例图:

testGraph = barabasi.game(10, 
m = 5,
power = 2, 
out.pref = TRUE,
zero.appeal = 0.5,
directed = TRUE)
Run Code Online (Sandbox Code Playgroud)

我可以graph.motifs()用来计算整个图中每个3节点图案的总数:

graph.motifs(testGraph, 
size = 3)
Run Code Online (Sandbox Code Playgroud)

[1] 0 0 26 0 16 0 2 58 0 0 0 0 0 0 0 0

但我想知道个别顶点参与.那么,顶点1参与了多少个图案(以及什么类型)?有人知道一个简单的方法吗?

Gab*_*rdi 7

这是一个快速的操作方法.

你对顶点A的三元组感兴趣,然后首先创建包含A及其直接邻居的诱导子图.您可以通过neighborhood()和/ induced.subgraph()或简单地执行此操作graph.neighborhood().

然后找到这个子图中的图案,但不是用graph.motifs(),而是用triad.census(),因为它计算所有可能的三元组,即使是非连接的三元组.

然后从该子图中删除A,然后triad.census()再次调用.两个计数向量的差异将是包含A的主题.


Eri*_*man 6

这是Gabor解决方案的一个独立示例:

testGraph = barabasi.game(10, 
    m = 5,
    power = 0.6, 
    out.pref = TRUE,
    zero.appeal = 0.5,
    directed = TRUE)

# Label nodes to more easily keep track during subsets/deletions
V(testGraph)$name = c('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten')

subGraph = graph.neighborhood(testGraph, order = 1, V(testGraph)[1], mode = 'all')[[1]]
allMotifs = triad.census(subGraph)
removeNode = delete.vertices(subGraph, 'one')
node1Motifs = allMotifs - triad.census(removeNode)
Run Code Online (Sandbox Code Playgroud)