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.