【问题标题】:Getting the target or source of an edge in igraph在 igraph 中获取边缘的目标或源
【发布时间】:2016-02-21 12:28:26
【问题描述】:

给定一个图 fg,我的例子:

library("igraph")

fg <- feature.graph <- graph.empty()

fg <- fg + vertices("root", "ho", "ha", value=c(1,2,3)) +
  edges(c("root", "ho", "root", "ha"), label=c("en", "an"), prob=c(0.2,0.8))

我提取了一个感兴趣的边缘:

> edge.of.interest <- E(fg)[from("root")][[1]]
> edge.of.interest
Edge sequence:
    e             
e [1] root -> ho  

现在我可以获取这条边的源或目标:

> get.edge(fg, edge.of.interest)
[1] 1 2
> get.edge(fg, edge.of.interest)[1]
[1] 1
> get.edge(fg, edge.of.interest)[2]
[1] 2

我本来希望函数源和目标具有这种效果:

> target(edge.of.interest)
2

我一直找不到这个或等效的功能。通过 get.edge 的方法是最好的吗?

【问题讨论】:

  • 您正在尝试从边缘获取顶点,对吧?但是尝试直接从图形中获取顶点不是更容易吗?以函数neighbors 为例?
  • 我将随机遍历图;当在给定的顶点处,任何远离它的边都以由边的属性 prob 给出的概率获取。至少直观地说,通过选择边缘更有意义。

标签: r igraph


【解决方案1】:

我知道这是一个老问题,但看起来我脑海中已经有了答案。你的意思是tail_ofhead_of 吗?

> head_of(fg, edge.of.interest)$value
[1] 1

> tail_of(fg, edge.of.interest)$value
[1] 2

另外,如果同时需要两端,ends 函数可能在这里有用。

【讨论】:

  • 不知道python中igraph是否有ends等价的功能?
  • 什么是等效的python igraph函数??
猜你喜欢
  • 1970-01-01
  • 2014-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多