Perform Centrality Functions on all Nodes using Cytoscape.js

跟風遠走 提交于 2019-12-25 08:01:28

问题


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()
})

回答1:


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.



来源:https://stackoverflow.com/questions/41107018/perform-centrality-functions-on-all-nodes-using-cytoscape-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!