2

当我们使用 'betweenness' 函数 betweenness(g,weights=NULL,directed = FALSE) 时,如果图具有权重属性,即使我们写成 weights=NULL,该函数仍然会使用权重属性计算介数。但我想计算没有权重属性的介数。所以我觉得这个功能看起来很奇怪。为什么我们写 weights=NULL 的时候还是使用 weight 属性?

function (graph, v = V(graph), directed = TRUE, weights = NULL, 
    nobigint = TRUE, normalized = FALSE) 
{
    if (!is.igraph(graph)) {
        stop("Not a graph object")
    }
    v <- as.igraph.vs(graph, v)
    if (is.null(weights) && "weight" %in% list.edge.attributes(graph)) {
        weights <- E(graph)$weight
    }
    if (!is.null(weights) && any(!is.na(weights))) {
        weights <- as.numeric(weights)
    }
    else {
        weights <- NULL
    }
    on.exit(.Call("R_igraph_finalizer", PACKAGE = "igraph"))
    res <- .Call("R_igraph_betweenness", graph, v - 1, as.logical(directed), 
        weights, as.logical(nobigint), PACKAGE = "igraph")
    if (normalized) {
        vc <- vcount(graph)
        res <- 2 * res/(vc * vc - 3 * vc + 2)
    }
    if (getIgraphOpt("add.vertex.names") && is.named(graph)) {
        names(res) <- V(graph)$name[v]
    }
    res
}
4

1 回答 1

6

权重选项不是忽略和不使用权重。这是一个关于为用户提供提供他们自己的权重向量的选项。

文档

weight - 用于计算加权介数的可选正权重向量。如果图形具有权重边属性,则默认使用此属性。

因此,如果weights=NULL该功能将E(g)$weight默认使用。

自己做这件事的方法是删除权重或将它们设置为 1 例如

E(g)$weight <- 1
于 2013-04-21T09:58:12.487 回答