/// <summary> /// Computes the PageRank over the <see cref="VisitedGraph"/>. /// </summary> public void Compute() { VertexDoubleDictionary tempRanks = new VertexDoubleDictionary(); // create filtered graph FilteredBidirectionalGraph fg = new FilteredBidirectionalGraph( this.VisitedGraph, Preds.KeepAllEdges(), new InDictionaryVertexPredicate(this.ranks) ); int iter = 0; double error = 0; do { // compute page ranks error = 0; foreach(DictionaryEntry de in this.Ranks) { IVertex v = (IVertex)de.Key; double rank = (double)de.Value; // compute ARi double r = 0; foreach(IEdge e in fg.InEdges(v)) { r += this.ranks[e.Source] / fg.OutDegree(e.Source); } // add sourceRank and store double newRank = (1-this.damping) + this.damping * r; tempRanks[v] = newRank; // compute deviation error += Math.Abs(rank - newRank); } // swap ranks VertexDoubleDictionary temp = ranks; ranks = tempRanks; tempRanks = temp; iter++; }while( error > this.tolerance && iter < this.maxIterations); Console.WriteLine("{0}, {1}",iter,error); }
public void Compute() { VertexDoubleDictionary dictionary = new VertexDoubleDictionary(); FilteredBidirectionalGraph graph = new FilteredBidirectionalGraph(this.VisitedGraph, Preds.KeepAllEdges(), new InDictionaryVertexPredicate(this.ranks)); int num = 0; double num2 = 0.0; do { num2 = 0.0; IDictionaryEnumerator enumerator = this.Ranks.GetEnumerator(); while (enumerator.MoveNext()) { DictionaryEntry current = (DictionaryEntry) enumerator.Current; IVertex key = (IVertex) current.Key; double num3 = (double) current.Value; double num4 = 0.0; FilteredEdgeEnumerable.Enumerator enumerator2 = graph.InEdges(key).GetEnumerator(); while (enumerator2.MoveNext()) { IEdge edge = enumerator2.get_Current(); num4 += this.ranks.get_Item(edge.get_Source()) / ((double) graph.OutDegree(edge.get_Source())); } double num5 = (1.0 - this.damping) + (this.damping * num4); dictionary.set_Item(key, num5); num2 += Math.Abs((double) (num3 - num5)); } VertexDoubleDictionary ranks = this.ranks; this.ranks = dictionary; dictionary = ranks; num++; } while ((num2 > this.tolerance) && (num < this.maxIterations)); Console.WriteLine("{0}, {1}", num, num2); }