如何构建新的中心性度量?

发布于 2024-08-12 06:40:15 字数 122 浏览 3 评论 0原文

我想使用 igraph 构建一个新的中心性度量,最好是在 R 中。

我该如何开始呢?

例如,添加到 igraph C 库R 接口 会更好吗?

I want to construct a new centrality measure using igraph, preferably in R.

How would I begin this?

For example, would I be better adding to the igraph C library or the R interface?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

以往的大感动 2024-08-19 06:40:16

这实际上取决于您的舒适程度。也就是说,igraph 主要是一个 C 库(您可以浏览 sourceforge 上的所有源代码) ,所以最合乎逻辑的扩展方法可能是在 C 中。例如,R 中的 closeness 函数只需调用相关的 C 函数:

> closeness
function (graph, v = V(graph), mode = c("all", "out", "in")) 
{
    if (!is.igraph(graph)) {
        stop("Not a graph object")
    }
    mode <- igraph.match.arg(mode)
    mode <- switch(mode, out = 1, `in` = 2, all = 3)
    on.exit(.Call("R_igraph_finalizer", PACKAGE = "igraph"))
    .Call("R_igraph_closeness", graph, as.igraph.vs(v), as.numeric(mode), 
        PACKAGE = "igraph")
}

这里是 现有的中心性源代码

This really boils down to what your comfortable level. That said, igraph is a primarily a C library (you can browse all the source code on sourceforge), so the most logical way to extend it is probably in C. For instance, the closeness function in R just call the related C function:

> closeness
function (graph, v = V(graph), mode = c("all", "out", "in")) 
{
    if (!is.igraph(graph)) {
        stop("Not a graph object")
    }
    mode <- igraph.match.arg(mode)
    mode <- switch(mode, out = 1, `in` = 2, all = 3)
    on.exit(.Call("R_igraph_finalizer", PACKAGE = "igraph"))
    .Call("R_igraph_closeness", graph, as.igraph.vs(v), as.numeric(mode), 
        PACKAGE = "igraph")
}

Here is the existing centrality sourcecode.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文