0

I am using JUNG library for its "PageRankWithPriors class". I used a very small graph (with just 3 nodes) to test this class. when there isn't any node with self-edge the output is OK, but if the graph contains a node with a self-edge the output becomes incorrect (the final rank of nodes is not in the form of probability value and their sum is not equal to 1). the output is :

0.2997601918465228

0.1247002398081535

0.1918465227817746

i used "setHyperedgesAreSelfLoops(true)" but the outputs are still incorrect:

320751.99531359226

609574.2619040733

2554381.251484884

why "PersonalizedPageRank class" does not work correctly? Is there a bug inside of it or i do something wrong?

my code is:

public static void main(String[] args) throws FileNotFoundException, IOException 
{           
   weigth[0][1]=0.2;
   weigth[0][2]=0.8;
   weigth[1][0]=1;
   weigth[2][1]= 0.5;
   weigth[2][2]= 0.5;       

   prior[0]=1;
   prior[1]=0;
   prior[2]=0;

   Graph<Integer, String> g = new DirectedSparseGraph<Integer, String> ();

   g.addVertex(new Integer(0));
   g.addVertex(new Integer(1));
   g.addVertex(new Integer(2));

   g.addEdge("0->1", 0, 1, EdgeType.DIRECTED);
   g.addEdge("0->2", 0, 2, EdgeType.DIRECTED);
   g.addEdge("1->0", 1, 0, EdgeType.DIRECTED);
   g.addEdge("2->1", 2, 1, EdgeType.DIRECTED);
   g.addEdge("2->2", 2, 2, EdgeType.DIRECTED);


   Transformer<String, Double> edge_weigths = 
           new Transformer<String, Double>()
           {
        @Override
                public Double transform(String e) 
                {
                    String[] split = e.split("->");           
                    return weigth[Integer.parseInt(split[0])][Integer.parseInt(split[1])];
                }           
           };

   Transformer<Integer, Double> vertex_prior = 
           new Transformer<Integer, Double>()
           {            
        @Override
                public Double transform(Integer v) 
                {                        
                    return prior[v];            
                }           
           }


   PageRankWithPriors prp = new PageRankWithPriors(g, edge_weigths, vertex_prior, 0.2);        
   prp.setHyperedgesAreSelfLoops(true);   
   prp.evaluate();

   System.out.println(prp.getVertexScore(0));
   System.out.println(prp.getVertexScore(1));
   System.out.println(prp.getVertexScore(2));   


}

your help is greatly appreciated.

1 Answers1

0

(1) I'm not sure why you're calling setHyperEdgesAreSelfLoops(), since you're not working with a hypergraph. Digging in a bit, it looks like the resultant numbers are weird because we're not guarding against the possibility that the graph is not a hypergraph when that method is called. Oops. In the meantime, don't call that if your graph isn't a Hypergraph. :)

(2) I think that this may be the problem:

g.addVertex((Integer)0);

I believe that casting 0 (or any other integer) to Integer is not the same thing as new Integer(0) or Integer.valueOf(0). What you're doing is actually casting the number 0 to a Integer reference. So I'll bet that if you ask your graph how many vertices it has, it will report '6' rather than '3'.

The good news is that addEdge() will automatically add the vertex arguments to the graph as needed, so you can just remove the addVertex() calls entirely.

Joshua O'Madadhain
  • 2,704
  • 1
  • 14
  • 18