我正在使用R& igraph
包用于绘制用graphml编写的图形,我想使用此语法中包含的weight
参数
<edge id="e389" source="w4" target="w0">
<data key="d1">0.166666666667</data>
</edge>
我可以用
获取值weight = E(f)$weight // f is the graph
但在计算weight
df = degree(f)
有关详细信息:所有节点相互连接,权重为1 /(number_of_nodes - 1),因此每个节点的度数应为1.
graphml文件
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<key id="d0" for="node" attr.name="label" attr.type="string"/>
<key id="d1" for="edge" attr.name="weight" attr.type="float"/>
<key id="d2" for="node" attr.name="type" attr.type="string"/>
<key id="d3" for="node" attr.name="tweet" attr.type="int"/>
<key id="d4" for="node" attr.name="color" attr.type="string"/>
<graph id="G" edgedefault="undirected">
<node id="w4">
<data key="d0">value1</data>
<data key="d2">word</data>
<data key="d1">0.166666666667</data>
<data key="d4">green</data>
</node>
.
.
.
<node id="w2">
<data key="d0">value2</data>
<data key="d2">word</data>
<data key="d1">0.166666666667</data>
<data key="d4">green</data>
</node>
<edge id="e389" source="w4" target="w0">
<data key="d1">0.166666666667</data>
</edge>
答案 0 :(得分:7)
很可能你不是在寻找degree()
,因为这并不关心边缘权重。您是否正在寻找graph.strength()
功能?
# create fully connected graph
g <- graph.full(10)
# assign weights such that every weight is 1/number_of_nodes -1
E(g)$weight <- 1/( length( V(g) ) -1 )
# calculate the "weighted degree"
graph.strength(g)
[1] 1 1 1 1 1 1 1 1 1 1
或者,您是否正在寻找标准化学位?
degree( g, normalized = TRUE )
[1] 1 1 1 1 1 1 1 1 1 1