graph-rank 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/graph-rank.rb +1 -1
- data/lib/graph-rank/page_rank.rb +6 -2
- metadata +2 -2
data/lib/graph-rank.rb
CHANGED
data/lib/graph-rank/page_rank.rb
CHANGED
@@ -4,14 +4,16 @@
|
|
4
4
|
class GraphRank::PageRank
|
5
5
|
|
6
6
|
# Initialize with default damping and convergence.
|
7
|
-
|
7
|
+
# A maximum number of iterations can also be supplied
|
8
|
+
# (default is no maximum, i.e. iterate until convergence).
|
9
|
+
def initialize(damping=nil, convergence=nil, max_it=-1)
|
8
10
|
damping ||= 0.85; convergence ||= 0.01
|
9
11
|
if damping <= 0 or damping > 1
|
10
12
|
raise 'Invalid damping factor.'
|
11
13
|
elsif convergence < 0 or convergence > 1
|
12
14
|
raise 'Invalid convergence factor.'
|
13
15
|
end
|
14
|
-
@damping, @convergence = damping, convergence
|
16
|
+
@damping, @convergence, @max_it = damping, convergence, max_it
|
15
17
|
@graph, @outlinks, @nodes, @weights = {}, {}, {}, {}
|
16
18
|
end
|
17
19
|
|
@@ -33,9 +35,11 @@ class GraphRank::PageRank
|
|
33
35
|
def calculate
|
34
36
|
done = false
|
35
37
|
until done
|
38
|
+
break if @max_it == 0
|
36
39
|
new_nodes = iteration
|
37
40
|
done = convergence(new_nodes)
|
38
41
|
@nodes = new_nodes
|
42
|
+
@max_it -= 1
|
39
43
|
end
|
40
44
|
@nodes.sort_by {|k,v|v}.reverse
|
41
45
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graph-rank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-17 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! ' GraphRank is an impementation of TextRank and PageRank in Ruby. '
|
15
15
|
email:
|