changeset 8:4d1885a2fa36 draft

fix method of calculation for computing PageRank.
author one
date Wed, 05 Sep 2012 17:19:59 +0900
parents c7b139ff27e2
children 9787663edb54
files src/pagerank/LinkToVertex.java src/pagerank/TPReadWikiLink.java
diffstat 2 files changed, 19 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/pagerank/LinkToVertex.java	Wed Sep 05 16:34:47 2012 +0900
+++ b/src/pagerank/LinkToVertex.java	Wed Sep 05 17:19:59 2012 +0900
@@ -23,8 +23,7 @@
 	private HashMap<String, WikiPage> wikiPageHash = new HashMap<String, WikiPage>();
 	private long AllVertexNumber;
 
-	private final double weight1 = 0.85;
-	private final double weight2 = 0.15;
+	private final double weight = 0.85;
 
 	public static final String HAS_LINK = "HasLink";
 
@@ -103,6 +102,12 @@
 		return setRelationship(v1, v2, HAS_LINK);
 	}
 
+	void initPageRankAllVertex() {
+		for (Vertex v : graph.getVertices()) {
+			setPageRank(v, 0.0);
+		}
+	}
+	
 	long searchAllVertices() {
 		AllVertexNumber = 0;
 		for (Vertex v : graph.getVertices()) {
@@ -218,9 +223,8 @@
 				sum += ((Double) linkV.getProperty(PAGE_RANK)) / computeInHasLink(linkV) ;
 			}
 		}
-	
-		pageRank = (double) sum * weight1
-				+ (double) ((double) 1 / AllVertexNumber * weight2);
+		pageRank = (double) (1 - weight) / AllVertexNumber
+				+ (double) sum * weight;
 
 		wiki.setRank(pageRank);
 		v.setProperty(PAGE_RANK, pageRank);
--- a/src/pagerank/TPReadWikiLink.java	Wed Sep 05 16:34:47 2012 +0900
+++ b/src/pagerank/TPReadWikiLink.java	Wed Sep 05 17:19:59 2012 +0900
@@ -35,18 +35,20 @@
 			in.close();
 			LinkToVertex ltv = new LinkToVertex(graph);
 
+//			ltv.initPageRankAllVertex();
 			final long AllVertexNumber = ltv.searchAllVertices();
 			HashMap<String, WikiPage> wikiHash = ltv.getWikiPageHash();
 			System.out.println("AllVertexNumber = "+AllVertexNumber);
 
-			String nodeIds[] = {"1574", "2829", "2850", "3618"};
-			writeComputeTransition(ltv, nodeIds, 50);
-			
-//			FileOutputStream fos = new FileOutputStream(new File("./resources/wikiPageRank.log"));
-//			descendingOrder(wikiHash, fos);			
-			
-			
-			
+
+//			String nodeIds[] = {"1574", "2829", "2850", "3618"};
+//			writeComputeTransition(ltv, nodeIds, 50);
+
+
+			FileOutputStream fos = new FileOutputStream(new File("./resources/wikiPageRank.log"));
+			descendingOrder(wikiHash, fos);			
+
+
 			FileOutputStream out = new FileOutputStream(new File(fileDB));
 			GraphMLWriter.outputGraph(graph, out);
 			out.close();