lib/pagerank/pagerank.rb in pagerank-0.2.1 vs lib/pagerank/pagerank.rb in pagerank-0.2.2

- old
+ new

@@ -54,13 +54,21 @@ else @score[from] = 0.15 end end + normalization + @iterates += 1 # return true if convergence? return calculate unless @iterates == 1 return true + end + + def normalization + sum = Math.sqrt(@score.inject(0){|sum, (key, value)| sum+=(value**2)}) + norm = @score.map{|key,value|value=value/sum} + @score.each_with_index{|(key,value),index|@score[key]=norm[index]} end # check convergence def convergence? convergence=0.01 return (convergence < 1.0)