关于igraph中的中介功能

Ben*_*Ben 2 r igraph

当我们使用'中性'函数介于中间(g,weights = NULL,directed = FALSE)时,如果图形具有权重属性,即使我们写权重= NULL,该函数仍将使用权重属性计算中介性.但我想计算没有权重属性的中介.所以我觉得这个功能看起来很奇怪.为什么在写weight = 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
}
Run Code Online (Sandbox Code Playgroud)

use*_*1_G 6

权重选项不是忽略而不是使用权重.它是关于为用户提供选项以提供他们自己的权重向量.

来自doc

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

因此,如果weights=NULL该函数将E(g)$weight默认使用.

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

E(g)$weight <- 1
Run Code Online (Sandbox Code Playgroud)