0

I am developing a semantic web application, and using Jung library to apply some graphs calculations, such as closeness, betweenness, etc. I was able to find the betweenness value for each node in my rdf and normalized it too. However, this is not the case with the ClosenessCentrality as I got NaN (not a number) score for some nodes.Below is my code:

int n =  graph.getVertexCount();// number of vertex 

double d = (double)(n-1)*(n-2)/2.0d; // this is to normalize the node value 

System.out.println("Applying ClosenessCentrality");

ClosenessCentrality<RDFNode, Statement> closeness = new ClosenessCentrality<RDFNode, Statement>(graph);

double[] closenessValues = new double[n];

Collection<RDFNode> closenessVertices = graph.getVertices();

int i = 0;

for (RDFNode vertex : closenessVertices)

closenessValues[i++] = closeness.getVertexScore(vertex) / d; // get the normalized score for each node

for (double score : closenessValues)

System.out.println(score);  // print all values.

So, as I mentioned before for some reason I got NAN score for some nodes. I feel that there is a bug on the ClosenessCentrality algorithm implementation as I got NaN. Any explanation guys ? am I doing something wrong ?

Thanks for the help

RGO
  • 4,586
  • 3
  • 26
  • 40
Dr.AdeeB
  • 31
  • 1
  • 4
  • 1
    Have you checked the closeness values before the normalization? NaN can be returned for 0/0 for example. – Eyal Schneider Dec 24 '13 at 09:34
  • Thanks @EyalSchneider, you are right, but my d value which I used to calculate the normalization never got zero value. I did and still got the same problem – Dr.AdeeB Dec 25 '13 at 17:34

2 Answers2

0

I'd have to recheck the code, but I'll bet that the closeness centrality value may do something weird if the vertex in question appears on no shortest paths (because it's a disconnected vertex or has no incoming edges). I'd check that first.

Joshua O'Madadhain
  • 2,704
  • 1
  • 14
  • 18
  • thanks @Joshua O'Madadhain for the reply. Well this is not the case in my graph. My constructed graph that I used for closeness calculation is fully connected (no DISCONNECTED vertex at all). i.e I made sure while constructing the graph that every vertex has at least one edge in and another edge out. Thus, I am waiting for your answer regarding this issue. Above is my code that I used for finding the closeness. FYI: the same code works just fine with betweenness. – Dr.AdeeB Jan 07 '14 at 05:44
0

if there's no edge to any other node from a vertex, then the closeness centrality of that vertex would be divided by 0. And NaN is the result. That's why you get the NaN for some vetex.

user3764792
  • 46
  • 1
  • 4