使用Cytoscape.js在所有节点上执行集中功能 [英] Perform Centrality Functions on all Nodes using Cytoscape.js
问题描述
我需要计算图上每个节点的程度,紧密度和中间度。我目前正在 cy.ready()
事件之后的每个节点上使用Cytoscape.js内置的函数。但是,由于图形非常大(250个以上的节点,650个以上的连接),因此计算时间太长。有人可以建议一种更有效的方法吗?
I need to calculate degree, closeness and betweenness centrality for every node on a graph. I'm currently using the functions built into Cytoscape.js on each node after the cy.ready()
event. However, as the graphs are quite large (250+ Nodes, 650+ Connections) it's taking too long to compute. Can anyone suggest a more efficient method?
var calculateSNA = function() {
// Don't run if already set...
if(data.sna) return false
console.log('Running SNA')
_.map(nodes, function(node) {
var target = cy.nodes('#' + node.data.id)
node.data.sna = {
degreeCentrality: cy.$().dc({ root: target }).degree,
closenessCentrality: cy.$().cc({ root: target }),
betweennessCentrality: cy.$().bc().betweenness(target)
}
return node
})
// Add SNA data to local storage
Data.add({
sna: true
})
Node.set(nodes)
console.log('SNA complete')
}
cy.ready(function(event) {
console.log('cy.ready()')
calculateSNA()
})
推荐答案
运行一次算法,而不是运行N次。然后只需查询结果即可:
Run the algorithm once, rather than running it N times. Then just query the result:
let ccn = cy.elements().closenessCentralityNormalized({ /* my options */ });
cy.nodes().forEach( n => {
n.data({
ccn: ccn.closeness( n )
});
} );
使用中心化算法的规范化版本,除非您有充分的理由这样做。例如,如果您将一个图形中的结果与另一图形中的结果进行比较,则只有规范化版本才真正有意义。
Use normalised versions of centrality algorithms unless you have a good reason to do otherwise. Only the normalised versions really mean anything if you compare results in one graph to results in another graph, for example.
这篇关于使用Cytoscape.js在所有节点上执行集中功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!